update server scripts files

This commit is contained in:
manuel 2024-07-22 12:27:12 +00:00
parent 3df65a2aca
commit 35ae8bb1d0
10 changed files with 370 additions and 269 deletions

View File

@ -1,21 +0,0 @@
#!/bin/bash
# Create systemd service file for welcome.sh
cat << EOF > /etc/systemd/system/welcome.service
[Unit]
Description=Welcome Script
After=network.target
[Service]
ExecStart=/usr/local/bin/welcome.sh
RemainAfterExit=true
[Install]
WantedBy=default.target
EOF
# Set permissions
chmod 644 /etc/systemd/system/welcome.service
# Enable the service to start on boot
systemctl enable welcome.service

View File

@ -65,6 +65,9 @@ secure_apache() {
# Function to configure Apache virtual hosts # Function to configure Apache virtual hosts
configure_apache_virtual_hosts() { configure_apache_virtual_hosts() {
DOMAIN=$(dialog --inputbox "Enter the domain name for the virtual host (e.g., example.com):" 10 40 3>&1 1>&2 2>&3 3>&-) DOMAIN=$(dialog --inputbox "Enter the domain name for the virtual host (e.g., example.com):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -n "$DOMAIN" ]]; then if [[ -n "$DOMAIN" ]]; then
sudo mkdir -p /var/www/$DOMAIN/public_html sudo mkdir -p /var/www/$DOMAIN/public_html
sudo chown -R www-data:www-data /var/www/$DOMAIN/public_html sudo chown -R www-data:www-data /var/www/$DOMAIN/public_html
@ -87,6 +90,14 @@ EOF
# Function to enable or disable Apache virtual host (site) # Function to enable or disable Apache virtual host (site)
enable_disable_apache_site() { enable_disable_apache_site() {
SITE=$(dialog --inputbox "Enter the site configuration file name (without .conf):" 10 40 3>&1 1>&2 2>&3 3>&-) SITE=$(dialog --inputbox "Enter the site configuration file name (without .conf):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -z "$SITE" ]]; then
dialog --msgbox "No site configuration file name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Site" \ ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Site" \
--title "Enable/Disable Apache Site" \ --title "Enable/Disable Apache Site" \
--menu "Choose an action:" 10 40 2 \ --menu "Choose an action:" 10 40 2 \
@ -94,6 +105,10 @@ enable_disable_apache_site() {
2 "Disable" \ 2 "Disable" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
case $ACTION in case $ACTION in
1) 1)
sudo a2ensite $SITE.conf sudo a2ensite $SITE.conf
@ -114,6 +129,14 @@ enable_disable_apache_site() {
# Function to enable or disable Apache modules # Function to enable or disable Apache modules
enable_disable_apache_module() { enable_disable_apache_module() {
MODULE=$(dialog --inputbox "Enter the name of the Apache module to enable/disable (e.g., rewrite):" 10 40 3>&1 1>&2 2>&3 3>&-) MODULE=$(dialog --inputbox "Enter the name of the Apache module to enable/disable (e.g., rewrite):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -z "$MODULE" ]]; then
dialog --msgbox "No module name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Module" \ ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Module" \
--title "Enable/Disable Apache Module" \ --title "Enable/Disable Apache Module" \
--menu "Choose an action:" 10 40 2 \ --menu "Choose an action:" 10 40 2 \
@ -121,6 +144,10 @@ enable_disable_apache_module() {
2 "Disable" \ 2 "Disable" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
case $ACTION in case $ACTION in
1) 1)
sudo a2enmod $MODULE sudo a2enmod $MODULE
@ -141,6 +168,9 @@ enable_disable_apache_module() {
# Function to configure Certbot for Apache # Function to configure Certbot for Apache
configure_certbot() { configure_certbot() {
DOMAIN=$(dialog --inputbox "Enter the domain name for which you want to configure Certbot (e.g., example.com):" 10 40 3>&1 1>&2 2>&3 3>&-) DOMAIN=$(dialog --inputbox "Enter the domain name for which you want to configure Certbot (e.g., example.com):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -n "$DOMAIN" ]]; then if [[ -n "$DOMAIN" ]]; then
sudo certbot --apache -d $DOMAIN sudo certbot --apache -d $DOMAIN
fi fi
@ -151,7 +181,7 @@ configure_apache() {
while true; do while true; do
CHOICE=$(dialog --clear --backtitle "Configure Apache" \ CHOICE=$(dialog --clear --backtitle "Configure Apache" \
--title "Apache Menu" \ --title "Apache Menu" \
--menu "Choose an option:" 20 60 11 \ --menu "Choose an option:" 20 60 12 \
1 "Install/Check Apache" \ 1 "Install/Check Apache" \
2 "Start Apache" \ 2 "Start Apache" \
3 "Stop Apache" \ 3 "Stop Apache" \
@ -166,13 +196,13 @@ configure_apache() {
12 "Return to Main Menu" \ 12 "Return to Main Menu" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -ne 0 ]; then
break break
fi fi
clear
case $CHOICE in case $CHOICE in
1) install_apache_if_needed ;; 1) install_apache_if_needed ;;
2) start_apache ;; 2) start_apache ;;

View File

@ -1,48 +1,5 @@
#!/bin/bash #!/bin/bash
# Function to install PHP if not installed
install_php_if_needed() {
if ! dpkg -l php > /dev/null 2>&1; then
echo "PHP is not installed. Installing..."
if sudo apt-get install -y php; then
echo "PHP installed successfully."
else
echo "Failed to install PHP. Exiting."
exit 1
fi
fi
}
# Function to configure PHP
configure_php() {
while true; do
OPTION=$(dialog --clear --backtitle "Configure PHP" \
--title "PHP Configuration Menu" \
--menu "Choose an option:" 15 60 4 \
1 "Configure PHP.ini" \
2 "Set PHP Error Reporting" \
3 "Set PHP Timezone" \
4 "Return to Main Menu" \
3>&1 1>&2 2>&3)
clear
# Check if user canceled
if [ $? -eq 1 ]; then
break
fi
case $OPTION in
1) sudo nano /etc/php/7.4/apache2/php.ini ;; # Adjust version if needed
2) echo "error_reporting = E_ALL" | sudo tee -a /etc/php/7.4/apache2/php.ini ;; # Adjust version if needed
3) TZ=$(dialog --inputbox "Enter PHP timezone (e.g., America/New_York):" 10 40 3>&1 1>&2 2>&3)
sudo sed -i "s|^;date.timezone =|date.timezone = $TZ|" /etc/php/7.4/apache2/php.ini ;; # Adjust version if needed
4) break ;;
*) dialog --msgbox "Invalid option." 10 30 ;;
esac
done
}
# Function to install Docker if not installed # Function to install Docker if not installed
install_docker_if_needed() { install_docker_if_needed() {
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
@ -53,6 +10,8 @@ install_docker_if_needed() {
echo "Failed to install Docker. Exiting." echo "Failed to install Docker. Exiting."
exit 1 exit 1
fi fi
else
echo "Docker is already installed."
fi fi
} }
@ -70,21 +29,21 @@ configure_docker() {
6 "Return to Main Menu" \ 6 "Return to Main Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break return
fi fi
case $OPTION in case $OPTION in
1) NETWORK=$(dialog --inputbox "Enter Docker network name:" 10 40 3>&1 1>&2 2>&3) 1) NETWORK=$(dialog --inputbox "Enter Docker network name:" 10 40 3>&1 1>&2 2>&3)
sudo docker network create $NETWORK ;; if [ $? -ne 1 ]; then
sudo docker network create $NETWORK
fi ;;
2) manage_docker_containers ;; 2) manage_docker_containers ;;
3) manage_docker_images ;; 3) manage_docker_images ;;
4) manage_docker_volumes ;; 4) manage_docker_volumes ;;
5) manage_docker_compose ;; 5) manage_docker_compose ;;
6) break ;; 6) return ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -102,20 +61,22 @@ manage_docker_containers() {
4 "Return to Docker Menu" \ 4 "Return to Docker Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break return
fi fi
case $ACTION in case $ACTION in
1) sudo docker ps -a ;; 1) sudo docker ps -a ;;
2) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3) 2) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3)
sudo docker start $CONTAINER ;; if [ $? -ne 1 ]; then
sudo docker start $CONTAINER
fi ;;
3) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3) 3) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3)
sudo docker stop $CONTAINER ;; if [ $? -ne 1 ]; then
4) break ;; sudo docker stop $CONTAINER
fi ;;
4) return ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -133,20 +94,22 @@ manage_docker_images() {
4 "Return to Docker Menu" \ 4 "Return to Docker Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break return
fi fi
case $ACTION in case $ACTION in
1) sudo docker images ;; 1) sudo docker images ;;
2) IMAGE=$(dialog --inputbox "Enter the image name (e.g., ubuntu):" 10 40 3>&1 1>&2 2>&3) 2) IMAGE=$(dialog --inputbox "Enter the image name (e.g., ubuntu):" 10 40 3>&1 1>&2 2>&3)
sudo docker pull $IMAGE ;; if [ $? -ne 1 ]; then
sudo docker pull $IMAGE
fi ;;
3) IMAGE=$(dialog --inputbox "Enter the image ID or name:" 10 40 3>&1 1>&2 2>&3) 3) IMAGE=$(dialog --inputbox "Enter the image ID or name:" 10 40 3>&1 1>&2 2>&3)
sudo docker rmi $IMAGE ;; if [ $? -ne 1 ]; then
4) break ;; sudo docker rmi $IMAGE
fi ;;
4) return ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -164,20 +127,22 @@ manage_docker_volumes() {
4 "Return to Docker Menu" \ 4 "Return to Docker Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break return
fi fi
case $ACTION in case $ACTION in
1) sudo docker volume ls ;; 1) sudo docker volume ls ;;
2) VOLUME=$(dialog --inputbox "Enter the volume name:" 10 40 3>&1 1>&2 2>&3) 2) VOLUME=$(dialog --inputbox "Enter the volume name:" 10 40 3>&1 1>&2 2>&3)
sudo docker volume create $VOLUME ;; if [ $? -ne 1 ]; then
sudo docker volume create $VOLUME
fi ;;
3) VOLUME=$(dialog --inputbox "Enter the volume name or ID:" 10 40 3>&1 1>&2 2>&3) 3) VOLUME=$(dialog --inputbox "Enter the volume name or ID:" 10 40 3>&1 1>&2 2>&3)
sudo docker volume rm $VOLUME ;; if [ $? -ne 1 ]; then
4) break ;; sudo docker volume rm $VOLUME
fi ;;
4) return ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -195,18 +160,16 @@ manage_docker_compose() {
4 "Return to Docker Menu" \ 4 "Return to Docker Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break return
fi fi
case $ACTION in case $ACTION in
1) docker_compose_up ;; 1) docker_compose_up ;;
2) docker_compose_down ;; 2) docker_compose_down ;;
3) docker_compose_remove ;; 3) docker_compose_remove ;;
4) break ;; 4) return ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -215,7 +178,7 @@ manage_docker_compose() {
# Function to run Docker Compose # Function to run Docker Compose
docker_compose_up() { docker_compose_up() {
COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3) COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3)
if [[ -n "$COMPOSE_FILE" ]]; then if [ $? -ne 1 ] && [ -n "$COMPOSE_FILE" ]; then
sudo docker-compose -f $COMPOSE_FILE up -d sudo docker-compose -f $COMPOSE_FILE up -d
fi fi
} }
@ -223,7 +186,7 @@ docker_compose_up() {
# Function to stop Docker Compose # Function to stop Docker Compose
docker_compose_down() { docker_compose_down() {
COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3) COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3)
if [[ -n "$COMPOSE_FILE" ]]; then if [ $? -ne 1 ] && [ -n "$COMPOSE_FILE" ]; then
sudo docker-compose -f $COMPOSE_FILE down sudo docker-compose -f $COMPOSE_FILE down
fi fi
} }
@ -231,7 +194,7 @@ docker_compose_down() {
# Function to remove Docker Compose # Function to remove Docker Compose
docker_compose_remove() { docker_compose_remove() {
COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3) COMPOSE_FILE=$(dialog --inputbox "Enter the Docker Compose file (e.g., docker-compose.yaml):" 10 40 3>&1 1>&2 2>&3)
if [[ -n "$COMPOSE_FILE" ]]; then if [ $? -ne 1 ] && [ -n "$COMPOSE_FILE" ]; then
sudo docker-compose -f $COMPOSE_FILE down --volumes --remove-orphans sudo docker-compose -f $COMPOSE_FILE down --volumes --remove-orphans
fi fi
} }
@ -241,27 +204,21 @@ main_menu() {
while true; do while true; do
CHOICE=$(dialog --clear --backtitle "Server Utilities Installation and Configuration" \ CHOICE=$(dialog --clear --backtitle "Server Utilities Installation and Configuration" \
--title "Main Menu" \ --title "Main Menu" \
--menu "Choose an option:" 15 60 5 \ --menu "Choose an option:" 15 60 4 \
1 "Install/Check PHP" \ 1 "Install/Check Docker" \
2 "Configure PHP" \ 2 "Configure Docker" \
3 "Install/Check Docker" \ 3 "Exit" \
4 "Configure Docker" \
5 "Return to Main Menu" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
break break
fi fi
case $CHOICE in case $CHOICE in
1) install_php_if_needed ;; 1) install_docker_if_needed ;;
2) configure_php ;; 2) configure_docker ;;
3) install_docker_if_needed ;; 3) break ;;
4) configure_docker ;;
5) break ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done

