mirror of
https://codeberg.org/vlw/href.git
synced 2025-09-13 16:23:41 +02:00
feat: add install script and Reflect submodule
This commit is contained in:
parent
f03978b0f0
commit
c1cf13d400
3 changed files with 132 additions and 0 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "reflect"]
|
||||
path = reflect
|
||||
url = https://codeberg.org/reflect/reflect
|
128
install.sh
Executable file
128
install.sh
Executable file
|
@ -0,0 +1,128 @@
|
|||
#!/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
|
1
reflect
Submodule
1
reflect
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 097a0bf777bbc8da2ab35b9ebb58a029778bf6bd
|
Loading…
Add table
Reference in a new issue