diff --git a/README.md b/README.md index e55a898..c011ab5 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,27 @@ # vlw.se -This is the source code behind [vlw.se](https://vlw.se) which is my personal website that I have written and designed from the ground up. The website is built on top of my own [web framework](https://vegvisir.vlw.se) and its API is also built on top of my own [API framework](https://reflect.vlw.se). +This is the source code behind [vlw.se](https://vlw.se) which is my personal website that I have written and designed from the ground up. The website is built on top of my own [Vegvisir web framework](https://vegvisir.vlw.se) and its optional REST API is built on top of my [Reflect API framework](https://reflect.vlw.se). # Installation -Here's how you get my website up and running on your own machine. Note, I have only tested this on Linux and the install script we will run later is written in bash. +Here's how you get my website up and running on your own machine. Note, I have only tested this on Linux and the install script we will run requires Bash with `coreutils` installed. -**Make sure you have both of these package managers installed before proceeding:** -- [Composer](https://getcomposer.org/) -- [NPM](https://www.npmjs.com/) +## Prerequisites +- A web server +- A MariaDB/MySQL server +- PHP 8.4 or newer with the following extensions enabled: +- - `php8.4-mysql` +- - `php8.4-mbstring` +- The composer package manager +- Bash with `coreutils` installed (for the install script) ## 1. Clone this repo -Clone/download this repo to your machine. Preferably to a non-public directory - the frameworks will handle that. - +Clone this repository with its submodules. Preferably to a non-public directory - the frameworks will handle that. ``` -git clone https://codeberg.org/vlw/vlw.se --depth 1 +git clone https://codeberg.org/vlw/vlw.se --recurse-submodules --depth 1 ``` -## 2. Install [Vegvisir](https://vegvisir.vlw.se) and [Reflect](https://reflect.vlw.se) -Follow the installation instructions for my web, and API framework. This site uses the default configuration for both frameworks so the only thing you need to do after you've installed both is to point the `root_path` and `endpoints` directory respectively to the directory where you cloned this repo. - -- [Vegvisir installation](https://vegvisir.vlw.se) -- [Reflect installation](https://reflect.vlw.se) - -*Example:* -```sh -# Vegvisir -root_path = "/var/www/vlw.se" -# Reflect -endpoints = "/var/www/vlw.se" +## 2. Run the install script +Run the `install.sh` script from the root directory of this repository. ``` - -## 3. Run the install script -Run the `install.sh` script from the root of the repo directory. [Make sure you have the required package managers installed](#installation). - -**Example:** -```sh -# vlw@example:$ -cd /var/www/vlw.se -# vlw@example:/var/www/vlw.se$ ./install.sh ``` - -## 4. Import the database templates -There's are two SQL files in [`/src/Database/Seeds/`](https://codeberg.org/vlw/vlw.se/src/branch/master/src/Database/Seeds) that you can use to initialize the two databases required for this website. - -- `vlw` - This database has the website data and should be added to the `db` variable under `server_database` in `/.env.ini` -- `vlw_reflect` - This is the Reflect database that has all the endpoints pre-configured. You'll have to add your own ACL rules. - -## 5. Set environment variables -Make a copy of the `.env.example.ini` file called `.env.ini` from the root directory of the repo. There are a few parameters you can change here but the required ones are the following: - -```ini -[client_api] -base_url = "" -api_key = "" - -[server_database] -host = "" -user = "" -pass = "" -db = "" -``` - -Please refer to the comments in the ini file for more information about each field. - -## Done! -That should be it. Navigate to your configured Vegvisir public host! \ No newline at end of file +This script will install and configure Vegvisir, Reflect, and the website through a few propmpted steps. \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..77244bf --- /dev/null +++ b/install.sh @@ -0,0 +1,251 @@ +#!/bin/bash + +# Define constants +DB_VLW="vlw" +DB_API="vlw_api" + +# Initialize variables +cwd="" +database_app_host="" +database_app_user="" +database_seed_host="" +database_seed_user="" +database_app_password="" +database_seed_password="" + +echo_err() { + echo "!! -> $1" +} + +# Make sure we have all the system packages we need to proceed with the installation +check_sys_depend() { + local valid=true + local packages=("git" "composer") + + for package in "${packages[@]}" ; do + if ! dpkg -l | grep -qw "ii ${package}" ; then + echo_err "Package '${package}' is not installed." + valid=false + fi + done + + # Bail out if any required package is missing + if [ "$valid" = false ] ; then + exit 1 + fi +} + +install_vegvisir() { + echo + echo "Installing Vegvisir into '$cwd/vegvisir'" + + curl -fsSL https://codeberg.org/vegvisir/install/raw/branch/master/install.sh | bash -s -- --install=n --overwrite=y --example=n --dir="$cwd" +} + +install_reflect() { + echo + echo "Installing Reflect into '$cwd/reflect'" + + curl -fsSL https://codeberg.org/reflect/install/raw/branch/master/install.sh | bash -s -- --install=n --overwrite=y --seed=n --dir="$cwd" --endpoints="api" --host="$database_app_host" --user="$database_app_user" --password="$database_app_password" --db="$DB_API" +} + +install_vlw() { + composer install --classmap-authoritative +} + +seed_databases() { + echo + echo "-- Database seeding --" + echo "We're now going to seed the databases '$DB_VLW' and '$DB_API' with default data" + echo "- Make sure that both databases exist and are empty" + echo "- Your credentials for this user '$(whoami)' might be different from your app credentials (php-mysql)" + echo + + # Database seed hostname + echo "Enter the full hostname of your MySQL/MariaDB server to use in this script for seeding." + read -p "Press enter to use the same host as the app credentials [$database_app_host]: " database_seed_host ]: " database_seed_password > .env.ini + done +} + +main() { + # Get the current working directory + cwd=$(pwd) + + check_sys_depend + + configure_vlw + seed_databases + + install_vlw + install_vegvisir + install_reflect + + echo "-- Success --" + echo "vlw.se has been installed! :)" + echo "- Point all traffic to your web server to '${cwd}/vegvisir/public/index.php'" + echo "- Point all traffic to your REST API server to '${cwd}/reflect/public/index.php'" + echo "-------------" + echo +} + +# Prompt the user for confirmation +echo +echo "-- Installing vlw.se --" +echo "You are currently in: $(pwd)" +read -p "Do you want to proceed with the installation in this directory? (y/n): " choice