View File

@ -8,45 +8,72 @@ install_mariadb_if_needed() {
echo "MariaDB installed successfully." echo "MariaDB installed successfully."
else else
echo "Failed to install MariaDB. Exiting." echo "Failed to install MariaDB. Exiting."
dialog --msgbox "Failed to install MariaDB. Exiting." 10 30
exit 1 exit 1
fi fi
else
dialog --msgbox "MariaDB is already installed." 10 30
fi fi
} }
# Function to start MariaDB # Function to start MariaDB
start_mariadb() { start_mariadb() {
sudo systemctl start mariadb sudo systemctl start mariadb
dialog --msgbox "MariaDB started." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB started successfully." 10 30
else
dialog --msgbox "Failed to start MariaDB." 10 30
fi
} }
# Function to stop MariaDB # Function to stop MariaDB
stop_mariadb() { stop_mariadb() {
sudo systemctl stop mariadb sudo systemctl stop mariadb
dialog --msgbox "MariaDB stopped." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB stopped successfully." 10 30
else
dialog --msgbox "Failed to stop MariaDB." 10 30
fi
} }
# Function to restart MariaDB # Function to restart MariaDB
restart_mariadb() { restart_mariadb() {
sudo systemctl restart mariadb sudo systemctl restart mariadb
dialog --msgbox "MariaDB restarted." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB restarted successfully." 10 30
else
dialog --msgbox "Failed to restart MariaDB." 10 30
fi
} }
# Function to enable MariaDB at boot # Function to enable MariaDB at boot
enable_mariadb_at_boot() { enable_mariadb_at_boot() {
sudo systemctl enable mariadb sudo systemctl enable mariadb
dialog --msgbox "MariaDB enabled at boot." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB enabled at boot successfully." 10 30
else
dialog --msgbox "Failed to enable MariaDB at boot." 10 30
fi
} }
# Function to disable MariaDB at boot # Function to disable MariaDB at boot
disable_mariadb_at_boot() { disable_mariadb_at_boot() {
sudo systemctl disable mariadb sudo systemctl disable mariadb
dialog --msgbox "MariaDB disabled at boot." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB disabled at boot successfully." 10 30
else
dialog --msgbox "Failed to disable MariaDB at boot." 10 30
fi
} }
# Function to secure MariaDB installation # Function to secure MariaDB installation
secure_mariadb() { secure_mariadb() {
sudo mysql_secure_installation sudo mysql_secure_installation
dialog --msgbox "MariaDB installation secured." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB installation secured successfully." 10 30
else
dialog --msgbox "Failed to secure MariaDB installation." 10 30
fi
} }
# Function to create a database # Function to create a database
@ -54,7 +81,11 @@ create_database() {
DATABASE=$(dialog --inputbox "Enter the name of the database to create:" 10 40 3>&1 1>&2 2>&3 3>&-) DATABASE=$(dialog --inputbox "Enter the name of the database to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then if [[ -n "$DATABASE" ]]; then
mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE;" mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE;"
dialog --msgbox "Database '$DATABASE' created successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' created successfully." 10 60
else
dialog --msgbox "Failed to create database '$DATABASE'." 10 60
fi
fi fi
} }
@ -64,7 +95,11 @@ create_table() {
TABLE=$(dialog --inputbox "Enter the name of the table to create:" 10 40 3>&1 1>&2 2>&3 3>&-) TABLE=$(dialog --inputbox "Enter the name of the table to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
mysql -e "USE $DATABASE; CREATE TABLE IF NOT EXISTS $TABLE (id INT AUTO_INCREMENT PRIMARY KEY);" mysql -e "USE $DATABASE; CREATE TABLE IF NOT EXISTS $TABLE (id INT AUTO_INCREMENT PRIMARY KEY);"
dialog --msgbox "Table '$TABLE' created in database '$DATABASE' successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Table '$TABLE' created in database '$DATABASE' successfully." 10 60
else
dialog --msgbox "Failed to create table '$TABLE' in database '$DATABASE'." 10 60
fi
fi fi
} }
@ -75,7 +110,11 @@ insert_data() {
DATA=$(dialog --inputbox "Enter data to insert into table (e.g., 'value1, value2'):" 10 60 3>&1 1>&2 2>&3 3>&-) DATA=$(dialog --inputbox "Enter data to insert into table (e.g., 'value1, value2'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; then if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; then
mysql -e "USE $DATABASE; INSERT INTO $TABLE VALUES ($DATA);" mysql -e "USE $DATABASE; INSERT INTO $TABLE VALUES ($DATA);"
dialog --msgbox "Data inserted into table '$TABLE' in database '$DATABASE' successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Data inserted into table '$TABLE' in database '$DATABASE' successfully." 10 60
else
dialog --msgbox "Failed to insert data into table '$TABLE' in database '$DATABASE'." 10 60
fi
fi fi
} }
@ -86,8 +125,12 @@ query_data() {
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
QUERY=$(dialog --inputbox "Enter SQL query (e.g., 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-) QUERY=$(dialog --inputbox "Enter SQL query (e.g., 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$QUERY" ]]; then if [[ -n "$QUERY" ]]; then
mysql -e "USE $DATABASE; $QUERY" RESULT=$(mysql -e "USE $DATABASE; $QUERY")
dialog --msgbox "Query executed successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Query executed successfully. Result:\n$RESULT" 20 80
else
dialog --msgbox "Failed to execute query on table '$TABLE' in database '$DATABASE'." 10 60
fi
fi fi
fi fi
} }
@ -97,7 +140,11 @@ backup_database() {
DATABASE=$(dialog --inputbox "Enter the name of the database to backup:" 10 40 3>&1 1>&2 2>&3 3>&-) DATABASE=$(dialog --inputbox "Enter the name of the database to backup:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then if [[ -n "$DATABASE" ]]; then
mysqldump $DATABASE > $DATABASE.sql mysqldump $DATABASE > $DATABASE.sql
dialog --msgbox "Database '$DATABASE' backed up to '$DATABASE.sql' successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' backed up to '$DATABASE.sql' successfully." 10 60
else
dialog --msgbox "Failed to backup database '$DATABASE'." 10 60
fi
fi fi
} }
@ -108,7 +155,11 @@ restore_database() {
FILE=$(dialog --inputbox "Enter the path to the SQL file to restore:" 10 60 3>&1 1>&2 2>&3 3>&-) FILE=$(dialog --inputbox "Enter the path to the SQL file to restore:" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -f "$FILE" ]]; then if [[ -f "$FILE" ]]; then
mysql $DATABASE < $FILE mysql $DATABASE < $FILE
dialog --msgbox "Database '$DATABASE' restored successfully." 10 60 if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' restored successfully." 10 60
else
dialog --msgbox "Failed to restore database '$DATABASE'." 10 60
fi
else else
dialog --msgbox "File not found or invalid." 10 60 dialog --msgbox "File not found or invalid." 10 60
fi fi
@ -137,13 +188,14 @@ configure_mariadb() {
14 "Return to Main Menu" \ 14 "Return to Main Menu" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -ne 0 ]; then
clear
break break
fi fi
clear
case $CHOICE in case $CHOICE in
1) install_mariadb_if_needed ;; 1) install_mariadb_if_needed ;;
2) start_mariadb ;; 2) start_mariadb ;;

