#!/bin/bash # Get the current working directory cwd=$(pwd) 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/vlw/href/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" "curl") 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() { echo "" echo "First we're going to install the Reflect API framework." echo "" curl -sSL https://href.vlw.se/reflect/install | bash if [ $? -ne 0 ] ; then echo_err "Failed to run Reflect install script" exit_report fi } configure_href() { if ! [ -f "reflect/.env.ini" ] ; then echo_err "Reflect is not installed correctly." exit_report fi local reflect_port=80 # A configuration file already exists if [ -f ".env.ini" ] ; then echo "A configuration file already exists at: ${cwd}/.env.ini" read -p "Do you want to overwrite this file? (y/n): " choice > reflect/.env.ini done echo "+- That should be it!" echo "|" echo "| Here is your admin API key that you can use to manage links" echo "| ${api_key_admin}" echo "|" echo "| See https://codeberg.org/vlw/href for more details" echo "|" echo "+- Thank you for using HREF." } main() { check_sys_depend install_reflect configure_href } main