diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8543797 --- /dev/null +++ b/install.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +set -euo pipefail + +sudo apt update + +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +install_docker_via_script() { + echo "πŸ› οΈ Installing Docker..." + curl -fsSL https://get.docker.com | sh + echo "βœ… Docker installed." +} + +setup_project_folder() { + local folder="nq-api" + echo "πŸ“ Creating folder: $folder" + mkdir -p "$folder" + + echo "⬇️ Downloading docker-compose.yaml" + curl -fsSL https://raw.githubusercontent.com/NatiqQuran/nq-api/refs/heads/main/docker-compose.yaml \ + -o "$folder/docker-compose.yaml" + + echo "⬇️ Downloading nginx.conf" + curl -fsSL https://raw.githubusercontent.com/NatiqQuran/nq-api/refs/heads/main/nginx.conf \ + -o "$folder/nginx.conf" + + echo "βœ…dokcer-compose.yaml and nginx.conf saved to nq-api." +} + +customize_compose() { + local file="$1/docker-compose.yaml" + + sed -i "/^ api:/,/^[^ ]/ s|^[[:space:]]*build:.*| image: natiqquran/nq-api|" "$file" + echo "πŸ”„ Step 1: image for api set to natiqquran/nq-api" + + local secret=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 40 | head -n 1) + sed -i "s/^ SECRET_KEY:.*/ SECRET_KEY: $secret/" "$file" + echo "πŸ”’ Step 2: SECRET_KEY has been set" + + local ip=$(hostname -I | awk '{print $1}') + sed -i "s|^ DJANGO_ALLOWED_HOSTS:.*| DJANGO_ALLOWED_HOSTS: $ip|" "$file" + echo "🌐 Step 3: DJANGO_ALLOWED_HOSTS set to $ip" + + echo -n "Do you want to open docker-compose.yaml for manual edit? (yes/no): " + read -t 10 -n 1 ans || ans="n" + echo + ans=${ans:-n} + + case "${ans,,}" in + yes|y) + ${EDITOR:-vi} "$file" + echo "✏️ Manual edit done, continuing..." + ;; + *) + echo "⏩ Skipping manual edit" + ;; + esac +} + +if [[ "${1:-}" == "no-install" ]]; then + echo "🚫 Skipping Docker installation (no-install flag used)" +else + if command_exists docker; then + echo -n "⚠️ Docker is already installed. Do you want to reinstall it? (yes/no): " + read -t 10 -n 1 reinstall || reinstall="n" + echo + reinstall=${reinstall:-n} + if [[ "${reinstall,,}" =~ ^(y|yes)$ ]]; then + install_docker_via_script + else + echo "⏩ Skipping Docker installation." + fi + else + install_docker_via_script + fi +fi + +setup_project_folder + +customize_compose "nq-api" + +echo "πŸš€ Running docker compose up -d" +cd nq-api +docker compose up -d + +echo "πŸŽ‰ Mission completed!"