diff --git a/iso_configs/hooks/normal/debsrv_64/1000-setup-welcome-service.chroot b/iso_configs/hooks/normal/debsrv_64/1000-setup-welcome-service.chroot new file mode 100755 index 00000000..827b9c56 --- /dev/null +++ b/iso_configs/hooks/normal/debsrv_64/1000-setup-welcome-service.chroot @@ -0,0 +1,21 @@ +#!/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 diff --git a/iso_configs/hooks/normal/devsrv_64/1000-setup-welcome.chroot b/iso_configs/hooks/normal/devsrv_64/1000-setup-welcome.chroot new file mode 100755 index 00000000..46ec99d0 --- /dev/null +++ b/iso_configs/hooks/normal/devsrv_64/1000-setup-welcome.chroot @@ -0,0 +1,102 @@ +#!/bin/bash + +# Detect the init system +if command -v openrc-init > /dev/null 2>&1; then + INIT_SYSTEM="openrc" +elif command -v runit > /dev/null 2>&1; then + INIT_SYSTEM="runit" +elif [ -d /etc/init.d ] && [ -f /etc/init.d/rc ]; then + INIT_SYSTEM="sysvinit" +else + echo "Unsupported init system." + exit 1 +fi + +# Create the welcome script +cat << 'EOF' > /usr/local/bin/welcome.sh +#!/bin/bash +echo "Welcome to your live system!" +EOF + +# Make the welcome script executable +chmod +x /usr/local/bin/welcome.sh + +case "$INIT_SYSTEM" in + openrc) + # Create OpenRC init script for welcome.sh + cat << 'EOF' > /etc/init.d/welcome +#!/sbin/openrc-run + +command="/usr/local/bin/welcome.sh" +command_background=false +description="Welcome Script" + +depend() { + after net +} +EOF + # Set permissions + chmod +x /etc/init.d/welcome + + # Enable the service to start on boot + rc-update add welcome default + ;; + + sysvinit) + # Create SysVinit init script for welcome.sh + cat << 'EOF' > /etc/init.d/welcome +#!/bin/sh +### BEGIN INIT INFO +# Provides: welcome +# Required-Start: $network +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Welcome Script +### END INIT INFO + +case "\$1" in + start) + echo "Starting welcome script" + /usr/local/bin/welcome.sh & + ;; + stop) + echo "Stopping welcome script" + # No stop action needed for this script + ;; + *) + echo "Usage: /etc/init.d/welcome {start|stop}" + exit 1 + ;; +esac + +exit 0 +EOF + # Set permissions + chmod +x /etc/init.d/welcome + + # Enable the service to start on boot + update-rc.d welcome defaults + ;; + + runit) + # Create runit service directory for welcome.sh + mkdir -p /etc/sv/welcome + + # Create the run script for the service + cat << 'EOF' > /etc/sv/welcome/run +#!/bin/sh +exec /usr/local/bin/welcome.sh +EOF + # Set permissions + chmod +x /etc/sv/welcome/run + + # Create the service link + ln -s /etc/sv/welcome /etc/runit/runsvdir/default/ + ;; + + *) + echo "Unsupported init system." + exit 1 + ;; +esac diff --git a/iso_configs/server/scripts/configure_apache2.sh b/iso_configs/server/scripts/debian/configure_apache2.sh similarity index 100% rename from iso_configs/server/scripts/configure_apache2.sh rename to iso_configs/server/scripts/debian/configure_apache2.sh diff --git a/iso_configs/server/scripts/configure_firewalld.sh b/iso_configs/server/scripts/debian/configure_firewalld.sh similarity index 100% rename from iso_configs/server/scripts/configure_firewalld.sh rename to iso_configs/server/scripts/debian/configure_firewalld.sh diff --git a/iso_configs/server/scripts/configure_hostname.sh b/iso_configs/server/scripts/debian/configure_hostname.sh similarity index 100% rename from iso_configs/server/scripts/configure_hostname.sh rename to iso_configs/server/scripts/debian/configure_hostname.sh diff --git a/iso_configs/server/scripts/configure_mariadb.sh b/iso_configs/server/scripts/debian/configure_mariadb.sh similarity index 100% rename from iso_configs/server/scripts/configure_mariadb.sh rename to iso_configs/server/scripts/debian/configure_mariadb.sh diff --git a/iso_configs/server/scripts/configure_nginx.sh b/iso_configs/server/scripts/debian/configure_nginx.sh similarity index 100% rename from iso_configs/server/scripts/configure_nginx.sh rename to iso_configs/server/scripts/debian/configure_nginx.sh diff --git a/iso_configs/server/scripts/configure_php_and_docker.sh b/iso_configs/server/scripts/debian/configure_php_and_docker.sh similarity index 100% rename from iso_configs/server/scripts/configure_php_and_docker.sh rename to iso_configs/server/scripts/debian/configure_php_and_docker.sh diff --git a/iso_configs/server/scripts/configure_postfix.sh b/iso_configs/server/scripts/debian/configure_postfix.sh similarity index 100% rename from iso_configs/server/scripts/configure_postfix.sh rename to iso_configs/server/scripts/debian/configure_postfix.sh diff --git a/iso_configs/server/scripts/configure_postgresql.sh b/iso_configs/server/scripts/debian/configure_postgresql.sh similarity index 100% rename from iso_configs/server/scripts/configure_postgresql.sh rename to iso_configs/server/scripts/debian/configure_postgresql.sh diff --git a/iso_configs/server/scripts/debian/configure_sqlite.sh b/iso_configs/server/scripts/debian/configure_sqlite.sh new file mode 100755 index 00000000..64f3de7d --- /dev/null +++ b/iso_configs/server/scripts/debian/configure_sqlite.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +# 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 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() { + 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 table in SQLite +create_sqlite_table() { + 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 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 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 backup SQLite database +backup_sqlite_database() { + 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 SQLite database +restore_sqlite_database() { + 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 +} + +# Function to configure SQLite +configure_sqlite() { + while true; do + CHOICE=$(dialog --clear --backtitle "Configure SQLite" \ + --title "SQLite Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Install/Check SQLite" \ + 2 "Secure SQLite Installation" \ + 3 "Create SQLite Database" \ + 4 "Create Table in SQLite" \ + 5 "Insert Data into SQLite Table" \ + 6 "Query Data from SQLite Table" \ + 7 "Backup SQLite Database" \ + 8 "Restore SQLite Database" \ + 9 "Return to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + clear + + # Check if user canceled + if [ $? -eq 1 ]; then + break + fi + + case $CHOICE in + 1) install_sqlite_if_needed ;; + 2) secure_sqlite ;; + 3) create_sqlite_database ;; + 4) create_sqlite_table ;; + 5) insert_data_into_sqlite ;; + 6) query_data_from_sqlite ;; + 7) backup_sqlite_database ;; + 8) restore_sqlite_database ;; + 9) break ;; + *) dialog --msgbox "Invalid option." 10 30 ;; + esac + done +} + +# Show main configuration menu +configure_sqlite + diff --git a/iso_configs/server/scripts/configure_ssh.sh b/iso_configs/server/scripts/debian/configure_ssh.sh similarity index 100% rename from iso_configs/server/scripts/configure_ssh.sh rename to iso_configs/server/scripts/debian/configure_ssh.sh diff --git a/iso_configs/server/scripts/configure_static_ip.sh b/iso_configs/server/scripts/debian/configure_static_ip.sh similarity index 100% rename from iso_configs/server/scripts/configure_static_ip.sh rename to iso_configs/server/scripts/debian/configure_static_ip.sh diff --git a/iso_configs/server/scripts/create_user.sh b/iso_configs/server/scripts/debian/create_user.sh similarity index 100% rename from iso_configs/server/scripts/create_user.sh rename to iso_configs/server/scripts/debian/create_user.sh diff --git a/iso_configs/server/scripts/update_and_install.sh b/iso_configs/server/scripts/debian/update_and_install.sh similarity index 100% rename from iso_configs/server/scripts/update_and_install.sh rename to iso_configs/server/scripts/debian/update_and_install.sh diff --git a/iso_configs/server/scripts/welcome.sh b/iso_configs/server/scripts/debian/welcome.sh similarity index 100% rename from iso_configs/server/scripts/welcome.sh rename to iso_configs/server/scripts/debian/welcome.sh diff --git a/iso_configs/server/scripts/devuan/configure_apache2.sh b/iso_configs/server/scripts/devuan/configure_apache2.sh new file mode 100755 index 00000000..7d725522 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_apache2.sh @@ -0,0 +1,224 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to install Apache if not installed +install_apache_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + if ! apk info -q apache2 > /dev/null 2>&1; then + echo "Apache is not installed. Installing..." + if sudo apk add apache2; then + echo "Apache installed successfully." + else + echo "Failed to install Apache. Exiting." + exit 1 + fi + fi + ;; + runit) + echo "Runit does not require Apache installation." + ;; + esac +} + +# Function to start Apache +start_apache() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service apache2 start + ;; + openrc) + sudo rc-service apache2 start + ;; + runit) + echo "Use 'sv start apache2' to start Apache with runit." + ;; + esac + dialog --msgbox "Apache started." 10 30 +} + +# Function to stop Apache +stop_apache() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service apache2 stop + ;; + openrc) + sudo rc-service apache2 stop + ;; + runit) + echo "Use 'sv stop apache2' to stop Apache with runit." + ;; + esac + dialog --msgbox "Apache stopped." 10 30 +} + +# Function to restart Apache +restart_apache() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service apache2 restart + ;; + openrc) + sudo rc-service apache2 restart + ;; + runit) + echo "Use 'sv restart apache2' to restart Apache with runit." + ;; + esac + dialog --msgbox "Apache restarted." 10 30 +} + +# Function to enable Apache at boot +enable_apache_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo update-rc.d apache2 enable + ;; + openrc) + sudo rc-update add apache2 default + ;; + runit) + echo "Runit does not require enabling services at boot." + ;; + esac + dialog --msgbox "Apache enabled at boot." 10 30 +} + +# Function to disable Apache at boot +disable_apache_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo update-rc.d apache2 disable + ;; + openrc) + sudo rc-update del apache2 default + ;; + runit) + echo "Runit does not require disabling services at boot." + ;; + esac + dialog --msgbox "Apache disabled at boot." 10 30 +} + +# 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 + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + + ServerAdmin webmaster@$DOMAIN + ServerName $DOMAIN + DocumentRoot /var/www/$DOMAIN/public_html + ErrorLog \${APACHE_LOG_DIR}/error.log + CustomLog \${APACHE_LOG_DIR}/access.log combined + +EOF + sudo a2ensite $DOMAIN.conf + sudo service apache2 reload + ;; + openrc) + sudo mkdir -p /var/www/$DOMAIN/public_html + sudo chown -R apache:apache /var/www/$DOMAIN/public_html + sudo chmod -R 755 /var/www/$DOMAIN + cat << EOF | sudo tee /etc/apache2/sites-available/$DOMAIN.conf > /dev/null + + ServerAdmin webmaster@$DOMAIN + ServerName $DOMAIN + DocumentRoot /var/www/$DOMAIN/public_html + ErrorLog /var/log/apache2/$DOMAIN_error.log + CustomLog /var/log/apache2/$DOMAIN_access.log combined + +EOF + sudo a2ensite $DOMAIN.conf + sudo service apache2 reload + ;; + runit) + echo "Runit does not use Apache virtual hosts in the same way." + ;; + esac + dialog --msgbox "Virtual host for $DOMAIN configured successfully." 10 60 + fi +} + +# Function to configure Apache +configure_apache() { + while true; do + 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 + + 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 +} + +# Main script logic +detect_init_system +configure_apache + + diff --git a/iso_configs/server/scripts/devuan/configure_firewalld.sh b/iso_configs/server/scripts/devuan/configure_firewalld.sh new file mode 100755 index 00000000..c5871832 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_firewalld.sh @@ -0,0 +1,219 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to enable firewalld +enable_firewalld() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service firewalld start + sudo chkconfig firewalld on + ;; + openrc) + sudo rc-service firewalld start + sudo rc-update add firewalld default + ;; + runit) + echo "Runit does not use firewalld." + ;; + esac + dialog --msgbox "firewalld enabled and started." 10 30 +} + +# Function to disable firewalld +disable_firewalld() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service firewalld stop + sudo chkconfig firewalld off + ;; + openrc) + sudo rc-service firewalld stop + sudo rc-update del firewalld default + ;; + runit) + echo "Runit does not use firewalld." + ;; + esac + dialog --msgbox "firewalld disabled and stopped." 10 30 +} + +# Function to add service to firewalld +add_service() { + SERVICE=$(dialog --inputbox "Enter the service name to add (e.g., ssh, http, https):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$SERVICE" ]; then + dialog --msgbox "Please enter a valid service name." 10 30 + else + case $INIT_SYSTEM in + systemd | sysvinit) + firewall-cmd --permanent --add-service=$SERVICE + firewall-cmd --reload + ;; + openrc | runit) + echo "Firewalld is not used with OpenRC or Runit." + ;; + esac + dialog --msgbox "Service $SERVICE added to firewalld." 10 30 + fi +} + +# Function to remove service from firewalld +remove_service() { + SERVICE=$(dialog --inputbox "Enter the service name to remove:" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$SERVICE" ]; then + dialog --msgbox "Please enter a valid service name." 10 30 + else + case $INIT_SYSTEM in + systemd | sysvinit) + firewall-cmd --permanent --remove-service=$SERVICE + firewall-cmd --reload + ;; + openrc | runit) + echo "Firewalld is not used with OpenRC or Runit." + ;; + esac + dialog --msgbox "Service $SERVICE removed from firewalld." 10 30 + fi +} + +# Function to add port to firewalld +add_port() { + PORT=$(dialog --inputbox "Enter the port to add (e.g., 8080/tcp):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$PORT" ]; then + dialog --msgbox "Please enter a valid port." 10 30 + else + case $INIT_SYSTEM in + systemd | sysvinit) + firewall-cmd --permanent --add-port=$PORT + firewall-cmd --reload + ;; + openrc | runit) + echo "Firewalld is not used with OpenRC or Runit." + ;; + esac + dialog --msgbox "Port $PORT added to firewalld." 10 30 + fi +} + +# Function to remove port from firewalld +remove_port() { + PORT=$(dialog --inputbox "Enter the port to remove (e.g., 8080/tcp):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$PORT" ]; then + dialog --msgbox "Please enter a valid port." 10 30 + else + case $INIT_SYSTEM in + systemd | sysvinit) + firewall-cmd --permanent --remove-port=$PORT + firewall-cmd --reload + ;; + openrc | runit) + echo "Firewalld is not used with OpenRC or Runit." + ;; + esac + dialog --msgbox "Port $PORT removed from firewalld." 10 30 + fi +} + +# Function to configure zones in firewalld +configure_zones() { + ZONE=$(dialog --inputbox "Enter the zone name (e.g., public, home, work):" 10 50 3>&1 1>&2 2>&3 3>&-) + INTERFACE=$(dialog --inputbox "Enter the interface name (e.g., eth0, wlan0):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$ZONE" ] || [ -z "$INTERFACE" ]; then + dialog --msgbox "Please enter valid zone and interface names." 10 30 + else + case $INIT_SYSTEM in + systemd | sysvinit) + firewall-cmd --zone=$ZONE --add-interface=$INTERFACE --permanent + firewall-cmd --reload + ;; + openrc | runit) + echo "Firewalld is not used with OpenRC or Runit." + ;; + esac + dialog --msgbox "Interface $INTERFACE added to zone $ZONE." 10 30 + fi +} + +# Function to configure firewalld options +configure_firewalld() { + while true; do + FIREWALL_CHOICE=$(dialog --clear --backtitle "Firewalld Configuration" \ + --title "Firewalld Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Enable firewalld" \ + 2 "Disable firewalld" \ + 3 "Add Service" \ + 4 "Remove Service" \ + 5 "Add Port" \ + 6 "Remove Port" \ + 7 "Configure Zones" \ + 8 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + break + fi + + case $FIREWALL_CHOICE in + 1) enable_firewalld ;; + 2) disable_firewalld ;; + 3) add_service ;; + 4) remove_service ;; + 5) add_port ;; + 6) remove_port ;; + 7) configure_zones ;; + 8) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Main script logic +detect_init_system +configure_firewalld + diff --git a/iso_configs/server/scripts/devuan/configure_hostname.sh b/iso_configs/server/scripts/devuan/configure_hostname.sh new file mode 100755 index 00000000..f95ec262 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_hostname.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# Function to set hostname +set_hostname() { + NEW_HOSTNAME=$(dialog --inputbox "Enter the new hostname:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$NEW_HOSTNAME" ]; then + dialog --msgbox "Hostname cannot be empty. Please enter a valid hostname." 10 60 + else + hostnamectl set-hostname "$NEW_HOSTNAME" + dialog --msgbox "Hostname set to $NEW_HOSTNAME." 10 60 + fi +} + +# Function to display current hostname +show_hostname() { + CURRENT_HOSTNAME=$(hostnamectl --static) + dialog --msgbox "Current hostname is: $CURRENT_HOSTNAME" 10 60 +} + +# Function to display network interfaces +show_network_interfaces() { + dialog --msgbox "$(ip -o link show | awk '{print $2,$9}')" 20 60 +} + +# Function to display IP addresses +show_ip_addresses() { + dialog --msgbox "$(ip -4 addr show | grep inet)" 30 80 +} + +# Function to configure DNS settings +configure_dns() { + while true; do + DNS_CHOICE=$(dialog --clear --backtitle "DNS Configuration" \ + --title "DNS Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Set DNS Servers" \ + 2 "Show DNS Configuration" \ + 3 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $DNS_CHOICE in + 1) set_dns_servers ;; + 2) show_dns_configuration ;; + 3) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to set DNS servers +set_dns_servers() { + DNS_SERVERS=$(dialog --inputbox "Enter DNS servers separated by comma (e.g., 8.8.8.8,8.8.4.4):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$DNS_SERVERS" ]; then + dialog --msgbox "DNS servers cannot be empty. Please enter valid DNS servers." 10 60 + else + echo "nameserver $DNS_SERVERS" | sudo tee /etc/resolv.conf >/dev/null + dialog --msgbox "DNS servers set to: $DNS_SERVERS" 10 60 + fi +} + +# Function to show current DNS configuration +show_dns_configuration() { + CURRENT_DNS=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | tr '\n' ' ') + dialog --msgbox "Current DNS configuration:\n$CURRENT_DNS" 10 60 +} + +# Function to configure host options +configure_host() { + while true; do + HOST_CHOICE=$(dialog --clear --backtitle "Host Configuration" \ + --title "Host Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Set Hostname" \ + 2 "Show Hostname" \ + 3 "Show Network Interfaces" \ + 4 "Show IP Addresses" \ + 5 "DNS Configuration" \ + 6 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $HOST_CHOICE in + 1) set_hostname ;; + 2) show_hostname ;; + 3) show_network_interfaces ;; + 4) show_ip_addresses ;; + 5) configure_dns ;; + 6) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Execute the main function to configure host settings +configure_host diff --git a/iso_configs/server/scripts/devuan/configure_mariadb.sh b/iso_configs/server/scripts/devuan/configure_mariadb.sh new file mode 100755 index 00000000..1cbcd029 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_mariadb.sh @@ -0,0 +1,243 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to install MariaDB if not installed +install_mariadb_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc | runit) + echo "MariaDB installation is managed differently in OpenRC or Runit." + ;; + esac +} + +# Function to start MariaDB +start_mariadb() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service mariadb start + ;; + openrc) + sudo rc-service mariadb start + ;; + runit) + echo "Runit does not manage MariaDB." + ;; + esac + dialog --msgbox "MariaDB started." 10 30 +} + +# Function to stop MariaDB +stop_mariadb() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service mariadb stop + ;; + openrc) + sudo rc-service mariadb stop + ;; + runit) + echo "Runit does not manage MariaDB." + ;; + esac + dialog --msgbox "MariaDB stopped." 10 30 +} + +# Function to restart MariaDB +restart_mariadb() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service mariadb restart + ;; + openrc) + sudo rc-service mariadb restart + ;; + runit) + echo "Runit does not manage MariaDB." + ;; + esac + dialog --msgbox "MariaDB restarted." 10 30 +} + +# Function to enable MariaDB at boot +enable_mariadb_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo systemctl enable mariadb + ;; + openrc) + sudo rc-update add mariadb default + ;; + runit) + echo "Runit does not manage MariaDB." + ;; + esac + dialog --msgbox "MariaDB enabled at boot." 10 30 +} + +# Function to disable MariaDB at boot +disable_mariadb_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo systemctl disable mariadb + ;; + openrc) + sudo rc-update del mariadb default + ;; + runit) + echo "Runit does not manage MariaDB." + ;; + esac + 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 options +configure_mariadb() { + while true; do + CHOICE=$(dialog --clear --backtitle "Configure MariaDB" \ + --title "MariaDB Menu" \ + --menu "Choose an option:" 20 60 14 \ + 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 + + 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 +} + +# Main script logic +detect_init_system +configure_mariadb + diff --git a/iso_configs/server/scripts/devuan/configure_nginx.sh b/iso_configs/server/scripts/devuan/configure_nginx.sh new file mode 100755 index 00000000..2fe13fd8 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_nginx.sh @@ -0,0 +1,283 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to install Nginx if not installed +install_nginx_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc | runit) + echo "Nginx installation is managed differently in OpenRC or Runit." + ;; + esac +} + +# Function to install Certbot if not installed +install_certbot_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc | runit) + echo "Certbot installation is managed differently in OpenRC or Runit." + ;; + esac +} + +# Function to start Nginx +start_nginx() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service nginx start + ;; + openrc) + sudo rc-service nginx start + ;; + runit) + echo "Runit does not manage Nginx." + ;; + esac + dialog --msgbox "Nginx started." 10 30 +} + +# Function to stop Nginx +stop_nginx() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service nginx stop + ;; + openrc) + sudo rc-service nginx stop + ;; + runit) + echo "Runit does not manage Nginx." + ;; + esac + dialog --msgbox "Nginx stopped." 10 30 +} + +# Function to restart Nginx +restart_nginx() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo service nginx restart + ;; + openrc) + sudo rc-service nginx restart + ;; + runit) + echo "Runit does not manage Nginx." + ;; + esac + dialog --msgbox "Nginx restarted." 10 30 +} + +# Function to enable Nginx at boot +enable_nginx_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo systemctl enable nginx + ;; + openrc) + sudo rc-update add nginx default + ;; + runit) + echo "Runit does not manage Nginx." + ;; + esac + dialog --msgbox "Nginx enabled at boot." 10 30 +} + +# Function to disable Nginx at boot +disable_nginx_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + sudo systemctl disable nginx + ;; + openrc) + sudo rc-update del nginx default + ;; + runit) + echo "Runit does not manage Nginx." + ;; + esac + dialog --msgbox "Nginx disabled at boot." 10 30 +} + +# Function to secure Nginx installation +secure_nginx() { + echo "Nginx does not require additional security configuration." + dialog --msgbox "Nginx installation secured." 10 30 +} + +# 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; + listen [::]:80; + + server_name $DOMAIN; + + root /var/www/$DOMAIN/html; + index index.html; + + location / { + try_files \$uri \$uri/ =404; + } +} +EOF + 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 +} + +# 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 + 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 + + 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 +} + +# Main script logic +detect_init_system +configure_nginx + diff --git a/iso_configs/server/scripts/devuan/configure_php_and_docker.sh b/iso_configs/server/scripts/devuan/configure_php_and_docker.sh new file mode 100755 index 00000000..b78438c0 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_php_and_docker.sh @@ -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 + diff --git a/iso_configs/server/scripts/devuan/configure_postfix.sh b/iso_configs/server/scripts/devuan/configure_postfix.sh new file mode 100755 index 00000000..6a18210a --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_postfix.sh @@ -0,0 +1,225 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to install Postfix if not installed +install_postfix_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit | openrc | runit) + 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 + ;; + *) + echo "Unsupported init system. Cannot install Postfix." + ;; + esac +} + +# Function to configure Postfix interactively +configure_postfix() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc | runit) + echo "Postfix configuration is managed differently in OpenRC or Runit." + ;; + esac +} + +# Function to start Postfix service +start_postfix() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + sudo rc-service postfix start + dialog --title "Success" --msgbox "Postfix service started successfully." 10 60 + ;; + runit) + echo "Runit does not manage Postfix." + ;; + esac +} + +# Function to stop Postfix service +stop_postfix() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + sudo rc-service postfix stop + dialog --title "Success" --msgbox "Postfix service stopped successfully." 10 60 + ;; + runit) + echo "Runit does not manage Postfix." + ;; + esac +} + +# Function to restart Postfix service +restart_postfix() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + sudo rc-service postfix restart + dialog --title "Success" --msgbox "Postfix service restarted successfully." 10 60 + ;; + runit) + echo "Runit does not manage Postfix." + ;; + esac +} + +# Function to enable Postfix service at boot +enable_postfix_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + sudo rc-update add postfix default + dialog --title "Success" --msgbox "Postfix service enabled at boot successfully." 10 60 + ;; + runit) + echo "Runit does not manage Postfix." + ;; + esac +} + +# Function to disable Postfix service at boot +disable_postfix_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + 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 + ;; + openrc) + sudo rc-update del postfix default + dialog --title "Success" --msgbox "Postfix service disabled at boot successfully." 10 60 + ;; + runit) + echo "Runit does not manage Postfix." + ;; + esac +} + +# 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." +} + +# Main script logic +detect_init_system +main_menu + diff --git a/iso_configs/server/scripts/devuan/configure_postgresql.sh b/iso_configs/server/scripts/devuan/configure_postgresql.sh new file mode 100755 index 00000000..50e24eae --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_postgresql.sh @@ -0,0 +1,255 @@ +#!/bin/bash + +# Detect init system +detect_init_system() { + if [[ -x "$(command -v systemctl)" ]]; then + INIT_SYSTEM="systemd" + elif [[ -x "$(command -v service)" ]]; then + INIT_SYSTEM="sysvinit" + elif [[ -x "$(command -v rc-service)" ]]; then + INIT_SYSTEM="openrc" + elif [[ -x "$(command -v runsvdir)" ]]; then + INIT_SYSTEM="runit" + else + echo "Unsupported init system. Exiting." + exit 1 + fi +} + +# Function to install PostgreSQL if not installed +install_postgresql_if_needed() { + case $INIT_SYSTEM in + systemd | sysvinit | openrc | runit) + 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 + ;; + *) + echo "Unsupported init system. Cannot install PostgreSQL." + ;; + esac +} + +# Function to start PostgreSQL +start_postgresql() { + case $INIT_SYSTEM in + systemd | sysvinit) + echo "Starting PostgreSQL..." + sudo systemctl start postgresql + dialog --msgbox "PostgreSQL started." 10 30 + ;; + openrc) + sudo rc-service postgresql start + dialog --msgbox "PostgreSQL started." 10 30 + ;; + runit) + echo "Runit does not manage PostgreSQL." + ;; + esac +} + +# Function to stop PostgreSQL +stop_postgresql() { + case $INIT_SYSTEM in + systemd | sysvinit) + echo "Stopping PostgreSQL..." + sudo systemctl stop postgresql + dialog --msgbox "PostgreSQL stopped." 10 30 + ;; + openrc) + sudo rc-service postgresql stop + dialog --msgbox "PostgreSQL stopped." 10 30 + ;; + runit) + echo "Runit does not manage PostgreSQL." + ;; + esac +} + +# Function to restart PostgreSQL +restart_postgresql() { + case $INIT_SYSTEM in + systemd | sysvinit) + echo "Restarting PostgreSQL..." + sudo systemctl restart postgresql + dialog --msgbox "PostgreSQL restarted." 10 30 + ;; + openrc) + sudo rc-service postgresql restart + dialog --msgbox "PostgreSQL restarted." 10 30 + ;; + runit) + echo "Runit does not manage PostgreSQL." + ;; + esac +} + +# Function to enable PostgreSQL at boot +enable_postgresql_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + echo "Enabling PostgreSQL at boot..." + sudo systemctl enable postgresql + dialog --msgbox "PostgreSQL enabled at boot." 10 30 + ;; + openrc) + sudo rc-update add postgresql default + dialog --msgbox "PostgreSQL enabled at boot." 10 30 + ;; + runit) + echo "Runit does not manage PostgreSQL." + ;; + esac +} + +# Function to disable PostgreSQL at boot +disable_postgresql_at_boot() { + case $INIT_SYSTEM in + systemd | sysvinit) + echo "Disabling PostgreSQL at boot..." + sudo systemctl disable postgresql + dialog --msgbox "PostgreSQL disabled at boot." 10 30 + ;; + openrc) + sudo rc-update del postgresql default + dialog --msgbox "PostgreSQL disabled at boot." 10 30 + ;; + runit) + echo "Runit does not manage PostgreSQL." + ;; + esac +} + +# Function to secure PostgreSQL installation +secure_postgresql() { + echo "Securing PostgreSQL installation..." + 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() { + while true; do + 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 + + 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 +} + +# Main script logic +detect_init_system +configure_postgresql + diff --git a/iso_configs/server/scripts/configure_sqlite.sh b/iso_configs/server/scripts/devuan/configure_sqlite.sh similarity index 69% rename from iso_configs/server/scripts/configure_sqlite.sh rename to iso_configs/server/scripts/devuan/configure_sqlite.sh index 9288de30..c03c1b3b 100755 --- a/iso_configs/server/scripts/configure_sqlite.sh +++ b/iso_configs/server/scripts/devuan/configure_sqlite.sh @@ -1,3 +1,4 @@ + #!/bin/bash # Function to install SQLite if not installed @@ -13,36 +14,6 @@ install_sqlite_if_needed() { 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." @@ -120,21 +91,16 @@ configure_sqlite() { while true; do CHOICE=$(dialog --clear --backtitle "Configure SQLite" \ --title "SQLite Menu" \ - --menu "Choose an option:" 20 60 13 \ + --menu "Choose an option:" 20 60 10 \ 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" \ + 2 "Secure SQLite Installation" \ + 3 "Create SQLite Database" \ + 4 "Create Table in SQLite" \ + 5 "Insert Data into SQLite Table" \ + 6 "Query Data from SQLite Table" \ + 7 "Backup SQLite Database" \ + 8 "Restore SQLite Database" \ + 9 "Return to Main Menu" \ 3>&1 1>&2 2>&3 3>&-) clear @@ -146,19 +112,14 @@ configure_sqlite() { 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 ;; + 2) secure_sqlite ;; + 3) create_sqlite_database ;; + 4) create_sqlite_table ;; + 5) insert_data_into_sqlite ;; + 6) query_data_from_sqlite ;; + 7) backup_sqlite_database ;; + 8) restore_sqlite_database ;; + 9) break ;; *) dialog --msgbox "Invalid option." 10 30 ;; esac done diff --git a/iso_configs/server/scripts/devuan/configure_ssh.sh b/iso_configs/server/scripts/devuan/configure_ssh.sh new file mode 100755 index 00000000..46903937 --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_ssh.sh @@ -0,0 +1,346 @@ +#!/bin/bash + +# Function to generate SSH keys +generate_ssh_keys() { + dialog --yesno "Do you want to generate SSH keys?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + SSH_DIR=~/.ssh + mkdir -p $SSH_DIR + SSH_KEY_FILE=$SSH_DIR/id_rsa + ssh-keygen -t rsa -b 4096 -f $SSH_KEY_FILE -N "" + + dialog --msgbox "SSH keys generated in $SSH_KEY_FILE." 10 60 +} + +# Function to add SSH key to authorized_keys +add_ssh_key() { + KEY_FILE=$(dialog --inputbox "Enter the path to the SSH public key file:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$KEY_FILE" ]; then + dialog --msgbox "Please enter a valid path to the SSH public key file." 10 60 + else + mkdir -p ~/.ssh + cat "$KEY_FILE" >> ~/.ssh/authorized_keys + dialog --msgbox "SSH key added to authorized_keys." 10 60 + fi +} + +# Function to configure advanced SSH options +configure_advanced_ssh() { + while true; do + ADV_CHOICE=$(dialog --clear --backtitle "SSH Advanced Configuration" \ + --title "SSH Advanced Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Edit SSH Config File" \ + 2 "Restart SSH Service" \ + 3 "Check SSH Service Status" \ + 4 "Install OpenSSH Server" \ + 5 "Uninstall OpenSSH Server" \ + 6 "View SSH Logs" \ + 7 "Backup SSH Config" \ + 8 "Restore SSH Config" \ + 9 "Change SSH Port" \ + 10 "Enable/Disable Password Authentication" \ + 11 "List SSH Connections" \ + 12 "Back to SSH Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $ADV_CHOICE in + 1) ${EDITOR:-nano} /etc/ssh/sshd_config ;; + 2) restart_ssh_service ;; + 3) check_ssh_service_status ;; + 4) install_openssh_server ;; + 5) uninstall_openssh_server ;; + 6) view_ssh_logs ;; + 7) backup_ssh_config ;; + 8) restore_ssh_config ;; + 9) change_ssh_port ;; + 10) toggle_password_authentication ;; + 11) list_ssh_connections ;; + 12) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to install OpenSSH Server +install_openssh_server() { + dialog --yesno "Do you want to install OpenSSH Server?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + case $INIT_SYSTEM in + "sysvinit") + apt update + apt install -y openssh-server + service ssh start + update-rc.d ssh defaults + ;; + "openrc") + apk update + apk add openssh + rc-update add sshd + rc-service sshd start + ;; + "runit") + apk update + apk add openssh + ln -s /etc/runit/sv/sshd /run/runit/service + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "OpenSSH Server installed and enabled." 10 60 +} + +# Function to uninstall OpenSSH Server +uninstall_openssh_server() { + dialog --yesno "Do you want to uninstall OpenSSH Server?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + case $INIT_SYSTEM in + "sysvinit") + service ssh stop + update-rc.d -f ssh remove + apt remove -y openssh-server + ;; + "openrc") + rc-service sshd stop + rc-update del sshd + apk del openssh + ;; + "runit") + rm /run/runit/service/sshd + apk del openssh + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "OpenSSH Server uninstalled." 10 60 +} + +# Function to view SSH logs +view_ssh_logs() { + if command -v journalctl >/dev/null 2>&1; then + dialog --msgbox "$(journalctl -u ssh --no-pager)" 30 80 + else + dialog --msgbox "Journalctl not found. Cannot view SSH logs." 10 60 + fi +} + +# Function to backup SSH config +backup_ssh_config() { + BACKUP_DIR="/var/backups" + BACKUP_FILE="sshd_config_$(date +"%Y%m%d_%H%M%S").bak" + cp /etc/ssh/sshd_config $BACKUP_DIR/$BACKUP_FILE + dialog --msgbox "SSH config backed up to $BACKUP_DIR/$BACKUP_FILE." 10 60 +} + +# Function to restore SSH config +restore_ssh_config() { + BACKUP_FILE=$(dialog --inputbox "Enter the full path of the SSH config backup file:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$BACKUP_FILE" ]; then + dialog --msgbox "Please enter a valid path to the SSH config backup file." 10 60 + elif [ ! -f "$BACKUP_FILE" ]; then + dialog --msgbox "Backup file not found." 10 60 + else + cp "$BACKUP_FILE" /etc/ssh/sshd_config + + case $INIT_SYSTEM in + "sysvinit") + service ssh restart + ;; + "openrc") + rc-service sshd restart + ;; + "runit") + sv restart sshd + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "SSH config restored from $BACKUP_FILE." 10 60 + fi +} + +# Function to change SSH port +change_ssh_port() { + NEW_PORT=$(dialog --inputbox "Enter the new SSH port:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [[ $NEW_PORT =~ ^[0-9]+$ ]]; then + sed -i "s/#Port 22/Port $NEW_PORT/" /etc/ssh/sshd_config + + case $INIT_SYSTEM in + "sysvinit") + service ssh restart + ;; + "openrc") + rc-service sshd restart + ;; + "runit") + sv restart sshd + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "SSH port changed to $NEW_PORT." 10 60 + else + dialog --msgbox "Invalid port number." 10 60 + fi +} + +# Function to enable/disable password authentication in SSH +toggle_password_authentication() { + STATUS=$(dialog --menu "Choose an option:" 10 60 2 \ + 1 "Enable Password Authentication" \ + 2 "Disable Password Authentication" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + case $STATUS in + 1) sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config ;; + 2) sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config ;; + esac + + case $INIT_SYSTEM in + "sysvinit") + service ssh restart + ;; + "openrc") + rc-service sshd restart + ;; + "runit") + sv restart sshd + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "Password authentication $(echo $STATUS | tr '[:lower:]' '[:upper:]')." 10 60 +} + +# Function to list SSH connections +list_ssh_connections() { + netstat -tnpa | grep 'ESTABLISHED.*sshd' + dialog --msgbox "List of SSH connections displayed." 10 60 +} + +# Function to check if OpenSSH is installed +check_ssh_installation() { + case $INIT_SYSTEM in + "sysvinit") + dpkg -l openssh-server >/dev/null 2>&1 + ;; + "openrc") + apk info openssh >/dev/null 2>&1 + ;; + "runit") + apk info openssh >/dev/null 2>&1 + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + if [ $? -eq 0 ]; then + dialog --msgbox "OpenSSH is installed." 10 60 + else + dialog --msgbox "OpenSSH is not installed." 10 60 + fi +} + +# Function to configure SSH options +configure_ssh() { + while true; do + SSH_CHOICE=$(dialog --clear --backtitle "SSH Configuration" \ + --title "SSH Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Generate SSH Keys" \ + 2 "Add SSH Key to authorized_keys" \ + 3 "Advanced Configuration" \ + 4 "Check SSH Installation" \ + 5 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $SSH_CHOICE in + 1) generate_ssh_keys ;; + 2) add_ssh_key ;; + 3) configure_advanced_ssh ;; + 4) check_ssh_installation ;; + 5) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Determine the init system and execute the main function to configure SSH +if command -v systemctl >/dev/null 2>&1; then + INIT_SYSTEM="sysvinit" +elif command -v rc-service >/dev/null 2>&1; then + INIT_SYSTEM="openrc" +elif command -v sv >/dev/null 2>&1; then + INIT_SYSTEM="runit" +else + dialog --msgbox "Unsupported init system." 10 60 + exit 1 +fi + +configure_ssh + diff --git a/iso_configs/server/scripts/devuan/configure_static_ip.sh b/iso_configs/server/scripts/devuan/configure_static_ip.sh new file mode 100755 index 00000000..b8561c7f --- /dev/null +++ b/iso_configs/server/scripts/devuan/configure_static_ip.sh @@ -0,0 +1,210 @@ +#!/bin/bash + +# Function to configure static IP +configure_static_ip() { + while true; do + # Prompt for network interface + INTERFACE=$(dialog --inputbox "Enter physical network interface (e.g., eth0):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Prompt for IP address + IP_ADDRESS=$(dialog --inputbox "Enter static IP address (e.g., 192.168.1.100):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Validate IP address format + if ! valid_ip "$IP_ADDRESS"; then + dialog --msgbox "Invalid IP address format. Please enter a valid IP address." 10 60 + continue + fi + + # Prompt for netmask + NETMASK=$(dialog --inputbox "Enter netmask (e.g., 255.255.255.0):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Validate netmask format + if ! valid_netmask "$NETMASK"; then + dialog --msgbox "Invalid netmask format. Please enter a valid netmask." 10 60 + continue + fi + + # Prompt for gateway + GATEWAY=$(dialog --inputbox "Enter gateway (optional, leave blank if none):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Prompt for DNS server + DNS_SERVER=$(dialog --inputbox "Enter DNS server (optional, leave blank if none):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Apply the static IP configuration + if [ -z "$INTERFACE" ] || [ -z "$IP_ADDRESS" ] || [ -z "$NETMASK" ]; then + dialog --msgbox "Network interface, IP address, and netmask cannot be empty. Please enter valid information." 10 60 + else + apply_static_ip "$INTERFACE" "$IP_ADDRESS" "$NETMASK" "$GATEWAY" "$DNS_SERVER" + return $? + fi + done +} + +# Function to validate IP address format +valid_ip() { + local ip=$1 + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + local IFS='.' + ip=($ip) + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + else + false + fi +} + +# Function to validate netmask format +valid_netmask() { + local netmask=$1 + if [[ $netmask =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + local IFS='.' + netmask=($netmask) + [[ ${netmask[0]} -le 255 && ${netmask[1]} -le 255 && ${netmask[2]} -le 255 && ${netmask[3]} -le 255 ]] + else + false + fi +} + +# Function to apply static IP configuration +apply_static_ip() { + local interface=$1 + local ip_address=$2 + local netmask=$3 + local gateway=$4 + local dns_server=$5 + + # Apply configuration to /etc/network/interfaces + case $INIT_SYSTEM in + "sysvinit") + cat </dev/null +auto lo +iface lo inet loopback + +auto $interface +iface $interface inet static + address $ip_address + netmask $netmask + gateway $gateway + dns-nameservers $dns_server +EOF + service networking restart + ;; + "openrc") + cat </dev/null +iface $interface inet static + address $ip_address + netmask $netmask + gateway $gateway + dns-nameservers $dns_server +EOF + rc-service networking restart + ;; + "runit") + cat </dev/null +#!/bin/sh +exec ip addr add $ip_address/$netmask dev $interface +exec ip link set $interface up +EOF + chmod +x /etc/network.d/$interface + sv restart networking + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + # Check if configuration applied successfully + if ip addr show $interface | grep -q "$ip_address"; then + dialog --msgbox "Static IP configuration applied successfully:\nInterface: $interface\nIP Address: $ip_address\nNetmask: $netmask\nGateway: $gateway\nDNS Server: $dns_server" 12 60 + return 0 + else + dialog --msgbox "Failed to apply static IP configuration. Please check your settings and try again." 10 60 + return 1 + fi +} + +# Main function to configure host settings +configure_host() { + while true; do + HOST_CHOICE=$(dialog --clear --backtitle "Host Configuration" \ + --title "Host Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Configure Static IP" \ + 2 "Show Current Network Settings" \ + 3 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $HOST_CHOICE in + 1) configure_static_ip ;; + 2) show_current_network_settings ;; + 3) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to show current network settings +show_current_network_settings() { + case $INIT_SYSTEM in + "sysvinit") + CURRENT_SETTINGS=$(ifconfig) + ;; + "openrc") + CURRENT_SETTINGS=$(ip addr show) + ;; + "runit") + CURRENT_SETTINGS=$(ip addr show) + ;; + *) + dialog --msgbox "Unsupported init system: $INIT_SYSTEM" 10 60 + return 1 + ;; + esac + + dialog --msgbox "Current Network Settings:\n\n$CURRENT_SETTINGS" 20 80 +} + +# Determine the init system and execute the main function to configure host settings +if command -v systemctl >/dev/null 2>&1; then + INIT_SYSTEM="sysvinit" +elif command -v rc-service >/dev/null 2>&1; then + INIT_SYSTEM="openrc" +elif command -v sv >/dev/null 2>&1; then + INIT_SYSTEM="runit" +else + dialog --msgbox "Unsupported init system." 10 60 + exit 1 +fi + +configure_host + diff --git a/iso_configs/server/scripts/devuan/create_user.sh b/iso_configs/server/scripts/devuan/create_user.sh new file mode 100755 index 00000000..65ebb9b7 --- /dev/null +++ b/iso_configs/server/scripts/devuan/create_user.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# 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>&-) + 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 + diff --git a/iso_configs/server/scripts/devuan/update_and_install.sh b/iso_configs/server/scripts/devuan/update_and_install.sh new file mode 100755 index 00000000..8f5bc73f --- /dev/null +++ b/iso_configs/server/scripts/devuan/update_and_install.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# Function to update package list +update_package_list() { + echo "Updating package list..." + if ! sudo apt update; then + echo "Failed to update package list." + dialog --title "Error" --msgbox "Failed to update package list. Check your internet connection or repository settings." 10 60 + return 1 + fi + echo "Package list updated successfully." +} + +# Function to install selected packages +install_selected_packages() { + local selected_packages=("$@") + + echo "Installing selected packages..." + for package in "${selected_packages[@]}"; do + echo "Installing package: $package" + if sudo apt install -y "$package"; then + echo "Package $package installed successfully." + else + echo "Failed to install package: $package" + dialog --title "Error" --msgbox "Failed to install package: $package" 10 60 + fi + done + echo "All packages installed successfully." + dialog --title "Success" --msgbox "All packages installed successfully." 10 60 +} + +# List of packages available for installation +# Add more if necessary +PACKAGES=("vim" + "emacs" + "mcedit" + "joe" + "wget" + "curl" + "lynx" + "htop" + "iftop" + "iotop" + "git" + "btop" + "dnsutils") + +# Check if script is running as root +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root." + dialog --title "Error" --msgbox "This script must be run as root." 10 30 + exit 1 +fi + +# Update package list before installation +update_package_list + +# Prepare package list for dialog +DIALOG_PACKAGES=() +for idx in "${!PACKAGES[@]}"; do + DIALOG_PACKAGES+=("$((idx + 1))" "${PACKAGES[$idx]}" off) +done + +while true; do + # Show dialog box for package selection + echo "Starting package selection dialog..." + selections=$(dialog --stdout --checklist "Select packages to install (use space to select):" 20 60 ${#PACKAGES[@]} "${DIALOG_PACKAGES[@]}" 3>&1 1>&2 2>&3) + + # Check if cancel button is pressed or no selection was made + if [[ $? -ne 0 ]]; then + echo "Installation canceled." + dialog --title "Information" --msgbox "Installation canceled." 10 60 + exit 0 + fi + + # Check if no selection was made + if [[ -z "$selections" ]]; then + echo "No packages selected. Please select at least one package." + dialog --title "Error" --msgbox "No packages selected. Please select at least one package." 10 60 + else + break + fi +done + +# Convert selection into an array +IFS=" " read -r -a packages_to_install <<< "$selections" + +# Call function to install selected packages +install_selected_packages "${packages_to_install[@]}" + +echo "Script completed." + diff --git a/iso_configs/server/scripts/devuan/welcome.sh b/iso_configs/server/scripts/devuan/welcome.sh new file mode 100755 index 00000000..640415ce --- /dev/null +++ b/iso_configs/server/scripts/devuan/welcome.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# Function to display the main menu +main_menu() { + while true; do + CHOICE=$(dialog --clear --backtitle "PeppermintOS Server Configuration" \ + --title "Main Menu" \ + --menu "Choose an option:" 20 60 15 \ + 1 "Configure SSH" \ + 2 "Configure Static IP" \ + 3 "Update and Install Packages" \ + 4 "Configure firewalld" \ + 5 "Configure Hostname" \ + 6 "Create User" \ + 7 "Configure Nginx" \ + 8 "Configure Apache2" \ + 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 + if [[ $? -ne 0 ]]; then + clear + echo "Menu closed or canceled. Exiting..." + exit 0 + fi + + clear + + case $CHOICE in + 1) sudo ./configure_ssh.sh ;; + 2) sudo ./configure_static_ip.sh ;; + 3) sudo ./update_and_install.sh ;; + 4) sudo ./configure_firewalld.sh ;; + 5) sudo ./configure_hostname.sh ;; + 6) sudo ./create_user.sh ;; + 7) sudo ./configure_nginx.sh ;; + 8) sudo ./configure_apache2.sh ;; + 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 +} + +# Show welcome message +dialog --msgbox "Welcome to PeppermintOS Server Friendly Configuration Tool! +This tool will help you configure various aspects of your server, including: + +1. SSH: Configure the SSH server and client for secure remote access. +2. Static IP: Set a static IP address for consistent network communication. +3. Update and Install Packages: Ensure your system is up-to-date and install essential packages. +4. firewalld: Set up firewall rules to secure your server. +5. Hostname: Change the hostname of your server. +6. Create User: Add new users to your system. +7. Nginx: Configure the Nginx web server. +8. Apache2: Configure the Apache2 web server. +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 + +# Display main menu +main_menu + diff --git a/python_modules/conf.py b/python_modules/conf.py index 10398cd4..746a6af6 100644 --- a/python_modules/conf.py +++ b/python_modules/conf.py @@ -46,8 +46,9 @@ shared_setup_server_cmds = ('inflate_bubble.set_fusato_server_installer_structur 'inflate_bubble.set_grub_shared', 'inflate_bubble.set_binary_shared', 'infra.shared_server_files', - 'infra.boostrap_shared' - ) + 'infra.boostrap_shared', + 'infra.server_config_files' + ) shared_setup_mini_cmds = ('inflate_bubble.set_fusato_mini_installer_structure', 'inflate_bubble.set_binary_shared', @@ -306,9 +307,8 @@ SERVER_LIST = ('zonefstoolspep\n' 'libzbdpep1\n' 'sudo\n' 'task-ssh-server\n' - #'task-web-server\n' + 'dialog\n' 'sshguard\n' - 'btop\n' 'whois\n' 'rkhunter\n' 'debsecan\n' @@ -318,8 +318,6 @@ SERVER_LIST = ('zonefstoolspep\n' 'openssl\n' 'cups\n' 'git\n' - 'wget\n' - 'vim\n' ) MINI_LIST = ('nano\n' diff --git a/python_modules/inflate_bubble.py b/python_modules/inflate_bubble.py index 430d4946..e9bb056c 100644 --- a/python_modules/inflate_bubble.py +++ b/python_modules/inflate_bubble.py @@ -67,8 +67,9 @@ def set_fusato_server_structure(): at the moment you deal with chroot, bootstrap, and includes-installer """ - make_chroot = ['etc/firewalld/zones', - 'boot/grub', + make_chroot = ['etc/firewalld/zones/', + 'boot/grub/', + 'usr/local/bin/', ] os.chdir(os.path.join(HOME_FOLDER, FUSATO_ROOT)) if os.path.exists('config'): diff --git a/python_modules/infra.py b/python_modules/infra.py index a808ecf6..b915b533 100644 --- a/python_modules/infra.py +++ b/python_modules/infra.py @@ -620,6 +620,80 @@ def shared_server_files(): ) logger.info(MSG_FIN + HOME_FOLDER + WPCHROOT + des) +def server_config_files(sbase): + """ + This will copy all specific files that are used for the server builds, + adapted for the provided base (sbase). + """ + base_config = { + "debian": { + "scripts_dir": "/server/scripts/debian/", + }, + "devuan": { + "scripts_dir": "/server/scripts/devuan/", + } + } + + if sbase not in base_config: + logger.error(f"Unsupported base: {sbase}") + return + + logger.info(f"Copy Shared Files for {sbase.capitalize()}") + + src_paths = [ + os.path.join(base_config[sbase]["scripts_dir"], 'welcome.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_apache2.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_firewalld.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_hostname.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_mariadb.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_nginx.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_php_and_docker.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_postfix.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_postgresql.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_sqlite.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_ssh.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'configure_static_ip.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'create_user.sh'), + os.path.join(base_config[sbase]["scripts_dir"], 'update_and_install.sh'), + ] + + des_paths = [ + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + '/usr/local/bin', + ] + + src_q = collections.deque(src_paths) + des_q = collections.deque(des_paths) + + while src_q and des_q: + src = src_q.popleft() + des = des_q.popleft() + src_path = os.path.join(HOME_FOLDER, src) + des_path = os.path.join(HOME_FOLDER, WPCHROOT, des) + + logger.info(f"Copying {src_path} to {des_path}") + try: + shutil.copy2(src_path, des_path) + except Exception as e: + logger.error(f"Error copying {src_path} to {des_path}: {e}") + else: + logger.info(f"Successfully copied {src_path} to {des_path}") + +# Example usage +shared_server_files("debian") +shared_server_files("devuan") def boostrap_shared(): """