mirror of
https://codeberg.org/vlw/href.git
synced 2025-09-13 16:23:41 +02:00
128 lines
No EOL
3.2 KiB
Bash
Executable file
128 lines
No EOL
3.2 KiB
Bash
Executable file
#!/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 </dev/tty
|
|
|
|
# Check the user's response
|
|
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
|
echo "Removing existing configuration and proceeding with the installation in ${cwd}..."
|
|
rm .env.ini
|
|
else
|
|
echo "Installation aborted."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "Next we're going to configure the HREF database."
|
|
echo "You can use the same database as Reflect here if you want."
|
|
echo ""
|
|
|
|
# Prompt the user for database credentials
|
|
echo "Database configuration."
|
|
read -p "Enter the full hostname of your HREF MySQL/MariaDB server: " db_host </dev/tty
|
|
read -p "Enter the username for your HREF MySQL/MariaDB server: " db_user </dev/tty
|
|
read -p "Enter the password for your HREF MySQL/MariaDB server: " db_pass </dev/tty
|
|
read -p "Enter the database name that HREF should use: " db_db </dev/tty
|
|
|
|
echo ""
|
|
echo "Almost there..."
|
|
echo ""
|
|
read -p "Is the Reflect instance running on port 80? (y/n): " choice </dev/tty
|
|
|
|
# Check the user's response
|
|
if [[ "$choice" == "n" || "$choice" == "N" ]] ; then
|
|
read -p "Enter the port number: " reflect_port </dev/tty
|
|
fi
|
|
|
|
local api_key_read=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c 64)
|
|
local api_key_admin=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c 64)
|
|
|
|
local config=(
|
|
"; This config file was generated automatically"
|
|
"; Refer to '.env.example.ini' for more information"
|
|
"[api]"
|
|
"base_url = 'http://localhost:${reflect_port}/'"
|
|
"api_key = '${api_key_read}'"
|
|
"verify_peer = false"
|
|
"[database]"
|
|
"host = '${db_host}'"
|
|
"user = '${db_user}'"
|
|
"pass = '${db_pass}'"
|
|
"db = '${db_db}'"
|
|
)
|
|
|
|
for line in "${config[@]}" ; do
|
|
echo "${line}" >> 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 |