View File

@ -93,6 +93,11 @@ EOF
# Function to enable or disable Nginx virtual host (site) # Function to enable or disable Nginx virtual host (site)
enable_disable_nginx_site() { enable_disable_nginx_site() {
SITE=$(dialog --inputbox "Enter the site configuration file name (without .conf):" 10 40 3>&1 1>&2 2>&3 3>&-) SITE=$(dialog --inputbox "Enter the site configuration file name (without .conf):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -z "$SITE" ]]; then
dialog --msgbox "No site configuration file name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Site" \ ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Site" \
--title "Enable/Disable Nginx Site" \ --title "Enable/Disable Nginx Site" \
--menu "Choose an action:" 10 40 2 \ --menu "Choose an action:" 10 40 2 \
@ -100,6 +105,10 @@ enable_disable_nginx_site() {
2 "Disable" \ 2 "Disable" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
case $ACTION in case $ACTION in
1) 1)
sudo ln -s /etc/nginx/sites-available/$SITE /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/$SITE /etc/nginx/sites-enabled/
@ -120,6 +129,11 @@ enable_disable_nginx_site() {
# Function to enable or disable Nginx modules # Function to enable or disable Nginx modules
enable_disable_nginx_module() { enable_disable_nginx_module() {
MODULE=$(dialog --inputbox "Enter the name of the Nginx module to enable/disable (e.g., ssl):" 10 40 3>&1 1>&2 2>&3 3>&-) MODULE=$(dialog --inputbox "Enter the name of the Nginx module to enable/disable (e.g., ssl):" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -z "$MODULE" ]]; then
dialog --msgbox "No module name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Module" \ ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Module" \
--title "Enable/Disable Nginx Module" \ --title "Enable/Disable Nginx Module" \
--menu "Choose an action:" 10 40 2 \ --menu "Choose an action:" 10 40 2 \
@ -127,6 +141,10 @@ enable_disable_nginx_module() {
2 "Disable" \ 2 "Disable" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
case $ACTION in case $ACTION in
1) 1)
sudo ln -s /etc/nginx/modules-available/$MODULE.conf /etc/nginx/modules-enabled/ sudo ln -s /etc/nginx/modules-available/$MODULE.conf /etc/nginx/modules-enabled/
@ -157,7 +175,7 @@ configure_nginx() {
while true; do while true; do
CHOICE=$(dialog --clear --backtitle "Configure Nginx" \ CHOICE=$(dialog --clear --backtitle "Configure Nginx" \
--title "Nginx Menu" \ --title "Nginx Menu" \
--menu "Choose an option:" 20 60 11 \ --menu "Choose an option:" 20 60 12 \
1 "Install/Check Nginx" \ 1 "Install/Check Nginx" \
2 "Start Nginx" \ 2 "Start Nginx" \
3 "Stop Nginx" \ 3 "Stop Nginx" \
@ -172,13 +190,13 @@ configure_nginx() {
12 "Return to Main Menu" \ 12 "Return to Main Menu" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -ne 0 ]; then
break break
fi fi
clear
case $CHOICE in case $CHOICE in
1) install_nginx_if_needed ;; 1) install_nginx_if_needed ;;
2) start_nginx ;; 2) start_nginx ;;

