linkwarden/install.sh
2025-06-02 17:37:18 +00:00

68 lines
1.6 KiB
Bash

#!/bin/bash
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"
# 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