#!/bin/bash # ==== Variables ==== GOGS_APP_USER="git" GOGS_VERSION="v0.13.0" GOG_INSTALLATION_DIR="/opt/gogs" POSTGRES_USER="postgres" POSTGRES_PASSWORD="postgres" DATABASE_NAME="gogs" GOGS_SECRET_KEY="BJRHSi4nIl9KFHu" echo "[+] Installing Go Version: 1.22.5" wget https://go.dev/dl/go1.22.5.linux-amd64.tar.gz # Remove any previous Go installation rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz # Add /usr/local/go/bin to the PATH environment variable export PATH=$PATH:/usr/local/go/bin echo "[+] Checking for a successful Go installation" go version echo "[+] Installing PostgreSQfL" apt update apt install -y postgresql postgresql-contrib # Determine PostgreSQL version PG_VERSION=$(psql -V | awk '{print $3}' | cut -d. -f1) PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf" echo "[+] Enabling and starting PostgreSQL service" systemctl enable postgresql systemctl start postgresql # Set password for postgres user sudo -u $POSTGRES_USER psql -c "ALTER USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';" sudo -u $POSTGRES_USER psql -U $POSTGRES_USER -c "CREATE DATABASE $DATABASE_NAME;" echo "[+] PostgreSQL password for user '$POSTGRES_USER' set" sed -i 's/^\(local\s\+all\s\+postgres\s\+\)peer/\1md5/' "$PG_HBA" echo "[+] Updated pg_hba.conf to use md5 authentication for 'postgres' user" # Restart PostgreSQL systemctl restart postgresql echo "[+] PostgreSQL restarted" # Create a new user for Gogs echo "[+] Creating system user '$GOGS_APP_USER'" useradd -m -s /bin/bash $GOGS_APP_USER # Setup Gogs echo "[+] Cloning Gogs source code" mkdir $GOG_INSTALLATION_DIR cd $GOG_INSTALLATION_DIR git clone -b $GOGS_VERSION --depth 1 https://github.com/gogs/gogs.git mkdir -p $GOG_INSTALLATION_DIR/gogs/custom/conf cat > $GOG_INSTALLATION_DIR/gogs/custom/conf/app.ini <