feat: add install script (#48)

This PR adds an install script which will configure vlw.se along with Reflect and Vegvisir. The only step which is manual (maybe for now) is pointing the web and REST API server. This is mentioned at the end of the installation.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/48
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
This commit is contained in:
Victor Westerlund 2025-08-07 13:00:10 +02:00 committed by Victor Westerlund
parent fafa8c5852
commit d4d73e9278
2 changed files with 266 additions and 55 deletions

View file

@ -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!
This script will install and configure Vegvisir, Reflect, and the website through a few propmpted steps.

251
install.sh Normal file
View file

@ -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 </dev/tty
# Use the same database host as the app configuration
if [[ "$database_seed_host" == "" ]] ; then
database_seed_host=$database_app_host
fi
# Database seed user
echo
echo "Enter the username for 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_user]: " database_seed_user </dev/tty
# Use the same database user as the app configuration
if [[ "$database_seed_user" == "" ]] ; then
database_seed_user=$database_app_user
fi
# Database seed password
echo
echo "Enter the password for your MySQL/MariaDB server to use in this script for seeding."
echo "Enter 'null' to disable password authentication"
read -p "Press enter to use the same password as the app credentials [<database_password>]: " database_seed_password </dev/tty
# Use the same database password as the app configuration
if [[ "$database_seed_password" == "" ]] ; then
database_seed_password=$database_app_password
fi
# Seed the main database
mysql -h "$database_seed_host" -u "$database_seed_user" --password="$database_seed_password" $DB_VLW < src/Database/Seeds/vlw.sql
if [ $? -ne 0 ]; then
echo_err "Installation aborted: MySQL error"
exit 1
fi
# Seed the API database
mysql -h "$database_seed_host" -u "$database_seed_user" --password="$database_seed_password" $DB_API < src/Database/Seeds/api.sql
if [ $? -ne 0 ]; then
echo_err "Installation aborted: MySQL error"
exit 1
fi
}
configure_vlw() {
local config_password=""
local config_available=""
local config_available_to=""
local config_available_from=""
local config_available_average=""
local config_available_timezone=""
local config_forgejo=""
local config_forgejo_url=""
local config_forgejo_profiles=""
# A configuration file already exists
if [[ -f ".env.ini" ]] ; then
echo
echo "A configuration file already exists at: ${cwd}/.env.ini"
read -p "Do you want to overwrite this file? (y/n): " overwrite </dev/tty
# Remove existing configuration file or abort
if [[ "$overwrite" == "y" || "$overwrite" == "Y" ]] ; then
echo "Removing existing configuration and proceeding with the installation in ${cwd}..."
rm .env.ini
else
echo_err "Installation aborted: Configuration file already exists"
exit 1
fi
fi
echo
echo "-- Database configuration --"
read -p "Enter the full hostname of your MySQL/MariaDB server (php-mysql): " database_app_host </dev/tty
read -p "Enter the app username for your MySQL/MariaDB server (php-mysql): " database_app_user </dev/tty
read -p "Enter the app password for your MySQL/MariaDB server (php-mysql): " config_password </dev/tty
# Coerce empty input as null keyword for later configurations
if [[ "$config_password" == "" ]] ; then
database_app_password="null"
fi
echo
read -p "(Optional) Would you like to configure time available settings? (y/n): " config_available </dev/tty
# Check the user's response
if [[ "$config_available" == "n" || "$config_available" == "N" ]]; then
config_available_to=0
config_available_from=0
config_available_average=0
config_available_timezone="Europe/Stockholm"
fi
if ! [[ -n "$config_available_timezone" ]]; then
read -p "Enter your timezone in IANA Time Zone Database Format ('Europe/Stockholm' for example): " config_available_timezone </dev/tty
fi
if ! [[ -n "$config_available_from" ]]; then
read -p "Enter time available from hour (24-hour format): " config_available_from </dev/tty
fi
if ! [[ -n "$config_available_to" ]]; then
read -p "Enter time available to hour (24-hour format): " config_available_to </dev/tty
fi
if ! [[ -n "$config_available_average" ]]; then
read -p "Enter average reply time in hours: " config_available_average </dev/tty
fi
echo
read -p "(Optional) Would you like to configure Forgejo language updates? (y/n): " config_forgejo </dev/tty
# Check the user's response
if [[ "$config_forgejo" == "n" || "$config_forgejo" == "N" ]]; then
config_forgejo_url="https://git.vlw.se"
config_forgejo_profiles="vlw,vegvisir,reflect"
fi
if ! [[ -n "$config_forgejo_url" ]]; then
read -p "Enter a hostname to a Forgejo instance ('https://git.vlw.se' for example): " config_forgejo_url </dev/tty
fi
if ! [[ -n "$config_forgejo_profiles" ]]; then
read -p "Enter a comma seperated list of Forgejo profiles to scan ('vlw,vegvisir,reflect' for example): " config_forgejo_profiles </dev/tty
fi
local config=(
"; This config file was generated automatically by ./install.sh"
"; Refer to '.env.example.ini' for more information"
"[mariadb]"
"host = '$database_app_host'"
"user = '$database_app_user'"
"pass = '$config_password'"
"db = '$DB_VLW'"
"[config_time_available]"
"time_zone = '$config_available_timezone'"
"available_to_hour = '$config_available_to'"
"reply_average_hours = '$config_available_average'"
"available_from_hour = '$config_available_from'"
"[service_forgejo]"
"url = '$config_forgejo_url'"
"profiles = '$config_forgejo_profiles'"
)
for line in "${config[@]}" ; do
echo "${line}" >> .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 </dev/tty
# Check the user's response
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
echo "Proceeding with the installation in $(pwd)..."
main
else
echo "Installation aborted."
fi