#!/bin/bash # Initialize variables db="" cwd="" dir="" host="" user="" seed="" install="" password="" seed_host="" seed_user="" overwrite="" endpoints="" seed_password="" echo_err() { echo "!! -> $1" } # Bail out from an error with a message asking the user to report the incident exit_report() { echo_err "Please report this error at: https://codeberg.org/reflect/install/issues" exit 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" "mysql") 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_reflect() { if ! [ -d ".git" ] ; then echo_err "Installation aborted: '${cwd}' is not a git repository" exit 1 fi if ! [ -d "reflect" ] ; then git submodule add https://codeberg.org/reflect/reflect fi # Update submodules git submodule update --init --recursive # Install dependencies with composer (cd reflect && composer install --classmap-authoritative) # Bail out if composer didn't create a vendor folder if ! [ -d "reflect/vendor" ] ; then echo_err "Something went wrong with the installation." exit_report fi } configure_reflect() { if ! [ -d "reflect" ] ; then echo_err "Reflect is not installed." exit_report fi # A configuration file already exists if [[ -f "reflect/.env.ini" ]] ; then if ! [[ -n "$overwrite" ]]; then echo "A Reflect configuration file already exists at: ${cwd}/reflect/.env.ini" read -p "Do you want to overwrite this file? (y/n): " overwrite ]: " seed_password > reflect/.env.ini done } main() { # Get the current working directory cwd=$(pwd) check_sys_depend # Download and install the Reflect repository if [[ "$install" != "n" ]]; then install_reflect fi configure_reflect echo echo "Reflect has been sucessfully installed." echo "Thank you for choosing Reflect :)" echo exit 0 } # Loop through all arguments for arg in "$@"; do case $arg in --db=*) db="${arg#*=}" ;; --dir=*) dir="${arg#*=}" ;; --host=*) host="${arg#*=}" ;; --user=*) user="${arg#*=}" ;; --seed=*) seed="${arg#*=}" ;; --install=*) install="${arg#*=}" ;; --seed-host=*) seed_host="${arg#*=}" ;; --seed-user=*) seed_user="${arg#*=}" ;; --password=*) password="${arg#*=}" ;; --overwrite=*) overwrite="${arg#*=}" ;; --endpoints=*) endpoints="${arg#*=}" ;; --seed-password=*) seed_password="${arg#*=}" ;; *) echo_err "Unknown argument: $arg" ;; esac done # Start installation in passed directory if [[ -n "$dir" ]]; then if ! [ -d "$dir" ]; then echo_err "Installation aborted: '$dir' is not a directory" exit 1 fi cd $dir cwd=$(pwd) main fi # Prompt the user for confirmation echo echo "You are currently in: $(pwd)" read -p "Do you want to proceed with the installation in this directory? (y/n): " choice