mirror of
https://codeberg.org/reflect/install.git
synced 2025-09-14 02:03:42 +02:00
initial commit
This commit is contained in:
commit
288e7bde06
2 changed files with 391 additions and 0 deletions
102
README.md
Normal file
102
README.md
Normal file
|
@ -0,0 +1,102 @@
|
|||
# Reflect installer
|
||||
Run this script from a git repository to automatically install and configure Reflect as a git submodule to your project.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The script will only run in environments with Bash and `coreutils` installed (for now).
|
||||
|
||||
# Prerequisite
|
||||
A MariaDB or MySQL server with at least `SELECT` rights granted to a database table. (`SELECT`, `INSERT`, `UPDATE`, and `DELETE` rights to this table are required if you wish to manage your Reflect configuration through REST)
|
||||
|
||||
# Get started
|
||||
1. Create a git repository for your project.
|
||||
2. Create a new empty MariaDB/MySQL database table.
|
||||
3. Run this command from the root directory of your local repository.
|
||||
|
||||
```sh
|
||||
curl -fsSL https://codeberg.org/reflect/install/raw/branch/master/install.sh | bash
|
||||
```
|
||||
|
||||
# Arguments
|
||||
You can pass optional named arguments to this script for headless installation of Reflect.
|
||||
|
||||
## `--overwrite` - Overwrite existing configuration files
|
||||
```sh
|
||||
./install.sh --example=n
|
||||
```
|
||||
Pass `--overwrite=y` to overwrite all existing Reflect configuration files.
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `--dir` - Installation directory
|
||||
```sh
|
||||
./install.sh --dir="/path/to/project"
|
||||
```
|
||||
Pass a `--dir` argument with a value of a directory Reflect should consider its [`root_path`](https://reflect.vlw.se/docs/Reference/Env#root_path).
|
||||
|
||||
### `--endpoints` - Overwrite configuration files
|
||||
```sh
|
||||
./install.sh --endpoints="api"
|
||||
```
|
||||
Pass an `--endpoints` argument with a value of a directory relative to [`root_path`](https://reflect.vlw.se/docs/Reference/Env#root_path) where Reflect endpoint directories are stored.
|
||||
|
||||
### Database
|
||||
|
||||
### `--db` - Reflect database table
|
||||
```sh
|
||||
./install.sh --db="reflect"
|
||||
```
|
||||
Pass a `--db` argument with a value of a database table that Reflect should use.
|
||||
|
||||
### `--host` - Reflect database hostname
|
||||
```sh
|
||||
./install.sh --host="/path/to/project"
|
||||
```
|
||||
Pass a `--host` argument with a value of a fully qualified hostname that Reflect should use when connecting to you MariaDB/MySQL server.
|
||||
|
||||
### `--user` - Reflect database user
|
||||
```sh
|
||||
./install.sh --user="www-data"
|
||||
```
|
||||
Pass a `--user` argument with a value of a username that Reflect should use when connecting to you MariaDB/MySQL server.
|
||||
|
||||
### `--password` - Reflect database user
|
||||
```sh
|
||||
./install.sh --password="mypassword"
|
||||
```
|
||||
Pass a `--password` argument with a value of a password that Reflect should use when connecting to you MariaDB/MySQL server.
|
||||
|
||||
```sh
|
||||
./install.sh --password=null
|
||||
```
|
||||
Pass "null" to this argument to disable password authentication
|
||||
|
||||
### Database seeding
|
||||
|
||||
### `--db` - Reflect database table
|
||||
```sh
|
||||
./install.sh --db="reflect"
|
||||
```
|
||||
Pass a `--db` argument with a value of a database table that Reflect should use.
|
||||
|
||||
### `--seed_host` - Reflect database hostname
|
||||
```sh
|
||||
./install.sh --seed_host="/path/to/project"
|
||||
```
|
||||
Pass a `--host` argument with a value of a fully qualified hostname that will be used by this script to seed the database.
|
||||
|
||||
### `--seed_user` - Reflect database user
|
||||
```sh
|
||||
./install.sh --seed_user="www-data"
|
||||
```
|
||||
Pass a `--user` argument with a value of a username that will be used by this script to seed the database.
|
||||
|
||||
### `--seed_password` - Reflect database user
|
||||
```sh
|
||||
./install.sh --seed_password="mypassword"
|
||||
```
|
||||
Pass a `--password` argument with a value of a password that will be used by this script to seed the database.
|
||||
|
||||
```sh
|
||||
./install.sh --seed_password=null
|
||||
```
|
||||
Pass "null" to this argument to disable password authentication
|
289
install.sh
Executable file
289
install.sh
Executable file
|
@ -0,0 +1,289 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Initialize variables
|
||||
db=""
|
||||
cwd=""
|
||||
dir=""
|
||||
host=""
|
||||
user=""
|
||||
seed=""
|
||||
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 </dev/tty
|
||||
fi
|
||||
|
||||
# Remove existing configuration file or abort
|
||||
if [[ "$overwrite" == "y" || "$overwrite" == "Y" ]] ; then
|
||||
echo "Removing existing Reflect configuration and proceeding with the installation in ${cwd}..."
|
||||
rm reflect/.env.ini
|
||||
else
|
||||
echo_err "Installation aborted: Configuration file already exists"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Configuring Reflect database."
|
||||
|
||||
# Database hostname
|
||||
if ! [[ -n "$host" ]]; then
|
||||
echo
|
||||
read -p "Enter the full hostname of your MySQL/MariaDB server: " host </dev/tty
|
||||
fi
|
||||
|
||||
# Database user
|
||||
if ! [[ -n "$user" ]]; then
|
||||
echo
|
||||
read -p "Enter the username for your MySQL/MariaDB server: " user </dev/tty
|
||||
fi
|
||||
|
||||
# Database password
|
||||
if ! [[ -n "$password" ]]; then
|
||||
echo
|
||||
read -p "Enter the password for your MySQL/MariaDB server: " password </dev/tty
|
||||
fi
|
||||
|
||||
# Database table
|
||||
if ! [[ -n "$db" ]]; then
|
||||
echo
|
||||
read -p "Enter the name of the database table that Reflect should use: " db </dev/tty
|
||||
fi
|
||||
|
||||
# Prompt the user for seeding the database if argument not provided
|
||||
if ! [[ -n "$seed" ]]; then
|
||||
echo
|
||||
echo "Do you want to seed the database '$db'?"
|
||||
echo "The database '$db' must EXIST and be EMPTY before proceeding with 'y'."
|
||||
read -p "Do you want to proceed? (y/n): " seed </dev/tty
|
||||
fi
|
||||
|
||||
# Seed the database
|
||||
if [[ "$seed" == "y" || "$seed" == "Y" ]] ; then
|
||||
# Database seed host
|
||||
if ! [[ -n "$seed_host" ]]; then
|
||||
echo
|
||||
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 Reflect configuration [$host]: " seed_host </dev/tty
|
||||
|
||||
if [[ "$seed_host" == "" ]] ; then
|
||||
seed_host=$host
|
||||
fi
|
||||
fi
|
||||
|
||||
# Database seed user
|
||||
if ! [[ -n "$seed_user" ]]; then
|
||||
echo
|
||||
echo "Enter the username for your MySQL/MariaDB server to use in this script for seeding."
|
||||
read -p "Press enter to use the same username as the Reflect configuration [$user]: " seed_user </dev/tty
|
||||
|
||||
if [[ "$seed_user" == "" ]] ; then
|
||||
seed_user=$user
|
||||
fi
|
||||
fi
|
||||
|
||||
# Database seed password
|
||||
if ! [[ -n "$seed_password" ]]; then
|
||||
echo
|
||||
echo "Enter the password for your MySQL/MariaDB server to use in this script for seeding."
|
||||
echo "Enter 'null' to disable password authentication."
|
||||
read -p "Press enter to use the same password as the Reflect configuration [<database_password>]: " seed_password </dev/tty
|
||||
|
||||
# Coerce password keyword "null" to empty string
|
||||
if [[ "$seed_password" == "null" ]]; then
|
||||
seed_password=""
|
||||
fi
|
||||
|
||||
if [[ "$seed_password" == "" ]] ; then
|
||||
seed_password=$password
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
mysql -h "$seed_host" -u "$seed_user" --password="$seed_password" "$db" < reflect/src/database/seed/reflect.sql
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo_err "Installation aborted: MySQL error"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Coerce password keyword "null" to empty string
|
||||
if [[ "$password" == "null" ]]; then
|
||||
password=""
|
||||
fi
|
||||
|
||||
local config=(
|
||||
"; This config file was generated automatically by https://codeberg.org/reflect/install"
|
||||
"; Refer to '.env.example.ini' or https://reflect.vlw.se/docs/Reference/Env for more information"
|
||||
"root_path = '${dir}'"
|
||||
"endpoints_dir = '${endpoints:="api"}'"
|
||||
"mysql_host = '${host}'"
|
||||
"mysql_user = '${user}'"
|
||||
"mysql_pass = '${password}'"
|
||||
"mysql_db = '${db}'"
|
||||
)
|
||||
|
||||
for line in "${config[@]}" ; do
|
||||
echo "${line}" >> reflect/.env.ini
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
# Get the current working directory
|
||||
cwd=$(pwd)
|
||||
|
||||
check_sys_depend
|
||||
install_reflect
|
||||
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#*=}"
|
||||
;;
|
||||
|
||||
--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 </dev/tty
|
||||
echo
|
||||
|
||||
# Check the user's response
|
||||
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
||||
echo "Proceeding with the installation in $(pwd)..."
|
||||
main
|
||||
else
|
||||
echo "Installation aborted."
|
||||
fi
|
Loading…
Add table
Reference in a new issue