mirror of
https://github.com/tteck/Proxmox.git
synced 2025-02-15 06:09:15 +01:00
lxc-forgejo: Move database choice if statements with switch-case inside the select command
This commit is contained in:
parent
ddafd1f871
commit
2f1b9e27b8
1 changed files with 57 additions and 53 deletions
|
@ -41,69 +41,73 @@ echo -e "Forgejo data directory: \e[32m/var/lib/forgejo\e[0m" >>~/forgejo.creds
|
||||||
msg_ok "Setup Forgejo"
|
msg_ok "Setup Forgejo"
|
||||||
|
|
||||||
read -r -p "Forgejo uses SQLite by default. Would you like to use another database? <y/N> " prompt
|
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
|
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_NAME=forgejodb
|
||||||
DB_USER=forgejo
|
DB_USER=forgejo
|
||||||
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
||||||
if [ "$DB_CHOICE" == "PostgreSQL" ]; then
|
|
||||||
$STD apt-get install -y postgresql
|
PS3="Please enter your choice: "
|
||||||
echo "" >>~/forgejo.creds
|
select DB_CHOICE in "PostgreSQL" "MySQL" "MariaDB"; do
|
||||||
echo -e "Database Type: \e[32mPostgresQL\e[0m" >>~/forgejo.creds
|
case $DB_CHOICE in
|
||||||
echo -e "PostgresQL Database Host: \e[32m127.0.0.1:5432\e[0m" >>~/forgejo.creds
|
"PostgreSQL")
|
||||||
echo -e "Forgejo PostgresQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds
|
$STD apt-get install -y postgresql
|
||||||
echo -e "Forgejo PostgresQL Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds
|
echo "" >>~/forgejo.creds
|
||||||
echo -e "Forgejo PostgresQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
echo -e "Database Type: \e[32mPostgresQL\e[0m" >>~/forgejo.creds
|
||||||
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
|
echo -e "PostgresQL Database Host: \e[32m127.0.0.1:5432\e[0m" >>~/forgejo.creds
|
||||||
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
|
echo -e "Forgejo PostgresQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds
|
||||||
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';"
|
echo -e "Forgejo PostgresQL Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds
|
||||||
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';"
|
echo -e "Forgejo PostgresQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
||||||
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'"
|
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
|
||||||
HBA_FILE=$(sudo -u postgres psql -t -P format=unaligned -c 'SHOW hba_file' 2>/dev/null)
|
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
|
||||||
tee -a "$HBA_FILE" > /dev/null <<EOL
|
$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 <<EOL
|
||||||
# Allow Forgejo database user to access the database
|
# Allow Forgejo database user to access the database
|
||||||
local forgejodb forgejo scram-sha-256
|
local forgejodb forgejo scram-sha-256
|
||||||
host forgejodb forgejo 127.0.0.1/32 scram-sha-256 # IPv4 local connections
|
host forgejodb forgejo 127.0.0.1/32 scram-sha-256 # IPv4 local connections
|
||||||
host forgejodb forgejo ::1/128 scram-sha-256 # IPv6 local connections
|
host forgejodb forgejo ::1/128 scram-sha-256 # IPv6 local connections
|
||||||
EOL
|
EOL
|
||||||
$STD systemctl restart postgresql
|
$STD systemctl restart postgresql
|
||||||
fi
|
break
|
||||||
if [ "$DB_CHOICE" == "MySQL" ]; then
|
;;
|
||||||
$STD apt-get install -y mysql-server
|
"MySQL")
|
||||||
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
$STD apt-get install -y mysql-server
|
||||||
echo "" >>~/forgejo.creds
|
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
||||||
echo -e "Database Type: \e[32mMySQL\e[0m" >>~/forgejo.creds
|
echo "" >>~/forgejo.creds
|
||||||
echo -e "MySQL Database Host: \e[32m127.0.0.1:3306\e[0m" >>~/forgejo.creds
|
echo -e "Database Type: \e[32mMySQL\e[0m" >>~/forgejo.creds
|
||||||
echo -e "MySQL Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/forgejo.creds
|
echo -e "MySQL Database Host: \e[32m127.0.0.1:3306\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MySQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds
|
echo -e "MySQL Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MySQL Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds
|
echo -e "Forgejo MySQL Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MySQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
echo -e "Forgejo MySQL Database Password: \e[32m$DB_PASS\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;"
|
echo -e "Forgejo MySQL Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
||||||
$STD systemctl restart mysql
|
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;"
|
||||||
fi
|
$STD systemctl restart mysql
|
||||||
if [ "$DB_CHOICE" == "MariaDB" ]; then
|
break
|
||||||
$STD apt-get install -y mariadb-server
|
;;
|
||||||
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
"MariaDB")
|
||||||
echo "" >>~/forgejo.creds
|
$STD apt-get install -y mariadb-server
|
||||||
echo -e "Database Type: \e[32mMariaDB\e[0m" >>~/forgejo.creds
|
ADMIN_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
||||||
echo -e "MariaDB Database Host: \e[32m127.0.0.1:3306\e[0m" >>~/forgejo.creds
|
echo "" >>~/forgejo.creds
|
||||||
echo -e "MariaDB Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/forgejo.creds
|
echo -e "Database Type: \e[32mMariaDB\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MariaDB Database User: \e[32m$DB_USER\e[0m" >>~/forgejo.creds
|
echo -e "MariaDB Database Host: \e[32m127.0.0.1:3306\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MariaDB Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds
|
echo -e "MariaDB Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/forgejo.creds
|
||||||
echo -e "Forgejo MariaDB Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
echo -e "Forgejo MariaDB Database User: \e[32m$DB_USER\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;"
|
echo -e "Forgejo MariaDB Database Password: \e[32m$DB_PASS\e[0m" >>~/forgejo.creds
|
||||||
$STD systemctl restart mariadb
|
echo -e "Forgejo MariaDB Database Name: \e[32m$DB_NAME\e[0m" >>~/forgejo.creds
|
||||||
fi
|
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;"
|
||||||
msg_ok "${BL}${DB_CHOICE}${CL} will be used"
|
$STD systemctl restart mariadb
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid option. Please select again."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
msg_ok "Database ${BL}${DB_CHOICE}${CL} will be used"
|
||||||
else
|
else
|
||||||
msg_ok "${BL}SQLite${CL} will be used"
|
msg_ok "Database ${BL}SQLite${CL} will be used"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -r -p "Would you like to add Adminer? <y/N> " prompt
|
read -r -p "Would you like to add Adminer? <y/N> " prompt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue