78 lines
1.9 KiB
Bash
Executable File
78 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Helper function to check if a command exists
|
|
command_exists() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
# Check if the first argument is "clean"
|
|
if [[ "$1" == "clean" ]]; then
|
|
echo "Downloading files with curl..."
|
|
curl -O https://raw.githubusercontent.com/linkwarden/linkwarden/refs/heads/main/docker-compose.yml
|
|
curl -L https://raw.githubusercontent.com/linkwarden/linkwarden/refs/heads/main/.env.sample -o ".env"
|
|
else
|
|
echo "Skipping curl download. Run with 'clen' to enable."
|
|
fi
|
|
|
|
# Helper function to check a command
|
|
command_exists() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
DOCKER_OK=true
|
|
COMPOSE_OK=true
|
|
|
|
# Check for Docker
|
|
if ! command_exists docker; then
|
|
DOCKER_OK=false
|
|
fi
|
|
|
|
# Check for Docker Compose (plugin or legacy)
|
|
if ! docker compose version >/dev/null 2>&1 && ! command_exists docker-compose; then
|
|
COMPOSE_OK=false
|
|
fi
|
|
|
|
# If either is missing, run install script
|
|
if [[ "$DOCKER_OK" = false || "$COMPOSE_OK" = false ]]; then
|
|
echo "Missing required tools. Running installer..."
|
|
git clone https://git.giovanesaggio.com/Selfhosting/docker_setup.git
|
|
./docker_setup/docker_setup.sh
|
|
rm -r docker_setup
|
|
fi
|
|
|
|
# Parse and prompt for .env variables
|
|
ENV_FILE=".env"
|
|
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
echo "$ENV_FILE not found. Creating a new one."
|
|
touch "$ENV_FILE"
|
|
fi
|
|
|
|
declare -A ENV_VARS
|
|
|
|
# Load existing env vars
|
|
while IFS='=' read -r key value; do
|
|
[[ "$key" =~ ^[A-Z_][A-Z0-9_]*$ ]] || continue
|
|
ENV_VARS["$key"]="$value"
|
|
done < "$ENV_FILE"
|
|
|
|
echo "Configure environment variables (press ENTER to keep current value):"
|
|
|
|
# Prompt for each variable
|
|
for key in "${!ENV_VARS[@]}"; do
|
|
current="${ENV_VARS[$key]}"
|
|
read -p "$key [$current]: " new_value
|
|
if [[ -n "$new_value" ]]; then
|
|
ENV_VARS["$key"]="$new_value"
|
|
fi
|
|
done
|
|
|
|
# Overwrite .env with updated values
|
|
> "$ENV_FILE"
|
|
for key in "${!ENV_VARS[@]}"; do
|
|
echo "$key=${ENV_VARS[$key]}" >> "$ENV_FILE"
|
|
done
|
|
|
|
# Launch Docker
|
|
docker compose up -d
|