From 97eb39a7c0ef4ea173eb8575ffc8da7e55e4dd77 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 7 Aug 2025 12:38:58 +0200 Subject: [PATCH] feat: add install script --- install.sh | 251 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 install.sh 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