#!/bin/bash # Ask the user if they want to start the initial setup or they want to migrate from an existing installation read -r -p "Do you want to start the initial setup? (y/n): " INSTALL_GITEA if [ -z "$INSTALL_GITEA" ] || [[ "$INSTALL_GITEA" != "y" && "$INSTALL_GITEA" != "n" ]]; then echo "Skipping inital setup." read -r -p "Do you want to migrate from an existing installation? (Y/n): " MIGRATE_EXISTING if [ "$MIGRATE_EXISTING" == "n" ]; then echo "Exiting setup." exit 0 else read -r -p "What method do you want to use for migration? (local/scp): " MIGRATION_METHOD if [ "$MIGRATION_METHOD" == "local" ]; then read -r -p "Enter the local path to the existing gitea installation: " LOCAL_PATH # check if the LOCAL_PATH is a compessed file if [[ "$LOCAL_PATH" == *.tar.gz || "$LOCAL_PATH" == *.tgz ]]; then echo "Extracting compressed file ..." sudo tar -xvzf "$LOCAL_PATH" -C . exit 0 elif [[ "$LOCAL_PATH" == *.zip ]]; then # check if unzip is installed if ! command -v unzip &> /dev/null; then echo "unzip could not be found, installing it ..." sudo apt-get update sudo apt-get install unzip fi echo "Extracting compressed file ..." sudo unzip "$LOCAL_PATH" -d . exit 0 fi sudo cp -r "$LOCAL_PATH" . exit 0 elif [ "$MIGRATION_METHOD" == "scp" ]; then read -r -p "Enter the remote user@host:/destination/of/gitea/: " REMOTE_PATH sudo scp -r "$REMOTE_PATH" . exit 0 else echo "Invalid migration method. Exiting setup." exit 0 fi fi else touch .env IPV4_ADDRESS=$(hostname -I | awk '{print $1}') export IPV4_ADDRESS echo "Current IPv4 Address: $IPV4_ADDRESS" echo "Temporary enable port 3000 for initial setup ..." sudo ufw allow 3000/tcp sudo ufw reload sudo ufw status # Start the initial setup docker compose file echo "Starting initial setup container ..." docker compose -f config/docker-compose.init.yml up -d --force-recreate docker logs gitea-init echo "Container is running at http://$IPV4_ADDRESS:3000" echo "Please complete the setup in the web interface." read -r -p "Please add a runner key or press any key to continue after completing the setup..." RUNNER_KEY if [ -n "$RUNNER_KEY" ]; then echo "Runner key provided: $RUNNER_KEY" echo "RUNNER_KEY=$RUNNER_KEY" >> .env else echo "No runner key provided. Continuing..." fi echo "ROOT_URL=http://$IPV4_ADDRESS:3000" >> .env echo "Stopping initial setup container ..." docker compose -f config/docker-compose.init.yml down echo "Disabling temporary port 3000 ..." sudo ufw delete allow 3000/tcp sudo ufw reload sudo ufw status fi # Get the current IPv4 address