dev/install (#58)
All checks were successful
Tests / Run Go Tests (push) Successful in 1m24s
All checks were successful
Tests / Run Go Tests (push) Successful in 1m24s
improved ci/cd pipeline + interactive install script Reviewed-on: #58 Co-authored-by: Tom Tröger <t.troeger.02@gmail.com> Co-committed-by: Tom Tröger <t.troeger.02@gmail.com>
This commit is contained in:
107
install.sh
Executable file
107
install.sh
Executable file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
envFile=Docker/.env
|
||||
envExample=Docker/env.example
|
||||
|
||||
echo "Checking Docker installation..."
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Docker not found. Install Docker? [y/N]"
|
||||
read -r install_docker
|
||||
if [[ "$install_docker" =~ ^[Yy]$ ]]; then
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
else
|
||||
echo "Docker is required. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Docker is already installed."
|
||||
fi
|
||||
|
||||
echo "Checking Docker Compose..."
|
||||
if ! docker compose version >/dev/null 2>&1; then
|
||||
echo "Docker Compose plugin missing. You may need to update Docker."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Preparing .env file..."
|
||||
if [ ! -f $envFile ]; then
|
||||
if [ -f $envExample ]; then
|
||||
echo ".env not found. Creating interactively from .env.example."
|
||||
> $envFile
|
||||
|
||||
while IFS= read -r line; do
|
||||
|
||||
#ignore empty lines and comments
|
||||
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
|
||||
|
||||
|
||||
key=$(printf "%s" "$line" | cut -d '=' -f 1)
|
||||
rest=$(printf "%s" "$line" | cut -d '=' -f 2-)
|
||||
|
||||
# extract inline comment portion
|
||||
comment=$(printf "%s" "$rest" | sed -n 's/.*# \(.*\)$/\1/p')
|
||||
raw_val=$(printf "%s" "$rest" | sed 's/ *#.*//')
|
||||
default_value=$(printf "%s" "$raw_val" | sed 's/"//g')
|
||||
|
||||
regex=""
|
||||
if [[ "$comment" =~ regex:(.*)$ ]]; then
|
||||
regex="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
comment=$(printf "%s" "$comment" | sed 's/ regex:.*//')
|
||||
|
||||
while true; do
|
||||
if [ -z "$comment" ]; then
|
||||
printf "Value for $key - $comment (default: $default_value"
|
||||
else
|
||||
printf "Value for $key (default: $default_value"
|
||||
fi
|
||||
if [ -n "$regex" ]; then
|
||||
printf ", must match: %s" "$regex"
|
||||
fi
|
||||
printf "):\n"
|
||||
|
||||
read user_input < /dev/tty
|
||||
|
||||
# empty input -> take default
|
||||
[ -z "$user_input" ] && user_input="$default_value"
|
||||
|
||||
printf "\e[A$user_input\n"
|
||||
|
||||
# validate
|
||||
if [ -n "$regex" ]; then
|
||||
if [[ "$user_input" =~ $regex ]]; then
|
||||
echo "$key=$user_input" >> $envFile
|
||||
break
|
||||
else
|
||||
printf "Invalid value. Does not match regex: %s\n" "$regex"
|
||||
continue
|
||||
fi
|
||||
else
|
||||
echo "$key=$user_input" >> $envFile
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
done < $envExample
|
||||
|
||||
echo ".env created."
|
||||
else
|
||||
echo "No .env or .env.example found."
|
||||
echo "Creating an empty .env file for manual editing."
|
||||
touch $envFile
|
||||
fi
|
||||
else
|
||||
echo "Using existing .env. (found at $envFile)"
|
||||
fi
|
||||
|
||||
echo "Start containers with docker compose up -d? [y/N]"
|
||||
read -r start_containers
|
||||
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
|
||||
cd Docker
|
||||
docker compose up -d
|
||||
echo "Containers started."
|
||||
else
|
||||
echo "You can start them manually with: docker compose up -d"
|
||||
fi
|
||||
Reference in New Issue
Block a user