lxc-forgejo: Move database choice if statements with switch-case inside the select command

This commit is contained in:
barremian 2024-05-29 00:37:56 +02:00
parent ddafd1f871
commit 2f1b9e27b8
No known key found for this signature in database
GPG key ID: 96E431287CDD3E4A

View file

@ -41,19 +41,15 @@ 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? <y/N> " prompt
msg_info "Setting up database"
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
PS3="Please enter your choice: "
files="$(ls -A .)"
select DB_CHOICE in "PostgreSQL" "MySQL" "MariaDB"; do
msg_ok "You selected ${BL}${DB_CHOICE}${CL}"
break
done
DB_NAME=forgejodb
DB_USER=forgejo
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
if [ "$DB_CHOICE" == "PostgreSQL" ]; then
PS3="Please enter your choice: "
select DB_CHOICE in "PostgreSQL" "MySQL" "MariaDB"; do
case $DB_CHOICE in
"PostgreSQL")
$STD apt-get install -y postgresql
echo "" >>~/forgejo.creds
echo -e "Database Type: \e[32mPostgresQL\e[0m" >>~/forgejo.creds
@ -74,8 +70,9 @@ host forgejodb forgejo 127.0.0.1/32 scram-sha-256 #
host forgejodb forgejo ::1/128 scram-sha-256 # IPv6 local connections
EOL
$STD systemctl restart postgresql
fi
if [ "$DB_CHOICE" == "MySQL" ]; then
break
;;
"MySQL")
$STD apt-get install -y mysql-server
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
echo "" >>~/forgejo.creds
@ -87,8 +84,9 @@ EOL
echo -e "Forgejo MySQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
mysql -uroot -p"$ADMIN_PASS" -e "SET old_passwords=0; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$ADMIN_PASS' 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' IDENTIFIED BY '$DB_PASS'; FLUSH PRIVILEGES;"
$STD systemctl restart mysql
fi
if [ "$DB_CHOICE" == "MariaDB" ]; then
break
;;
"MariaDB")
$STD apt-get install -y mariadb-server
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
echo "" >>~/forgejo.creds
@ -100,10 +98,16 @@ EOL
echo -e "Forgejo MariaDB Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
mariadb -uroot -p"$ADMIN_PASS" -e "SET old_passwords=0; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$ADMIN_PASS' 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' IDENTIFIED BY '$DB_PASS'; FLUSH PRIVILEGES;"
$STD systemctl restart mariadb
fi
msg_ok "${BL}${DB_CHOICE}${CL} will be used"
break
;;
*)
echo "Invalid option. Please select again."
;;
esac
done
msg_ok "Database ${BL}${DB_CHOICE}${CL} will be used"
else
msg_ok "${BL}SQLite${CL} will be used"
msg_ok "Database ${BL}SQLite${CL} will be used"
fi
read -r -p "Would you like to add Adminer? <y/N> " prompt