diff --git a/install/forgejo-install.sh b/install/forgejo-install.sh index 81dcb31a..5c4c5b8e 100644 --- a/install/forgejo-install.sh +++ b/install/forgejo-install.sh @@ -42,103 +42,12 @@ echo -e "Forgejo GIT User: \e[32mgit\e[0m" >>~/forgejo.creds echo -e "Forgejo data directory: \e[32m/var/lib/forgejo\e[0m" >>~/forgejo.creds msg_ok "Setup Forgejo" -read -r -p "Forgejo uses SQLite by default. Would you like to use another database? " prompt -if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then - DB_NAME=forgejodb - DB_USER=forgejo - DB_PASS="$(openssl rand -base64 18 | cut -c1-13)" - - PS3="Please enter your choice: " - select DB_CHOICE in "PostgreSQL" "MySQL"; do - case $DB_CHOICE in - "PostgreSQL") - msg_info "Setting up PostgreSQL" - $STD apt-get install -y postgresql - echo "" >>~/forgejo.creds - echo -e "Database Type: \e[32mPostgresQL\e[0m" >>~/forgejo.creds - echo -e "PostgresQL Database Host: \e[32mlocalhost:5432\e[0m" >>~/forgejo.creds - echo -e "Forgejo PostgresQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds - echo -e "Forgejo PostgresQL Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds - echo -e "Forgejo PostgresQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds - $STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" - $STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" - $STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" - $STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" - $STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'" - HBA_FILE=$(sudo -u postgres psql -t -P format=unaligned -c 'SHOW hba_file' 2>/dev/null) - tee -a "$HBA_FILE" > /dev/null <>~/forgejo.creds - echo -e "Database Type: \e[32mMySQL\e[0m" >>~/forgejo.creds - echo -e "MySQL Database Host: \e[32mlocalhost:3306\e[0m" >>~/forgejo.creds - echo -e "MySQL Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/forgejo.creds - echo -e "Forgejo MySQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds - echo -e "Forgejo MySQL Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds - echo -e "Forgejo MySQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds - mariadb -uroot -p"$ADMIN_PASS" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$ADMIN_PASS'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; CREATE USER '$DB_USER' IDENTIFIED BY '$DB_PASS'; CREATE DATABASE $DB_NAME CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'; GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'; FLUSH PRIVILEGES;" - $STD systemctl restart mariadb - msg_ok "Setup MySQL" - break - ;; - *) - echo "Invalid option. Please select again." - ;; - esac - done -else - msg_ok "Database ${BL}SQLite${CL} will be used" -fi - -if [[ -n "${DB_CHOICE:-}" ]]; then - read -r -p "Would you like to add Adminer? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then - msg_info "Installing Adminer" - $STD apt install -y adminer - $STD a2enconf adminer - systemctl reload apache2 - IP=$(hostname -I | awk '{print $1}') - echo "" >>~/forgejo.creds - echo -e "Adminer Interface: \e[32m$IP/adminer/\e[0m" >>~/forgejo.creds - if [[ "$DB_CHOICE" == "PostgreSQL" ]]; then - echo -e "Adminer System: \e[32mPostgreSQL\e[0m" >>~/forgejo.creds - echo -e "Adminer Server: \e[32mlocalhost:5432\e[0m" >>~/forgejo.creds - elif [[ "$DB_CHOICE" == "MySQL" ]]; then - echo -e "Adminer System: \e[32mMySQL\e[0m" >>~/forgejo.creds - echo -e "Adminer Server: \e[32mlocalhost:3306\e[0m" >>~/forgejo.creds - fi - echo -e "Adminer Username: \e[32m$DB_USER\e[0m" >>~/forgejo.creds - echo -e "Adminer Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds - echo -e "Adminer Database: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds - msg_ok "Installed Adminer" - fi -fi - msg_info "Creating Service" cat </etc/systemd/system/forgejo.service [Unit] Description=Forgejo After=syslog.target After=network.target -$(if [[ -n "${DB_CHOICE:-}" && "${DB_CHOICE}" == "PostgreSQL" ]]; then -echo -e "Wants=postgresql.service" -echo -e "After=postgresql.service" -fi) -$(if [[ -n "${DB_CHOICE:-}" && "$DB_CHOICE" == "MySQL" ]]; then -echo -e "Wants=mariadb.service" -echo -e "After=mariadb.service" -fi) [Service] # Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that # LimitNOFILE=524288:524288