View File

@ -107,16 +107,16 @@ main_menu() {
6 "Enable Postfix at Boot" \ 6 "Enable Postfix at Boot" \
7 "Disable Postfix at Boot" \ 7 "Disable Postfix at Boot" \
8 "Secure Postfix Configuration" \ 8 "Secure Postfix Configuration" \
9 "Exit" \ 9 "Return to Main Menu" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
clear
# Check if user canceled # Check if user canceled
if [ $? -eq 1 ]; then if [ $? -ne 0 ]; then
break break
fi fi
clear
case $CHOICE in case $CHOICE in
1) install_postfix_if_needed ;; 1) install_postfix_if_needed ;;
2) configure_postfix ;; 2) configure_postfix ;;

View File

@ -1,147 +1,199 @@
#!/bin/bash #!/bin/bash
# Function to install PostgreSQL if not installed # Função para instalar PostgreSQL, se necessário
install_postgresql_if_needed() { install_postgresql_if_needed() {
if ! dpkg -l postgresql > /dev/null 2>&1; then if ! dpkg -l postgresql > /dev/null 2>&1; then
echo "PostgreSQL is not installed. Installing..." echo "PostgreSQL não está instalado. Instalando..."
if sudo apt-get install -y postgresql; then if sudo apt-get install -y postgresql; then
echo "PostgreSQL installed successfully." echo "PostgreSQL instalado com sucesso."
dialog --msgbox "PostgreSQL instalado com sucesso." 10 30
else else
echo "Failed to install PostgreSQL. Exiting." echo "Falha ao instalar PostgreSQL. Saindo."
dialog --msgbox "Falha ao instalar PostgreSQL. Saindo." 10 30
exit 1 exit 1
fi fi
else
dialog --msgbox "PostgreSQL já está instalado." 10 30
fi fi
} }
# Function to start PostgreSQL # Função para iniciar PostgreSQL
start_postgresql() { start_postgresql() {
sudo systemctl start postgresql sudo systemctl start postgresql
dialog --msgbox "PostgreSQL started." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL iniciado com sucesso." 10 30
else
dialog --msgbox "Falha ao iniciar PostgreSQL." 10 30
fi
} }
# Function to stop PostgreSQL # Função para parar PostgreSQL
stop_postgresql() { stop_postgresql() {
sudo systemctl stop postgresql sudo systemctl stop postgresql
dialog --msgbox "PostgreSQL stopped." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL parado com sucesso." 10 30
else
dialog --msgbox "Falha ao parar PostgreSQL." 10 30
fi
} }
# Function to restart PostgreSQL # Função para reiniciar PostgreSQL
restart_postgresql() { restart_postgresql() {
sudo systemctl restart postgresql sudo systemctl restart postgresql
dialog --msgbox "PostgreSQL restarted." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL reiniciado com sucesso." 10 30
else
dialog --msgbox "Falha ao reiniciar PostgreSQL." 10 30
fi
} }
# Function to enable PostgreSQL at boot # Função para habilitar PostgreSQL na inicialização
enable_postgresql_at_boot() { enable_postgresql_at_boot() {
sudo systemctl enable postgresql sudo systemctl enable postgresql
dialog --msgbox "PostgreSQL enabled at boot." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL habilitado na inicialização com sucesso." 10 30
else
dialog --msgbox "Falha ao habilitar PostgreSQL na inicialização." 10 30
fi
} }
# Function to disable PostgreSQL at boot # Função para desabilitar PostgreSQL na inicialização
disable_postgresql_at_boot() { disable_postgresql_at_boot() {
sudo systemctl disable postgresql sudo systemctl disable postgresql
dialog --msgbox "PostgreSQL disabled at boot." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL desabilitado na inicialização com sucesso." 10 30
else
dialog --msgbox "Falha ao desabilitar PostgreSQL na inicialização." 10 30
fi
} }
# Function to secure PostgreSQL installation # Função para garantir a instalação do PostgreSQL
secure_postgresql() { secure_postgresql() {
sudo passwd postgres sudo passwd postgres
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_password';" sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_password';"
dialog --msgbox "PostgreSQL installation secured." 10 30 if [[ $? -eq 0 ]]; then
dialog --msgbox "Instalação do PostgreSQL protegida com sucesso." 10 30
else
dialog --msgbox "Falha ao proteger a instalação do PostgreSQL." 10 30
fi
} }
# Function to create a database # Função para criar um banco de dados
create_database() { create_database() {
DATABASE=$(dialog --inputbox "Enter the name of the database to create:" 10 40 3>&1 1>&2 2>&3 3>&-) DATABASE=$(dialog --inputbox "Digite o nome do banco de dados a ser criado:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then if [[ -n "$DATABASE" ]]; then
sudo -u postgres createdb $DATABASE sudo -u postgres createdb $DATABASE
dialog --msgbox "Database '$DATABASE' created successfully." 10 60 if [[ $? -eq 0 ]]; então
fi dialog --msgbox "Banco de dados '$DATABASE' criado com sucesso." 10 60
}
# Function to create a table
create_table() {
DATABASE=$(dialog --inputbox "Enter the name of the database:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Enter the name of the table to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
sudo -u postgres psql -d $DATABASE -c "CREATE TABLE $TABLE (id SERIAL PRIMARY KEY);"
dialog --msgbox "Table '$TABLE' created in database '$DATABASE' successfully." 10 60
fi
}
# Function to insert data into a table
insert_data() {
DATABASE=$(dialog --inputbox "Enter the name of the database:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Enter the name of the table to insert data into:" 10 40 3>&1 1>&2 2>&3 3>&-)
DATA=$(dialog --inputbox "Enter data to insert into table (e.g., 'value1, value2'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; then
sudo -u postgres psql -d $DATABASE -c "INSERT INTO $TABLE VALUES ($DATA);"
dialog --msgbox "Data inserted into table '$TABLE' in database '$DATABASE' successfully." 10 60
fi
}
# Function to query data from a table
query_data() {
DATABASE=$(dialog --inputbox "Enter the name of the database:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Enter the name of the table to query from:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
QUERY=$(dialog --inputbox "Enter SQL query (e.g., 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$QUERY" ]]; then
sudo -u postgres psql -d $DATABASE -c "$QUERY"
dialog --msgbox "Query executed successfully." 10 60
fi
fi
}
# Function to backup the database
backup_database() {
DATABASE=$(dialog --inputbox "Enter the name of the database to backup:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then
sudo -u postgres pg_dump $DATABASE > $DATABASE.sql
dialog --msgbox "Database '$DATABASE' backed up to '$DATABASE.sql' successfully." 10 60
fi
}
# Function to restore the database
restore_database() {
DATABASE=$(dialog --inputbox "Enter the name of the database to restore into:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then
FILE=$(dialog --inputbox "Enter the path to the SQL file to restore:" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -f "$FILE" ]]; then
sudo -u postgres psql -d $DATABASE < $FILE
dialog --msgbox "Database '$DATABASE' restored successfully." 10 60
else else
dialog --msgbox "File not found or invalid." 10 60 dialog --msgbox "Falha ao criar o banco de dados '$DATABASE'." 10 60
fi fi
fi fi
} }
# Function to configure PostgreSQL # Função para criar uma tabela
create_table() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela a ser criada:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; então
sudo -u postgres psql -d $DATABASE -c "CREATE TABLE $TABLE (id SERIAL PRIMARY KEY);"
if [[ $? -eq 0 ]]; então
dialog --msgbox "Tabela '$TABLE' criada no banco de dados '$DATABASE' com sucesso." 10 60
else
dialog --msgbox "Falha ao criar a tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para inserir dados em uma tabela
insert_data() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela para inserir dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
DATA=$(dialog --inputbox "Digite os dados para inserir na tabela (por exemplo, 'valor1, valor2'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; então
sudo -u postgres psql -d $DATABASE -c "INSERT INTO $TABLE VALUES ($DATA);"
if [[ $? -eq 0 ]]; então
dialog --msgbox "Dados inseridos na tabela '$TABLE' no banco de dados '$DATABASE' com sucesso." 10 60
else
dialog --msgbox "Falha ao inserir dados na tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para consultar dados de uma tabela
query_data() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela para consultar:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; então
QUERY=$(dialog --inputbox "Digite a consulta SQL (por exemplo, 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$QUERY" ]]; então
RESULT=$(sudo -u postgres psql -d $DATABASE -c "$QUERY")
if [[ $? -eq 0 ]]; então
dialog --msgbox "Consulta executada com sucesso. Resultado:\n$RESULT" 20 80
else
dialog --msgbox "Falha ao executar a consulta na tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
fi
}
# Função para fazer backup do banco de dados
backup_database() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados para fazer backup:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; então
sudo -u postgres pg_dump $DATABASE > $DATABASE.sql
if [[ $? -eq 0 ]]; então
dialog --msgbox "Banco de dados '$DATABASE' feito backup para '$DATABASE.sql' com sucesso." 10 60
else
dialog --msgbox "Falha ao fazer backup do banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para restaurar o banco de dados
restore_database() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados para restaurar:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; então
FILE=$(dialog --inputbox "Digite o caminho para o arquivo SQL para restaurar:" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -f "$FILE" ]]; então
sudo -u postgres psql -d $DATABASE < $FILE
if [[ $? -eq 0 ]]; então
dialog --msgbox "Banco de dados '$DATABASE' restaurado com sucesso." 10 60
else
dialog --msgbox "Falha ao restaurar o banco de dados '$DATABASE'." 10 60
fi
else
dialog --msgbox "Arquivo não encontrado ou inválido." 10 60
fi
fi
}
# Função para configurar PostgreSQL
configure_postgresql() { configure_postgresql() {
while true; do while true; do
CHOICE=$(dialog --clear --backtitle "Configure PostgreSQL" \ CHOICE=$(dialog --clear --backtitle "Configurar PostgreSQL" \
--title "PostgreSQL Menu" \ --title "Menu do PostgreSQL" \
--menu "Choose an option:" 20 60 14 \ --menu "Escolha uma opção:" 20 60 14 \
1 "Install/Check PostgreSQL" \ 1 "Instalar/Verificar PostgreSQL" \
2 "Start PostgreSQL" \ 2 "Iniciar PostgreSQL" \
3 "Stop PostgreSQL" \ 3 "Parar PostgreSQL" \
4 "Restart PostgreSQL" \ 4 "Reiniciar PostgreSQL" \
5 "Enable PostgreSQL at Boot" \ 5 "Habilitar PostgreSQL na Inicialização" \
6 "Disable PostgreSQL at Boot" \ 6 "Desabilitar PostgreSQL na Inicialização" \
7 "Secure PostgreSQL Installation" \ 7 "Proteger Instalação do PostgreSQL" \
8 "Create Database" \ 8 "Criar Banco de Dados" \
9 "Create Table" \ 9 "Criar Tabela" \
10 "Insert Data into Table" \ 10 "Inserir Dados na Tabela" \
11 "Query Data from Table" \ 11 "Consultar Dados da Tabela" \
12 "Backup Database" \ 12 "Fazer Backup do Banco de Dados" \
13 "Restore Database" \ 13 "Restaurar Banco de Dados" \
14 "Return to Main Menu" \ 14 "Retornar ao Menu Principal" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3 3>&-)
clear clear
# Check if user canceled # Verificar se o usuário cancelou
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; então
break break
fi fi
@ -160,11 +212,11 @@ configure_postgresql() {
12) backup_database ;; 12) backup_database ;;
13) restore_database ;; 13) restore_database ;;
14) break ;; 14) break ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Opção inválida." 10 30 ;;
esac esac
done done
} }
# Show main configuration menu # Mostrar menu de configuração principal
configure_postgresql configure_postgresql

