update server scripts
This commit is contained in:
parent
db657149f4
commit
381d575ea7
|
@ -1,105 +1,196 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check if Apache is installed
|
||||
check_apache() {
|
||||
if ! command -v apache2 &> /dev/null; then
|
||||
dialog --msgbox "Apache is not installed. Installing now..." 10 50
|
||||
sudo apt update
|
||||
sudo apt install -y apache2
|
||||
dialog --msgbox "Apache has been installed successfully." 10 50
|
||||
else
|
||||
dialog --msgbox "Apache is already installed." 10 50
|
||||
# Function to install Apache if not installed
|
||||
install_apache_if_needed() {
|
||||
if ! dpkg -l apache2 > /dev/null 2>&1; then
|
||||
echo "Apache is not installed. Installing..."
|
||||
if sudo apt-get install -y apache2; then
|
||||
echo "Apache installed successfully."
|
||||
else
|
||||
echo "Failed to install Apache. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start Apache service
|
||||
# Function to install Certbot if not installed
|
||||
install_certbot_if_needed() {
|
||||
if ! command -v certbot &> /dev/null; then
|
||||
echo "Certbot is not installed. Installing..."
|
||||
if sudo apt-get install -y certbot python3-certbot-apache; then
|
||||
echo "Certbot installed successfully."
|
||||
else
|
||||
echo "Failed to install Certbot. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start Apache
|
||||
start_apache() {
|
||||
sudo systemctl start apache2
|
||||
dialog --msgbox "Apache service started." 10 30
|
||||
dialog --msgbox "Apache started." 10 30
|
||||
}
|
||||
|
||||
# Function to stop Apache service
|
||||
# Function to stop Apache
|
||||
stop_apache() {
|
||||
sudo systemctl stop apache2
|
||||
dialog --msgbox "Apache service stopped." 10 30
|
||||
dialog --msgbox "Apache stopped." 10 30
|
||||
}
|
||||
|
||||
# Function to restart Apache service
|
||||
# Function to restart Apache
|
||||
restart_apache() {
|
||||
sudo systemctl restart apache2
|
||||
dialog --msgbox "Apache service restarted." 10 30
|
||||
dialog --msgbox "Apache restarted." 10 30
|
||||
}
|
||||
|
||||
# Function to enable Apache service
|
||||
enable_apache() {
|
||||
# Function to enable Apache at boot
|
||||
enable_apache_at_boot() {
|
||||
sudo systemctl enable apache2
|
||||
dialog --msgbox "Apache service enabled." 10 30
|
||||
dialog --msgbox "Apache enabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to disable Apache service
|
||||
disable_apache() {
|
||||
# Function to disable Apache at boot
|
||||
disable_apache_at_boot() {
|
||||
sudo systemctl disable apache2
|
||||
dialog --msgbox "Apache service disabled." 10 30
|
||||
dialog --msgbox "Apache disabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to configure Apache virtual host
|
||||
configure_apache_virtual_host() {
|
||||
DOMAIN=$(dialog --inputbox "Enter the domain name (e.g., example.com):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
# Function to secure Apache installation
|
||||
secure_apache() {
|
||||
echo "Apache does not require additional security configuration."
|
||||
dialog --msgbox "Apache installation secured." 10 30
|
||||
}
|
||||
|
||||
sudo mkdir -p /var/www/$DOMAIN/html
|
||||
sudo chown -R $USER:$USER /var/www/$DOMAIN/html
|
||||
sudo chmod -R 755 /var/www/$DOMAIN
|
||||
|
||||
cat <<EOF | sudo tee /etc/apache2/sites-available/$DOMAIN.conf > /dev/null
|
||||
# Function to 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>&-)
|
||||
if [[ -n "$DOMAIN" ]]; then
|
||||
sudo mkdir -p /var/www/$DOMAIN/public_html
|
||||
sudo chown -R www-data:www-data /var/www/$DOMAIN/public_html
|
||||
sudo chmod -R 755 /var/www/$DOMAIN
|
||||
cat << EOF | sudo tee /etc/apache2/sites-available/$DOMAIN.conf > /dev/null
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin webmaster@localhost
|
||||
ServerAdmin webmaster@$DOMAIN
|
||||
ServerName $DOMAIN
|
||||
ServerAlias www.$DOMAIN
|
||||
DocumentRoot /var/www/$DOMAIN/html
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
DocumentRoot /var/www/$DOMAIN/public_html
|
||||
ErrorLog \${APACHE_LOG_DIR}/error.log
|
||||
CustomLog \${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
EOF
|
||||
|
||||
sudo a2ensite $DOMAIN.conf
|
||||
sudo systemctl reload apache2
|
||||
dialog --msgbox "Apache virtual host for $DOMAIN configured successfully." 10 50
|
||||
sudo a2ensite $DOMAIN.conf
|
||||
sudo systemctl reload apache2
|
||||
dialog --msgbox "Virtual host for $DOMAIN configured successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function to configure Apache
|
||||
configure_apache() {
|
||||
check_apache
|
||||
# Function to enable or disable Apache virtual host (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>&-)
|
||||
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Site" \
|
||||
--title "Enable/Disable Apache Site" \
|
||||
--menu "Choose an action:" 10 40 2 \
|
||||
1 "Enable" \
|
||||
2 "Disable" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
case $ACTION in
|
||||
1)
|
||||
sudo a2ensite $SITE.conf
|
||||
sudo systemctl reload apache2
|
||||
dialog --msgbox "Apache site $SITE enabled." 10 30
|
||||
;;
|
||||
2)
|
||||
sudo a2dissite $SITE.conf
|
||||
sudo systemctl reload apache2
|
||||
dialog --msgbox "Apache site $SITE disabled." 10 30
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 10 30
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to enable or disable Apache modules
|
||||
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>&-)
|
||||
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Module" \
|
||||
--title "Enable/Disable Apache Module" \
|
||||
--menu "Choose an action:" 10 40 2 \
|
||||
1 "Enable" \
|
||||
2 "Disable" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
case $ACTION in
|
||||
1)
|
||||
sudo a2enmod $MODULE
|
||||
sudo systemctl restart apache2
|
||||
dialog --msgbox "Apache module $MODULE enabled." 10 30
|
||||
;;
|
||||
2)
|
||||
sudo a2dismod $MODULE
|
||||
sudo systemctl restart apache2
|
||||
dialog --msgbox "Apache module $MODULE disabled." 10 30
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 10 30
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to configure Certbot for Apache
|
||||
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>&-)
|
||||
if [[ -n "$DOMAIN" ]]; then
|
||||
sudo certbot --apache -d $DOMAIN
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure Apache
|
||||
configure_apache() {
|
||||
while true; do
|
||||
local APACHE_CHOICE
|
||||
APACHE_CHOICE=$(dialog --clear --backtitle "Apache Configuration" \
|
||||
--title "Apache Menu" \
|
||||
--menu "Choose an option:" 20 60 10 \
|
||||
1 "Start Apache" \
|
||||
2 "Stop Apache" \
|
||||
3 "Restart Apache" \
|
||||
4 "Enable Apache at Boot" \
|
||||
5 "Disable Apache at Boot" \
|
||||
6 "Configure Virtual Host" \
|
||||
7 "Back to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
CHOICE=$(dialog --clear --backtitle "Configure Apache" \
|
||||
--title "Apache Menu" \
|
||||
--menu "Choose an option:" 20 60 11 \
|
||||
1 "Install/Check Apache" \
|
||||
2 "Start Apache" \
|
||||
3 "Stop Apache" \
|
||||
4 "Restart Apache" \
|
||||
5 "Enable Apache at Boot" \
|
||||
6 "Disable Apache at Boot" \
|
||||
7 "Secure Apache Installation" \
|
||||
8 "Configure Virtual Host" \
|
||||
9 "Enable/Disable Apache Site" \
|
||||
10 "Enable/Disable Apache Module" \
|
||||
11 "Configure Certbot" \
|
||||
12 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then break; fi
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case "$APACHE_CHOICE" in
|
||||
1) start_apache ;;
|
||||
2) stop_apache ;;
|
||||
3) restart_apache ;;
|
||||
4) enable_apache ;;
|
||||
5) disable_apache ;;
|
||||
6) configure_apache_virtual_host ;;
|
||||
7) break ;;
|
||||
*) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;;
|
||||
case $CHOICE in
|
||||
1) install_apache_if_needed ;;
|
||||
2) start_apache ;;
|
||||
3) stop_apache ;;
|
||||
4) restart_apache ;;
|
||||
5) enable_apache_at_boot ;;
|
||||
6) disable_apache_at_boot ;;
|
||||
7) secure_apache ;;
|
||||
8) configure_apache_virtual_hosts ;;
|
||||
9) enable_disable_apache_site ;;
|
||||
10) enable_disable_apache_module ;;
|
||||
11) configure_certbot ;;
|
||||
12) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Execute the main function to configure Apache
|
||||
# Show main configuration menu
|
||||
configure_apache
|
||||
|
||||
|
|
|
@ -1,81 +1,169 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check if MariaDB is installed
|
||||
check_mariadb() {
|
||||
if ! command -v mariadb &> /dev/null; then
|
||||
dialog --msgbox "MariaDB is not installed. Installing now..." 10 50
|
||||
sudo apt update
|
||||
sudo apt install -y mariadb-server
|
||||
sudo mysql_secure_installation
|
||||
dialog --msgbox "MariaDB has been installed and secured successfully." 10 50
|
||||
else
|
||||
dialog --msgbox "MariaDB is already installed." 10 50
|
||||
# Function to install MariaDB if not installed
|
||||
install_mariadb_if_needed() {
|
||||
if ! dpkg -l mariadb-server > /dev/null 2>&1; then
|
||||
echo "MariaDB is not installed. Installing..."
|
||||
if sudo apt-get install -y mariadb-server; then
|
||||
echo "MariaDB installed successfully."
|
||||
else
|
||||
echo "Failed to install MariaDB. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start MariaDB service
|
||||
# Function to start MariaDB
|
||||
start_mariadb() {
|
||||
sudo systemctl start mariadb
|
||||
dialog --msgbox "MariaDB service started." 10 30
|
||||
dialog --msgbox "MariaDB started." 10 30
|
||||
}
|
||||
|
||||
# Function to stop MariaDB service
|
||||
# Function to stop MariaDB
|
||||
stop_mariadb() {
|
||||
sudo systemctl stop mariadb
|
||||
dialog --msgbox "MariaDB service stopped." 10 30
|
||||
dialog --msgbox "MariaDB stopped." 10 30
|
||||
}
|
||||
|
||||
# Function to restart MariaDB service
|
||||
# Function to restart MariaDB
|
||||
restart_mariadb() {
|
||||
sudo systemctl restart mariadb
|
||||
dialog --msgbox "MariaDB service restarted." 10 30
|
||||
dialog --msgbox "MariaDB restarted." 10 30
|
||||
}
|
||||
|
||||
# Function to enable MariaDB service
|
||||
enable_mariadb() {
|
||||
# Function to enable MariaDB at boot
|
||||
enable_mariadb_at_boot() {
|
||||
sudo systemctl enable mariadb
|
||||
dialog --msgbox "MariaDB service enabled." 10 30
|
||||
dialog --msgbox "MariaDB enabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to disable MariaDB service
|
||||
disable_mariadb() {
|
||||
# Function to disable MariaDB at boot
|
||||
disable_mariadb_at_boot() {
|
||||
sudo systemctl disable mariadb
|
||||
dialog --msgbox "MariaDB service disabled." 10 30
|
||||
dialog --msgbox "MariaDB disabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to secure MariaDB installation
|
||||
secure_mariadb() {
|
||||
sudo mysql_secure_installation
|
||||
dialog --msgbox "MariaDB installation secured." 10 30
|
||||
}
|
||||
|
||||
# Function to create a database
|
||||
create_database() {
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the database to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" ]]; then
|
||||
mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE;"
|
||||
dialog --msgbox "Database '$DATABASE' created successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# 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
|
||||
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
|
||||
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
|
||||
mysql -e "USE $DATABASE; 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
|
||||
mysql -e "USE $DATABASE; $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
|
||||
mysqldump $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
|
||||
mysql $DATABASE < $FILE
|
||||
dialog --msgbox "Database '$DATABASE' restored successfully." 10 60
|
||||
else
|
||||
dialog --msgbox "File not found or invalid." 10 60
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure MariaDB
|
||||
configure_mariadb() {
|
||||
check_mariadb
|
||||
|
||||
while true; do
|
||||
local MARIADB_CHOICE
|
||||
MARIADB_CHOICE=$(dialog --clear --backtitle "MariaDB Configuration" \
|
||||
--title "MariaDB Menu" \
|
||||
--menu "Choose an option:" 20 60 10 \
|
||||
1 "Start MariaDB" \
|
||||
2 "Stop MariaDB" \
|
||||
3 "Restart MariaDB" \
|
||||
4 "Enable MariaDB at Boot" \
|
||||
5 "Disable MariaDB at Boot" \
|
||||
6 "Secure MariaDB Installation" \
|
||||
7 "Back to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
CHOICE=$(dialog --clear --backtitle "Configure MariaDB" \
|
||||
--title "MariaDB Menu" \
|
||||
--menu "Choose an option:" 20 60 12 \
|
||||
1 "Install/Check MariaDB" \
|
||||
2 "Start MariaDB" \
|
||||
3 "Stop MariaDB" \
|
||||
4 "Restart MariaDB" \
|
||||
5 "Enable MariaDB at Boot" \
|
||||
6 "Disable MariaDB at Boot" \
|
||||
7 "Secure MariaDB Installation" \
|
||||
8 "Create Database" \
|
||||
9 "Create Table" \
|
||||
10 "Insert Data into Table" \
|
||||
11 "Query Data from Table" \
|
||||
12 "Backup Database" \
|
||||
13 "Restore Database" \
|
||||
14 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then break; fi
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case "$MARIADB_CHOICE" in
|
||||
1) start_mariadb ;;
|
||||
2) stop_mariadb ;;
|
||||
3) restart_mariadb ;;
|
||||
4) enable_mariadb ;;
|
||||
5) disable_mariadb ;;
|
||||
6) sudo mysql_secure_installation ;;
|
||||
7) break ;;
|
||||
*) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;;
|
||||
case $CHOICE in
|
||||
1) install_mariadb_if_needed ;;
|
||||
2) start_mariadb ;;
|
||||
3) stop_mariadb ;;
|
||||
4) restart_mariadb ;;
|
||||
5) enable_mariadb_at_boot ;;
|
||||
6) disable_mariadb_at_boot ;;
|
||||
7) secure_mariadb ;;
|
||||
8) create_database ;;
|
||||
9) create_table ;;
|
||||
10) insert_data ;;
|
||||
11) query_data ;;
|
||||
12) backup_database ;;
|
||||
13) restore_database ;;
|
||||
14) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Execute the main function to configure MariaDB
|
||||
# Show main configuration menu
|
||||
configure_mariadb
|
||||
|
||||
|
|
|
@ -1,106 +1,202 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check if NGINX is installed
|
||||
check_nginx() {
|
||||
if ! command -v nginx &> /dev/null; then
|
||||
dialog --msgbox "NGINX is not installed. Installing now..." 10 50
|
||||
sudo apt update
|
||||
sudo apt install -y nginx
|
||||
dialog --msgbox "NGINX has been installed successfully." 10 50
|
||||
else
|
||||
dialog --msgbox "NGINX is already installed." 10 50
|
||||
# Function to install Nginx if not installed
|
||||
install_nginx_if_needed() {
|
||||
if ! dpkg -l nginx > /dev/null 2>&1; then
|
||||
echo "Nginx is not installed. Installing..."
|
||||
if sudo apt-get install -y nginx; then
|
||||
echo "Nginx installed successfully."
|
||||
else
|
||||
echo "Failed to install Nginx. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start NGINX service
|
||||
# Function to install Certbot if not installed
|
||||
install_certbot_if_needed() {
|
||||
if ! command -v certbot &> /dev/null; then
|
||||
echo "Certbot is not installed. Installing..."
|
||||
if sudo apt-get install -y certbot python3-certbot-nginx; then
|
||||
echo "Certbot installed successfully."
|
||||
else
|
||||
echo "Failed to install Certbot. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start Nginx
|
||||
start_nginx() {
|
||||
sudo systemctl start nginx
|
||||
dialog --msgbox "NGINX service started." 10 30
|
||||
dialog --msgbox "Nginx started." 10 30
|
||||
}
|
||||
|
||||
# Function to stop NGINX service
|
||||
# Function to stop Nginx
|
||||
stop_nginx() {
|
||||
sudo systemctl stop nginx
|
||||
dialog --msgbox "NGINX service stopped." 10 30
|
||||
dialog --msgbox "Nginx stopped." 10 30
|
||||
}
|
||||
|
||||
# Function to restart NGINX service
|
||||
# Function to restart Nginx
|
||||
restart_nginx() {
|
||||
sudo systemctl restart nginx
|
||||
dialog --msgbox "NGINX service restarted." 10 30
|
||||
dialog --msgbox "Nginx restarted." 10 30
|
||||
}
|
||||
|
||||
# Function to enable NGINX service
|
||||
enable_nginx() {
|
||||
# Function to enable Nginx at boot
|
||||
enable_nginx_at_boot() {
|
||||
sudo systemctl enable nginx
|
||||
dialog --msgbox "NGINX service enabled." 10 30
|
||||
dialog --msgbox "Nginx enabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to disable NGINX service
|
||||
disable_nginx() {
|
||||
# Function to disable Nginx at boot
|
||||
disable_nginx_at_boot() {
|
||||
sudo systemctl disable nginx
|
||||
dialog --msgbox "NGINX service disabled." 10 30
|
||||
dialog --msgbox "Nginx disabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to configure NGINX virtual host
|
||||
configure_nginx_virtual_host() {
|
||||
DOMAIN=$(dialog --inputbox "Enter the domain name (e.g., example.com):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
# Function to secure Nginx installation
|
||||
secure_nginx() {
|
||||
echo "Nginx does not require additional security configuration."
|
||||
dialog --msgbox "Nginx installation secured." 10 30
|
||||
}
|
||||
|
||||
sudo mkdir -p /var/www/$DOMAIN/html
|
||||
sudo chown -R $USER:$USER /var/www/$DOMAIN/html
|
||||
sudo chmod -R 755 /var/www/$DOMAIN
|
||||
|
||||
cat <<EOF | sudo tee /etc/nginx/sites-available/$DOMAIN > /dev/null
|
||||
# Function to configure Nginx virtual hosts
|
||||
configure_nginx_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>&-)
|
||||
if [[ -n "$DOMAIN" ]]; then
|
||||
sudo mkdir -p /var/www/$DOMAIN/html
|
||||
sudo chown -R www-data:www-data /var/www/$DOMAIN/html
|
||||
sudo chmod -R 755 /var/www/$DOMAIN
|
||||
cat << EOF | sudo tee /etc/nginx/sites-available/$DOMAIN > /dev/null
|
||||
server {
|
||||
listen 80;
|
||||
server_name $DOMAIN www.$DOMAIN;
|
||||
listen [::]:80;
|
||||
|
||||
server_name $DOMAIN;
|
||||
|
||||
root /var/www/$DOMAIN/html;
|
||||
index index.html index.htm;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
try_files \$uri \$uri/ =404;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
sudo ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
dialog --msgbox "NGINX virtual host for $DOMAIN configured successfully." 10 50
|
||||
sudo ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/
|
||||
sudo systemctl reload nginx
|
||||
dialog --msgbox "Virtual host for $DOMAIN configured successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function to configure NGINX
|
||||
configure_nginx() {
|
||||
check_nginx
|
||||
# Function to enable or disable Nginx virtual host (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>&-)
|
||||
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Site" \
|
||||
--title "Enable/Disable Nginx Site" \
|
||||
--menu "Choose an action:" 10 40 2 \
|
||||
1 "Enable" \
|
||||
2 "Disable" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
case $ACTION in
|
||||
1)
|
||||
sudo ln -s /etc/nginx/sites-available/$SITE /etc/nginx/sites-enabled/
|
||||
sudo systemctl reload nginx
|
||||
dialog --msgbox "Nginx site $SITE enabled." 10 30
|
||||
;;
|
||||
2)
|
||||
sudo rm -f /etc/nginx/sites-enabled/$SITE
|
||||
sudo systemctl reload nginx
|
||||
dialog --msgbox "Nginx site $SITE disabled." 10 30
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 10 30
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to enable or disable Nginx modules
|
||||
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>&-)
|
||||
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Module" \
|
||||
--title "Enable/Disable Nginx Module" \
|
||||
--menu "Choose an action:" 10 40 2 \
|
||||
1 "Enable" \
|
||||
2 "Disable" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
case $ACTION in
|
||||
1)
|
||||
sudo ln -s /etc/nginx/modules-available/$MODULE.conf /etc/nginx/modules-enabled/
|
||||
sudo systemctl restart nginx
|
||||
dialog --msgbox "Nginx module $MODULE enabled." 10 30
|
||||
;;
|
||||
2)
|
||||
sudo rm -f /etc/nginx/modules-enabled/$MODULE.conf
|
||||
sudo systemctl restart nginx
|
||||
dialog --msgbox "Nginx module $MODULE disabled." 10 30
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 10 30
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to configure Certbot for Nginx
|
||||
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>&-)
|
||||
if [[ -n "$DOMAIN" ]]; then
|
||||
sudo certbot --nginx -d $DOMAIN
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure Nginx
|
||||
configure_nginx() {
|
||||
while true; do
|
||||
local NGINX_CHOICE
|
||||
NGINX_CHOICE=$(dialog --clear --backtitle "NGINX Configuration" \
|
||||
--title "NGINX Menu" \
|
||||
--menu "Choose an option:" 20 60 10 \
|
||||
1 "Start NGINX" \
|
||||
2 "Stop NGINX" \
|
||||
3 "Restart NGINX" \
|
||||
4 "Enable NGINX at Boot" \
|
||||
5 "Disable NGINX at Boot" \
|
||||
6 "Configure Virtual Host" \
|
||||
7 "Back to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
CHOICE=$(dialog --clear --backtitle "Configure Nginx" \
|
||||
--title "Nginx Menu" \
|
||||
--menu "Choose an option:" 20 60 11 \
|
||||
1 "Install/Check Nginx" \
|
||||
2 "Start Nginx" \
|
||||
3 "Stop Nginx" \
|
||||
4 "Restart Nginx" \
|
||||
5 "Enable Nginx at Boot" \
|
||||
6 "Disable Nginx at Boot" \
|
||||
7 "Secure Nginx Installation" \
|
||||
8 "Configure Virtual Host" \
|
||||
9 "Enable/Disable Nginx Site" \
|
||||
10 "Enable/Disable Nginx Module" \
|
||||
11 "Configure Certbot" \
|
||||
12 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then break; fi
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case "$NGINX_CHOICE" in
|
||||
1) start_nginx ;;
|
||||
2) stop_nginx ;;
|
||||
3) restart_nginx ;;
|
||||
4) enable_nginx ;;
|
||||
5) disable_nginx ;;
|
||||
6) configure_nginx_virtual_host ;;
|
||||
7) break ;;
|
||||
*) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;;
|
||||
case $CHOICE in
|
||||
1) install_nginx_if_needed ;;
|
||||
2) start_nginx ;;
|
||||
3) stop_nginx ;;
|
||||
4) restart_nginx ;;
|
||||
5) enable_nginx_at_boot ;;
|
||||
6) disable_nginx_at_boot ;;
|
||||
7) secure_nginx ;;
|
||||
8) configure_nginx_virtual_hosts ;;
|
||||
9) enable_disable_nginx_site ;;
|
||||
10) enable_disable_nginx_module ;;
|
||||
11) configure_certbot ;;
|
||||
12) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Execute the main function to configure NGINX
|
||||
# Show main configuration menu
|
||||
configure_nginx
|
||||
|
||||
|
|
|
@ -0,0 +1,274 @@
|
|||
#!/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
|
||||
install_docker_if_needed() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed. Installing..."
|
||||
if curl -fsSL https://get.docker.com | sudo sh; then
|
||||
echo "Docker installed successfully."
|
||||
else
|
||||
echo "Failed to install Docker. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure Docker
|
||||
configure_docker() {
|
||||
while true; do
|
||||
OPTION=$(dialog --clear --backtitle "Configure Docker" \
|
||||
--title "Docker Configuration Menu" \
|
||||
--menu "Choose an option:" 15 60 6 \
|
||||
1 "Create Docker Network" \
|
||||
2 "Manage Docker Containers" \
|
||||
3 "Manage Docker Images" \
|
||||
4 "Manage Docker Volumes" \
|
||||
5 "Manage Docker Compose" \
|
||||
6 "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) NETWORK=$(dialog --inputbox "Enter Docker network name:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker network create $NETWORK ;;
|
||||
2) manage_docker_containers ;;
|
||||
3) manage_docker_images ;;
|
||||
4) manage_docker_volumes ;;
|
||||
5) manage_docker_compose ;;
|
||||
6) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to manage Docker containers
|
||||
manage_docker_containers() {
|
||||
while true; do
|
||||
ACTION=$(dialog --clear --backtitle "Manage Docker Containers" \
|
||||
--title "Docker Container Management" \
|
||||
--menu "Choose an action:" 15 60 4 \
|
||||
1 "List Containers" \
|
||||
2 "Start Container" \
|
||||
3 "Stop Container" \
|
||||
4 "Return to Docker Menu" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $ACTION in
|
||||
1) sudo docker ps -a ;;
|
||||
2) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker start $CONTAINER ;;
|
||||
3) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker stop $CONTAINER ;;
|
||||
4) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to manage Docker images
|
||||
manage_docker_images() {
|
||||
while true; do
|
||||
ACTION=$(dialog --clear --backtitle "Manage Docker Images" \
|
||||
--title "Docker Image Management" \
|
||||
--menu "Choose an action:" 15 60 4 \
|
||||
1 "List Images" \
|
||||
2 "Pull Image" \
|
||||
3 "Remove Image" \
|
||||
4 "Return to Docker Menu" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $ACTION in
|
||||
1) sudo docker images ;;
|
||||
2) IMAGE=$(dialog --inputbox "Enter the image name (e.g., ubuntu):" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker pull $IMAGE ;;
|
||||
3) IMAGE=$(dialog --inputbox "Enter the image ID or name:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker rmi $IMAGE ;;
|
||||
4) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to manage Docker volumes
|
||||
manage_docker_volumes() {
|
||||
while true; do
|
||||
ACTION=$(dialog --clear --backtitle "Manage Docker Volumes" \
|
||||
--title "Docker Volume Management" \
|
||||
--menu "Choose an action:" 15 60 4 \
|
||||
1 "List Volumes" \
|
||||
2 "Create Volume" \
|
||||
3 "Remove Volume" \
|
||||
4 "Return to Docker Menu" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $ACTION in
|
||||
1) sudo docker volume ls ;;
|
||||
2) VOLUME=$(dialog --inputbox "Enter the volume name:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker volume create $VOLUME ;;
|
||||
3) VOLUME=$(dialog --inputbox "Enter the volume name or ID:" 10 40 3>&1 1>&2 2>&3)
|
||||
sudo docker volume rm $VOLUME ;;
|
||||
4) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to manage Docker Compose
|
||||
manage_docker_compose() {
|
||||
while true; do
|
||||
ACTION=$(dialog --clear --backtitle "Manage Docker Compose" \
|
||||
--title "Docker Compose Management" \
|
||||
--menu "Choose an action:" 15 60 4 \
|
||||
1 "Run Docker Compose" \
|
||||
2 "Stop Docker Compose" \
|
||||
3 "Remove Docker Compose" \
|
||||
4 "Return to Docker Menu" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $ACTION in
|
||||
1) docker_compose_up ;;
|
||||
2) docker_compose_down ;;
|
||||
3) docker_compose_remove ;;
|
||||
4) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Function to run Docker Compose
|
||||
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)
|
||||
if [[ -n "$COMPOSE_FILE" ]]; then
|
||||
sudo docker-compose -f $COMPOSE_FILE up -d
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to stop Docker Compose
|
||||
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)
|
||||
if [[ -n "$COMPOSE_FILE" ]]; then
|
||||
sudo docker-compose -f $COMPOSE_FILE down
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to remove Docker Compose
|
||||
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)
|
||||
if [[ -n "$COMPOSE_FILE" ]]; then
|
||||
sudo docker-compose -f $COMPOSE_FILE down --volumes --remove-orphans
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display the main menu
|
||||
main_menu() {
|
||||
while true; do
|
||||
CHOICE=$(dialog --clear --backtitle "Server Utilities Installation and Configuration" \
|
||||
--title "Main Menu" \
|
||||
--menu "Choose an option:" 15 60 5 \
|
||||
1 "Install/Check PHP" \
|
||||
2 "Configure PHP" \
|
||||
3 "Install/Check Docker" \
|
||||
4 "Configure Docker" \
|
||||
5 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $CHOICE in
|
||||
1) install_php_if_needed ;;
|
||||
2) configure_php ;;
|
||||
3) install_docker_if_needed ;;
|
||||
4) configure_docker ;;
|
||||
5) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Server utilities installation and configuration script completed."
|
||||
}
|
||||
|
||||
# Display main menu
|
||||
main_menu
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to install Postfix if not installed
|
||||
install_postfix_if_needed() {
|
||||
if ! dpkg -l postfix > /dev/null 2>&1; then
|
||||
echo "Postfix is not installed. Installing..."
|
||||
if sudo apt-get install -y postfix; then
|
||||
echo "Postfix installed successfully."
|
||||
else
|
||||
echo "Failed to install Postfix. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure Postfix interactively
|
||||
configure_postfix() {
|
||||
echo "Configuring Postfix..."
|
||||
if ! sudo dpkg-reconfigure postfix; then
|
||||
echo "Failed to configure Postfix."
|
||||
dialog --title "Error" --msgbox "Failed to configure Postfix." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix configured successfully."
|
||||
dialog --title "Success" --msgbox "Postfix configured successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to start Postfix service
|
||||
start_postfix() {
|
||||
echo "Starting Postfix service..."
|
||||
if ! sudo systemctl start postfix; then
|
||||
echo "Failed to start Postfix service."
|
||||
dialog --title "Error" --msgbox "Failed to start Postfix service." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix service started successfully."
|
||||
dialog --title "Success" --msgbox "Postfix service started successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to stop Postfix service
|
||||
stop_postfix() {
|
||||
echo "Stopping Postfix service..."
|
||||
if ! sudo systemctl stop postfix; then
|
||||
echo "Failed to stop Postfix service."
|
||||
dialog --title "Error" --msgbox "Failed to stop Postfix service." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix service stopped successfully."
|
||||
dialog --title "Success" --msgbox "Postfix service stopped successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to restart Postfix service
|
||||
restart_postfix() {
|
||||
echo "Restarting Postfix service..."
|
||||
if ! sudo systemctl restart postfix; then
|
||||
echo "Failed to restart Postfix service."
|
||||
dialog --title "Error" --msgbox "Failed to restart Postfix service." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix service restarted successfully."
|
||||
dialog --title "Success" --msgbox "Postfix service restarted successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to enable Postfix service at boot
|
||||
enable_postfix_at_boot() {
|
||||
echo "Enabling Postfix service at boot..."
|
||||
if ! sudo systemctl enable postfix; then
|
||||
echo "Failed to enable Postfix service at boot."
|
||||
dialog --title "Error" --msgbox "Failed to enable Postfix service at boot." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix service enabled at boot successfully."
|
||||
dialog --title "Success" --msgbox "Postfix service enabled at boot successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to disable Postfix service at boot
|
||||
disable_postfix_at_boot() {
|
||||
echo "Disabling Postfix service at boot..."
|
||||
if ! sudo systemctl disable postfix; then
|
||||
echo "Failed to disable Postfix service at boot."
|
||||
dialog --title "Error" --msgbox "Failed to disable Postfix service at boot." 10 60
|
||||
exit 1
|
||||
fi
|
||||
echo "Postfix service disabled at boot successfully."
|
||||
dialog --title "Success" --msgbox "Postfix service disabled at boot successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to configure Postfix securely (optional)
|
||||
secure_postfix() {
|
||||
echo "Securing Postfix configuration..."
|
||||
# You can add additional secure configuration steps here if needed
|
||||
echo "Postfix configuration secured successfully."
|
||||
dialog --title "Success" --msgbox "Postfix configuration secured successfully." 10 60
|
||||
}
|
||||
|
||||
# Function to display the main menu
|
||||
main_menu() {
|
||||
while true; do
|
||||
CHOICE=$(dialog --clear --backtitle "Postfix Configuration" \
|
||||
--title "Postfix Menu" \
|
||||
--menu "Choose an option:" 15 60 9 \
|
||||
1 "Install/Check Postfix" \
|
||||
2 "Configure Postfix" \
|
||||
3 "Start Postfix" \
|
||||
4 "Stop Postfix" \
|
||||
5 "Restart Postfix" \
|
||||
6 "Enable Postfix at Boot" \
|
||||
7 "Disable Postfix at Boot" \
|
||||
8 "Secure Postfix Configuration" \
|
||||
9 "Exit" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case $CHOICE in
|
||||
1) install_postfix_if_needed ;;
|
||||
2) configure_postfix ;;
|
||||
3) start_postfix ;;
|
||||
4) stop_postfix ;;
|
||||
5) restart_postfix ;;
|
||||
6) enable_postfix_at_boot ;;
|
||||
7) disable_postfix_at_boot ;;
|
||||
8) secure_postfix ;;
|
||||
9) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Postfix configuration script completed."
|
||||
}
|
||||
|
||||
# Display main menu
|
||||
main_menu
|
||||
|
|
@ -1,80 +1,170 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check if PostgreSQL is installed
|
||||
check_postgresql() {
|
||||
if ! command -v psql &> /dev/null; then
|
||||
dialog --msgbox "PostgreSQL is not installed. Installing now..." 10 50
|
||||
sudo apt update
|
||||
sudo apt install -y postgresql postgresql-contrib
|
||||
dialog --msgbox "PostgreSQL has been installed successfully." 10 50
|
||||
else
|
||||
dialog --msgbox "PostgreSQL is already installed." 10 50
|
||||
# Function to install PostgreSQL if not installed
|
||||
install_postgresql_if_needed() {
|
||||
if ! dpkg -l postgresql > /dev/null 2>&1; then
|
||||
echo "PostgreSQL is not installed. Installing..."
|
||||
if sudo apt-get install -y postgresql; then
|
||||
echo "PostgreSQL installed successfully."
|
||||
else
|
||||
echo "Failed to install PostgreSQL. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start PostgreSQL service
|
||||
# Function to start PostgreSQL
|
||||
start_postgresql() {
|
||||
sudo systemctl start postgresql
|
||||
dialog --msgbox "PostgreSQL service started." 10 30
|
||||
dialog --msgbox "PostgreSQL started." 10 30
|
||||
}
|
||||
|
||||
# Function to stop PostgreSQL service
|
||||
# Function to stop PostgreSQL
|
||||
stop_postgresql() {
|
||||
sudo systemctl stop postgresql
|
||||
dialog --msgbox "PostgreSQL service stopped." 10 30
|
||||
dialog --msgbox "PostgreSQL stopped." 10 30
|
||||
}
|
||||
|
||||
# Function to restart PostgreSQL service
|
||||
# Function to restart PostgreSQL
|
||||
restart_postgresql() {
|
||||
sudo systemctl restart postgresql
|
||||
dialog --msgbox "PostgreSQL service restarted." 10 30
|
||||
dialog --msgbox "PostgreSQL restarted." 10 30
|
||||
}
|
||||
|
||||
# Function to enable PostgreSQL service
|
||||
enable_postgresql() {
|
||||
# Function to enable PostgreSQL at boot
|
||||
enable_postgresql_at_boot() {
|
||||
sudo systemctl enable postgresql
|
||||
dialog --msgbox "PostgreSQL service enabled." 10 30
|
||||
dialog --msgbox "PostgreSQL enabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to disable PostgreSQL service
|
||||
disable_postgresql() {
|
||||
# Function to disable PostgreSQL at boot
|
||||
disable_postgresql_at_boot() {
|
||||
sudo systemctl disable postgresql
|
||||
dialog --msgbox "PostgreSQL service disabled." 10 30
|
||||
dialog --msgbox "PostgreSQL disabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to secure PostgreSQL installation
|
||||
secure_postgresql() {
|
||||
sudo passwd postgres
|
||||
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_password';"
|
||||
dialog --msgbox "PostgreSQL installation secured." 10 30
|
||||
}
|
||||
|
||||
# Function to create a database
|
||||
create_database() {
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the database to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" ]]; then
|
||||
sudo -u postgres createdb $DATABASE
|
||||
dialog --msgbox "Database '$DATABASE' created successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# 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
|
||||
dialog --msgbox "File not found or invalid." 10 60
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure PostgreSQL
|
||||
configure_postgresql() {
|
||||
check_postgresql
|
||||
|
||||
while true; do
|
||||
local POSTGRESQL_CHOICE
|
||||
POSTGRESQL_CHOICE=$(dialog --clear --backtitle "PostgreSQL Configuration" \
|
||||
--title "PostgreSQL Menu" \
|
||||
--menu "Choose an option:" 20 60 10 \
|
||||
1 "Start PostgreSQL" \
|
||||
2 "Stop PostgreSQL" \
|
||||
3 "Restart PostgreSQL" \
|
||||
4 "Enable PostgreSQL at Boot" \
|
||||
5 "Disable PostgreSQL at Boot" \
|
||||
6 "Create PostgreSQL User" \
|
||||
7 "Back to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
CHOICE=$(dialog --clear --backtitle "Configure PostgreSQL" \
|
||||
--title "PostgreSQL Menu" \
|
||||
--menu "Choose an option:" 20 60 14 \
|
||||
1 "Install/Check PostgreSQL" \
|
||||
2 "Start PostgreSQL" \
|
||||
3 "Stop PostgreSQL" \
|
||||
4 "Restart PostgreSQL" \
|
||||
5 "Enable PostgreSQL at Boot" \
|
||||
6 "Disable PostgreSQL at Boot" \
|
||||
7 "Secure PostgreSQL Installation" \
|
||||
8 "Create Database" \
|
||||
9 "Create Table" \
|
||||
10 "Insert Data into Table" \
|
||||
11 "Query Data from Table" \
|
||||
12 "Backup Database" \
|
||||
13 "Restore Database" \
|
||||
14 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then break; fi
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case "$POSTGRESQL_CHOICE" in
|
||||
1) start_postgresql ;;
|
||||
2) stop_postgresql ;;
|
||||
3) restart_postgresql ;;
|
||||
4) enable_postgresql ;;
|
||||
5) disable_postgresql ;;
|
||||
6) create_postgresql_user ;;
|
||||
7) break ;;
|
||||
*) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;;
|
||||
case $CHOICE in
|
||||
1) install_postgresql_if_needed ;;
|
||||
2) start_postgresql ;;
|
||||
3) stop_postgresql ;;
|
||||
4) restart_postgresql ;;
|
||||
5) enable_postgresql_at_boot ;;
|
||||
6) disable_postgresql_at_boot ;;
|
||||
7) secure_postgresql ;;
|
||||
8) create_database ;;
|
||||
9) create_table ;;
|
||||
10) insert_data ;;
|
||||
11) query_data ;;
|
||||
12) backup_database ;;
|
||||
13) restore_database ;;
|
||||
14) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Execute the main function to configure PostgreSQL
|
||||
# Show main configuration menu
|
||||
configure_postgresql
|
||||
|
||||
|
|
|
@ -1,128 +1,169 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check if SQLite is installed
|
||||
check_sqlite() {
|
||||
if ! command -v sqlite3 &> /dev/null; then
|
||||
dialog --msgbox "SQLite is not installed. Installing now..." 10 50
|
||||
sudo apt update
|
||||
sudo apt install -y sqlite3
|
||||
dialog --msgbox "SQLite has been installed successfully." 10 50
|
||||
else
|
||||
dialog --msgbox "SQLite is already installed." 10 50
|
||||
# Function to install SQLite if not installed
|
||||
install_sqlite_if_needed() {
|
||||
if ! dpkg -l sqlite3 > /dev/null 2>&1; then
|
||||
echo "SQLite is not installed. Installing..."
|
||||
if sudo apt-get install -y sqlite3; then
|
||||
echo "SQLite installed successfully."
|
||||
else
|
||||
echo "Failed to install SQLite. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start SQLite
|
||||
start_sqlite() {
|
||||
sudo systemctl start sqlite3
|
||||
dialog --msgbox "SQLite started." 10 30
|
||||
}
|
||||
|
||||
# Function to stop SQLite
|
||||
stop_sqlite() {
|
||||
sudo systemctl stop sqlite3
|
||||
dialog --msgbox "SQLite stopped." 10 30
|
||||
}
|
||||
|
||||
# Function to restart SQLite
|
||||
restart_sqlite() {
|
||||
sudo systemctl restart sqlite3
|
||||
dialog --msgbox "SQLite restarted." 10 30
|
||||
}
|
||||
|
||||
# Function to enable SQLite at boot
|
||||
enable_sqlite_at_boot() {
|
||||
sudo systemctl enable sqlite3
|
||||
dialog --msgbox "SQLite enabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to disable SQLite at boot
|
||||
disable_sqlite_at_boot() {
|
||||
sudo systemctl disable sqlite3
|
||||
dialog --msgbox "SQLite disabled at boot." 10 30
|
||||
}
|
||||
|
||||
# Function to secure SQLite installation
|
||||
secure_sqlite() {
|
||||
echo "SQLite does not require additional security configuration."
|
||||
dialog --msgbox "SQLite installation secured." 10 30
|
||||
}
|
||||
|
||||
# Function to create a SQLite database
|
||||
create_sqlite_database() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to create (e.g., /path/to/db.sqlite):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
sqlite3 $DB_PATH "VACUUM;"
|
||||
dialog --msgbox "SQLite database $DB_PATH created successfully." 10 30
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite database to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" ]]; then
|
||||
touch $DATABASE.db
|
||||
dialog --msgbox "SQLite database '$DATABASE.db' created successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create a SQLite table
|
||||
# Function to create a table in SQLite
|
||||
create_sqlite_table() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to create table in):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
TABLE_NAME=$(dialog --inputbox "Enter the name of the table to create:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
COLUMNS=$(dialog --inputbox "Enter table columns (e.g., id INTEGER PRIMARY KEY, name TEXT):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
sqlite3 $DB_PATH "CREATE TABLE $TABLE_NAME ($COLUMNS);"
|
||||
dialog --msgbox "Table $TABLE_NAME created successfully in SQLite database $DB_PATH." 10 30
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite database:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
TABLE=$(dialog --inputbox "Enter the name of the table to create in SQLite:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
|
||||
sqlite3 $DATABASE.db "CREATE TABLE $TABLE (id INTEGER PRIMARY KEY);"
|
||||
dialog --msgbox "Table '$TABLE' created in SQLite database '$DATABASE.db' successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to insert data into a SQLite table
|
||||
insert_sqlite_data() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to insert data into table):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
TABLE_NAME=$(dialog --inputbox "Enter the name of the table to insert data into:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
COLUMNS=$(dialog --inputbox "Enter column names (e.g., name, age):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
VALUES=$(dialog --inputbox "Enter values to insert (e.g., 'John', 30):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
sqlite3 $DB_PATH "INSERT INTO $TABLE_NAME ($COLUMNS) VALUES ($VALUES);"
|
||||
dialog --msgbox "Data inserted successfully into table $TABLE_NAME of SQLite database $DB_PATH." 10 30
|
||||
# Function to insert data into SQLite table
|
||||
insert_data_into_sqlite() {
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite database:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
TABLE=$(dialog --inputbox "Enter the name of the SQLite table to insert data into:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
DATA=$(dialog --inputbox "Enter data to insert into SQLite table (e.g., 'value1, value2'):" 10 60 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; then
|
||||
sqlite3 $DATABASE.db "INSERT INTO $TABLE VALUES ($DATA);"
|
||||
dialog --msgbox "Data inserted into SQLite table '$TABLE' in database '$DATABASE.db' successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to query data from a SQLite table
|
||||
query_sqlite_data() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to query data from table):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
QUERY=$(dialog --inputbox "Enter SQL query (e.g., SELECT * FROM table_name):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
RESULT=$(sqlite3 -header -column $DB_PATH "$QUERY")
|
||||
dialog --msgbox "Query result:\n\n$RESULT" 20 70
|
||||
# Function to query data from SQLite table
|
||||
query_data_from_sqlite() {
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite database:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
TABLE=$(dialog --inputbox "Enter the name of the SQLite table to query from:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" && -n "$TABLE" ]]; then
|
||||
QUERY=$(dialog --inputbox "Enter SQLite query (e.g., 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$QUERY" ]]; then
|
||||
sqlite3 $DATABASE.db "$QUERY"
|
||||
dialog --msgbox "Query executed successfully." 10 60
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to back up a SQLite database
|
||||
# Function to backup SQLite database
|
||||
backup_sqlite_database() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to backup:" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
BACKUP_FILE=$(dialog --inputbox "Enter the path and name of the backup file (e.g., /home/user/backup.sql):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
sqlite3 $DB_PATH ".backup $BACKUP_FILE"
|
||||
dialog --msgbox "Backup of SQLite database $DB_PATH successfully saved to $BACKUP_FILE." 10 30
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite database to backup:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -n "$DATABASE" ]]; then
|
||||
cp $DATABASE.db $DATABASE.backup.db
|
||||
dialog --msgbox "SQLite database '$DATABASE.db' backed up to '$DATABASE.backup.db' successfully." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to restore a SQLite database from backup
|
||||
# Function to restore SQLite database
|
||||
restore_sqlite_database() {
|
||||
DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to restore to:" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
BACKUP_FILE=$(dialog --inputbox "Enter the path and name of the backup file (e.g., /home/user/backup.sql):" 10 50 3>&1 1>&2 2>&3 3>&-)
|
||||
if [ $? -eq 1 ]; then return; fi
|
||||
|
||||
sqlite3 $DB_PATH ".restore $BACKUP_FILE"
|
||||
dialog --msgbox "SQLite database $DB_PATH successfully restored from $BACKUP_FILE." 10 30
|
||||
DATABASE=$(dialog --inputbox "Enter the name of the SQLite 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 SQLite backup file to restore:" 10 60 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -f "$FILE" ]]; then
|
||||
cp $FILE $DATABASE.db
|
||||
dialog --msgbox "SQLite database '$DATABASE.db' restored successfully." 10 60
|
||||
else
|
||||
dialog --msgbox "File not found or invalid." 10 60
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function to configure SQLite
|
||||
# Function to configure SQLite
|
||||
configure_sqlite() {
|
||||
check_sqlite
|
||||
|
||||
while true; do
|
||||
local SQLITE_CHOICE
|
||||
SQLITE_CHOICE=$(dialog --clear --backtitle "SQLite Configuration" \
|
||||
--title "SQLite Menu" \
|
||||
--menu "Choose an option:" 20 60 10 \
|
||||
1 "Create Database" \
|
||||
2 "Create Table" \
|
||||
3 "Insert Data into Table" \
|
||||
4 "Query Data from Table" \
|
||||
5 "Backup Database" \
|
||||
6 "Restore Database" \
|
||||
7 "Back to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
CHOICE=$(dialog --clear --backtitle "Configure SQLite" \
|
||||
--title "SQLite Menu" \
|
||||
--menu "Choose an option:" 20 60 13 \
|
||||
1 "Install/Check SQLite" \
|
||||
2 "Start SQLite" \
|
||||
3 "Stop SQLite" \
|
||||
4 "Restart SQLite" \
|
||||
5 "Enable SQLite at Boot" \
|
||||
6 "Disable SQLite at Boot" \
|
||||
7 "Secure SQLite Installation" \
|
||||
8 "Create SQLite Database" \
|
||||
9 "Create Table in SQLite" \
|
||||
10 "Insert Data into SQLite Table" \
|
||||
11 "Query Data from SQLite Table" \
|
||||
12 "Backup SQLite Database" \
|
||||
13 "Restore SQLite Database" \
|
||||
14 "Return to Main Menu" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
clear
|
||||
|
||||
# Check if user canceled
|
||||
if [ $? -eq 1 ]; then break; fi
|
||||
if [ $? -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
case "$SQLITE_CHOICE" in
|
||||
1) create_sqlite_database ;;
|
||||
2) create_sqlite_table ;;
|
||||
3) insert_sqlite_data ;;
|
||||
4) query_sqlite_data ;;
|
||||
5) backup_sqlite_database ;;
|
||||
6) restore_sqlite_database ;;
|
||||
7) break ;;
|
||||
*) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;;
|
||||
case $CHOICE in
|
||||
1) install_sqlite_if_needed ;;
|
||||
2) start_sqlite ;;
|
||||
3) stop_sqlite ;;
|
||||
4) restart_sqlite ;;
|
||||
5) enable_sqlite_at_boot ;;
|
||||
6) disable_sqlite_at_boot ;;
|
||||
7) secure_sqlite ;;
|
||||
8) create_sqlite_database ;;
|
||||
9) create_sqlite_table ;;
|
||||
10) insert_data_into_sqlite ;;
|
||||
11) query_data_from_sqlite ;;
|
||||
12) backup_sqlite_database ;;
|
||||
13) restore_sqlite_database ;;
|
||||
14) break ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Execute the main function to configure SQLite
|
||||
# Show main configuration menu
|
||||
configure_sqlite
|
||||
|
||||
|
|
|
@ -2,11 +2,74 @@
|
|||
|
||||
# Function to create users
|
||||
create_user() {
|
||||
local USERNAME
|
||||
local FULLNAME
|
||||
local PASSWORD
|
||||
local GROUPS
|
||||
local SELECTED_GROUPS
|
||||
|
||||
# Prompt for username
|
||||
USERNAME=$(dialog --inputbox "Enter the username of the new user:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
useradd -m $USERNAME
|
||||
passwd $USERNAME
|
||||
dialog --msgbox "User $USERNAME created successfully." 10 30
|
||||
if [[ -z "$USERNAME" ]]; then
|
||||
dialog --msgbox "Username cannot be empty. User creation canceled." 10 30
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if username already exists
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
dialog --msgbox "User $USERNAME already exists. User creation canceled." 10 30
|
||||
return
|
||||
fi
|
||||
|
||||
# Prompt for full name
|
||||
FULLNAME=$(dialog --inputbox "Enter the full name of the new user:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -z "$FULLNAME" ]]; then
|
||||
dialog --msgbox "Full name cannot be empty. User creation canceled." 10 30
|
||||
return
|
||||
fi
|
||||
|
||||
# Prompt for password
|
||||
PASSWORD=$(dialog --passwordbox "Enter the password for user $USERNAME:" 10 40 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -z "$PASSWORD" ]]; then
|
||||
dialog --msgbox "Password cannot be empty. User creation canceled." 10 30
|
||||
return
|
||||
fi
|
||||
|
||||
# Get list of available groups
|
||||
GROUPS=$(getent group | cut -d: -f1)
|
||||
GROUPS_ARR=()
|
||||
for group in $GROUPS; do
|
||||
GROUPS_ARR+=("$group" "" off)
|
||||
done
|
||||
|
||||
# Select groups to add user
|
||||
SELECTED_GROUPS=$(dialog --checklist "Select groups to add user $USERNAME:" 20 60 10 "${GROUPS_ARR[@]}" 3>&1 1>&2 2>&3 3>&-)
|
||||
if [[ -z "$SELECTED_GROUPS" ]]; then
|
||||
dialog --msgbox "No groups selected. User $USERNAME will not be added to any groups." 10 30
|
||||
fi
|
||||
|
||||
# Create the user
|
||||
useradd -m -c "$FULLNAME" "$USERNAME"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||
if [[ $? -eq 0 ]]; then
|
||||
dialog --msgbox "User $USERNAME created successfully." 10 30
|
||||
# Add user to selected groups
|
||||
for group in $SELECTED_GROUPS; do
|
||||
usermod -aG "$group" "$USERNAME"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
dialog --msgbox "Failed to add user $USERNAME to group $group." 10 30
|
||||
fi
|
||||
done
|
||||
else
|
||||
dialog --msgbox "Failed to set password for user $USERNAME. User creation canceled." 10 30
|
||||
userdel -r "$USERNAME" # Rollback user creation if password setting failed
|
||||
fi
|
||||
else
|
||||
dialog --msgbox "Failed to create user $USERNAME. User creation canceled." 10 30
|
||||
fi
|
||||
}
|
||||
|
||||
# Call the function to create users
|
||||
create_user
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ main_menu() {
|
|||
while true; do
|
||||
CHOICE=$(dialog --clear --backtitle "PeppermintOS Server Configuration" \
|
||||
--title "Main Menu" \
|
||||
--menu "Choose an option:" 20 60 12 \
|
||||
--menu "Choose an option:" 20 60 15 \
|
||||
1 "Configure SSH" \
|
||||
2 "Configure Static IP" \
|
||||
3 "Update and Install Packages" \
|
||||
|
@ -14,10 +14,12 @@ main_menu() {
|
|||
6 "Create User" \
|
||||
7 "Configure Nginx" \
|
||||
8 "Configure Apache2" \
|
||||
9 "Configure MariaDB" \
|
||||
10 "Configure PostgreSQL" \
|
||||
11 "Configure SQLite" \
|
||||
12 "Exit" \
|
||||
9 "Configure Postfix" \
|
||||
10 "Configure MariaDB" \
|
||||
11 "Configure PostgreSQL" \
|
||||
12 "Configure SQLite" \
|
||||
13 "Configure PHP and Docker" \
|
||||
14 "Exit" \
|
||||
3>&1 1>&2 2>&3 3>&-)
|
||||
|
||||
# Check if user canceled or exited
|
||||
|
@ -38,10 +40,12 @@ main_menu() {
|
|||
6) sudo ./create_user.sh ;;
|
||||
7) sudo ./configure_nginx.sh ;;
|
||||
8) sudo ./configure_apache2.sh ;;
|
||||
9) sudo ./configure_mariadb.sh ;;
|
||||
10) sudo ./configure_postgresql.sh ;;
|
||||
11) sudo ./configure_sqlite.sh ;;
|
||||
12) clear; echo "Exiting..."; exit 0 ;;
|
||||
9) sudo ./configure_postfix.sh ;;
|
||||
10) sudo ./configure_mariadb.sh ;;
|
||||
11) sudo ./configure_postgresql.sh ;;
|
||||
12) sudo ./configure_sqlite.sh ;;
|
||||
13) sudo ./configure_php_and_docker.sh ;;
|
||||
14) clear; echo "Exiting..."; exit 0 ;;
|
||||
*) dialog --msgbox "Invalid option." 10 30 ;;
|
||||
esac
|
||||
done
|
||||
|
@ -59,9 +63,13 @@ This tool will help you configure various aspects of your server, including:
|
|||
6. Create User: Add new users to your system.
|
||||
7. Nginx: Configure the Nginx web server.
|
||||
8. Apache2: Configure the Apache2 web server.
|
||||
9. MariaDB: Set up the MariaDB database server.
|
||||
10. PostgreSQL: Set up the PostgreSQL database server.
|
||||
11. SQLite: Configure the SQLite database.
|
||||
9. Postfix: Configure the Postfix mail server.
|
||||
10. MariaDB: Set up the MariaDB database server.
|
||||
11. PostgreSQL: Set up the PostgreSQL database server.
|
||||
12. SQLite: Configure the SQLite database.
|
||||
13. PHP: Configure PHP and related settings.
|
||||
14. Docker: Configure Docker and manage containers.
|
||||
15. Exit: Exit the configuration tool.
|
||||
|
||||
Please select an option from the menu to begin." 20 60
|
||||
|
||||
|
|
Loading…
Reference in New Issue