View File

@ -81,8 +81,11 @@ while true; do
fi fi
done done
# Convert selection into an array # Convert selection indices into package names
IFS=" " read -r -a packages_to_install <<< "$selections" packages_to_install=()
for index in $selections; do
packages_to_install+=("${PACKAGES[$((index - 1))]}")
done
# Call function to install selected packages # Call function to install selected packages
install_selected_packages "${packages_to_install[@]}" install_selected_packages "${packages_to_install[@]}"

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# Directory where the scripts are located
SCRIPT_DIR="/usr/local/bin"
# Function to display the main menu # Function to display the main menu
main_menu() { main_menu() {
while true; do while true; do
@ -17,10 +20,9 @@ main_menu() {
9 "Configure Postfix" \ 9 "Configure Postfix" \
10 "Configure MariaDB" \ 10 "Configure MariaDB" \
11 "Configure PostgreSQL" \ 11 "Configure PostgreSQL" \
12 "Configure SQLite" \ 12 "Configure Docker" \
13 "Configure PHP and Docker" \ 13 "Exit" \
14 "Exit" \ 3>&1 1>&2 2>&3)
3>&1 1>&2 2>&3 3>&-)
# Check if user canceled or exited # Check if user canceled or exited
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
@ -32,20 +34,19 @@ main_menu() {
clear clear
case $CHOICE in case $CHOICE in
1) sudo ./configure_ssh.sh ;; 1) sudo "$SCRIPT_DIR/configure_ssh.sh" ;;
2) sudo ./configure_static_ip.sh ;; 2) sudo "$SCRIPT_DIR/configure_static_ip.sh" ;;
3) sudo ./update_and_install.sh ;; 3) sudo "$SCRIPT_DIR/update_and_install.sh" ;;
4) sudo ./configure_firewalld.sh ;; 4) sudo "$SCRIPT_DIR/configure_firewalld.sh" ;;
5) sudo ./configure_hostname.sh ;; 5) sudo "$SCRIPT_DIR/configure_hostname.sh" ;;
6) sudo ./create_user.sh ;; 6) sudo "$SCRIPT_DIR/create_user.sh" ;;
7) sudo ./configure_nginx.sh ;; 7) sudo "$SCRIPT_DIR/configure_nginx.sh" ;;
8) sudo ./configure_apache2.sh ;; 8) sudo "$SCRIPT_DIR/configure_apache2.sh" ;;
9) sudo ./configure_postfix.sh ;; 9) sudo "$SCRIPT_DIR/configure_postfix.sh" ;;
10) sudo ./configure_mariadb.sh ;; 10) sudo "$SCRIPT_DIR/configure_mariadb.sh" ;;
11) sudo ./configure_postgresql.sh ;; 11) sudo "$SCRIPT_DIR/configure_postgresql.sh" ;;
12) sudo ./configure_sqlite.sh ;; 12) sudo "$SCRIPT_DIR/configure_docker.sh" ;;
13) sudo ./configure_php_and_docker.sh ;; 13) clear; echo "Exiting..."; exit 0 ;;
14) clear; echo "Exiting..."; exit 0 ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac
done done
@ -66,13 +67,19 @@ This tool will help you configure various aspects of your server, including:
9. Postfix: Configure the Postfix mail server. 9. Postfix: Configure the Postfix mail server.
10. MariaDB: Set up the MariaDB database server. 10. MariaDB: Set up the MariaDB database server.
11. PostgreSQL: Set up the PostgreSQL database server. 11. PostgreSQL: Set up the PostgreSQL database server.
12. SQLite: Configure the SQLite database. 12. PHP: Configure PHP and related settings.
13. PHP: Configure PHP and related settings. 13. Docker: Configure Docker and manage containers.
14. Docker: Configure Docker and manage containers. 14. Exit: Exit the configuration tool.
15. Exit: Exit the configuration tool.
Please select an option from the menu to begin." 20 60 Please select an option from the menu to begin." 20 60
# Check if user canceled the welcome message
if [[ $? -ne 0 ]]; then
clear
echo "Welcome message closed or canceled. Exiting..."
exit 0
fi
# Display main menu # Display main menu
main_menu main_menu

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# Directory where the scripts are located
SCRIPT_DIR="/usr/local/bin"
# Function to display the main menu # Function to display the main menu
main_menu() { main_menu() {
while true; do while true; do
@ -20,7 +23,7 @@ main_menu() {
12 "Configure SQLite" \ 12 "Configure SQLite" \
13 "Configure PHP and Docker" \ 13 "Configure PHP and Docker" \
14 "Exit" \ 14 "Exit" \
3>&1 1>&2 2>&3 3>&-) 3>&1 1>&2 2>&3)
# Check if user canceled or exited # Check if user canceled or exited
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
@ -32,19 +35,19 @@ main_menu() {
clear clear
case $CHOICE in case $CHOICE in
1) sudo ./configure_ssh.sh ;; 1) sudo "$SCRIPT_DIR/configure_ssh.sh" ;;
2) sudo ./configure_static_ip.sh ;; 2) sudo "$SCRIPT_DIR/configure_static_ip.sh" ;;
3) sudo ./update_and_install.sh ;; 3) sudo "$SCRIPT_DIR/update_and_install.sh" ;;
4) sudo ./configure_firewalld.sh ;; 4) sudo "$SCRIPT_DIR/configure_firewalld.sh" ;;
5) sudo ./configure_hostname.sh ;; 5) sudo "$SCRIPT_DIR/configure_hostname.sh" ;;
6) sudo ./create_user.sh ;; 6) sudo "$SCRIPT_DIR/create_user.sh" ;;
7) sudo ./configure_nginx.sh ;; 7) sudo "$SCRIPT_DIR/configure_nginx.sh" ;;
8) sudo ./configure_apache2.sh ;; 8) sudo "$SCRIPT_DIR/configure_apache2.sh" ;;
9) sudo ./configure_postfix.sh ;; 9) sudo "$SCRIPT_DIR/configure_postfix.sh" ;;
10) sudo ./configure_mariadb.sh ;; 10) sudo "$SCRIPT_DIR/configure_mariadb.sh" ;;
11) sudo ./configure_postgresql.sh ;; 11) sudo "$SCRIPT_DIR/configure_postgresql.sh" ;;
12) sudo ./configure_sqlite.sh ;; 12) sudo "$SCRIPT_DIR/configure_sqlite.sh" ;;
13) sudo ./configure_php_and_docker.sh ;; 13) sudo "$SCRIPT_DIR/configure_php_and_docker.sh" ;;
14) clear; echo "Exiting..."; exit 0 ;; 14) clear; echo "Exiting..."; exit 0 ;;
*) dialog --msgbox "Invalid option." 10 30 ;; *) dialog --msgbox "Invalid option." 10 30 ;;
esac esac