files update

This commit is contained in:
manuel 2024-07-31 10:55:04 +00:00
parent f756b0ecc9
commit 5e67b135fd
38 changed files with 5178 additions and 66 deletions

View File

@ -70,6 +70,7 @@ os.makedirs(os.path.join(uchinanchu, "fusato", "config", "includes.chroot", "etc
os.makedirs(os.path.join(uchinanchu, "fusato", "config", "includes.chroot", "etc", "firewalld", "zones"), exist_ok=True)
os.makedirs(os.path.join(uchinanchu, "fusato", "config", "includes.installer", "preseed", "grub"), exist_ok=True)
os.makedirs(os.path.join(uchinanchu, "fusato", "config", "includes.installer", "usr", "lib", "finish-install.d"), exist_ok=True)
os.makedirs(os.path.join(uchinanchu, "fusato", "config", "includes.chroot", "usr", "local", "bin"), exist_ok=True)
# Install software
with open(os.path.join(uchinanchu, "fusato", "config", "package-lists", "package.list.chroot"), "a") as file:
@ -79,26 +80,19 @@ with open(os.path.join(uchinanchu, "fusato", "config", "package-lists", "package
file.write("libzbdpep1\n")
file.write("sudo\n")
file.write("task-ssh-server\n")
file.write("task-web-server\n")
file.write("sshguard\n")
file.write("htop\n")
file.write("whois\n")
file.write("rkhunter\n")
file.write("debsecan\n")
file.write("net-tools\n")
file.write("cockpit\n")
file.write("cockpit-podman\n")
file.write("cockpit-machines\n")
file.write("cockpit-pcp\n")
file.write("podman\n")
file.write("nfs-common\n")
file.write("firewalld\n")
file.write("samba\n")
file.write("cups\n")
file.write("gvfs-backends\n")
file.write("git\n")
file.write("wget\n")
file.write("curl\n")
file.write("tuned\n")
file.write("dialog\n")
# Copy single files and folder to the chroot
shutil.copy2(os.path.join(uchinanchu, "pepgrub", "grub"), os.path.join(uchinanchu, "fusato", "config", "includes.installer", "preseed", "grub"))
@ -111,6 +105,8 @@ for item in os.listdir(os.path.join(uchinanchu, "pepfirewall")):
shutil.copy2(os.path.join(uchinanchu, "pepinstaller", "preseed", "preseed.cfg"), os.path.join(uchinanchu, "fusato", "config", "includes.installer"))
for item in os.listdir(os.path.join(uchinanchu, "pepscripts")):
shutil.copy2(os.path.join(uchinanchu, "pepscripts", item), os.path.join(uchinanchu, "fusato", "config", "includes.installer", "usr", "lib", "finish-install.d"))
for item in os.listdir(os.path.join(uchinanchu, "pepinstaller", "scripts" , "debsrv")):
shutil.copy2(os.path.join(uchinanchu, "pepinstaller", "scripts" , "debsrv", item), os.path.join(uchinanchu, "fusato", "config", "includes.chroot", "usr", "local", "bin"))
# Copy recursive files and sub-directories, containing symlinks.
shutil.copytree(os.path.join(uchinanchu, "peploadersplash", "boot"), os.path.join(uchinanchu, "fusato", "config", "includes.binary", "boot"))

View File

@ -53,7 +53,7 @@ mkdir -p $uchinanchu/fusato/config/includes.binary
mkdir -p $uchinanchu/fusato/config/includes.chroot/boot/grub
mkdir -p $uchinanchu/fusato/config/includes.chroot/etc/default
mkdir -p $uchinanchu/fusato/config/includes.installer/usr/share
mkdir -p $uchinanchu/fusato/config/includes.chroot/etc
mkdir -p $uchinanchu/fusato/config/includes.chroot/usr/local/bin
mkdir -p $uchinanchu/fusato/config/includes.chroot/etc/firewalld/zones
mkdir -p $uchinanchu/fusato/config/includes.installer/preseed/grub
mkdir -p $uchinanchu/fusato/config/includes.installer/usr/lib/finish-install.d
@ -65,25 +65,19 @@ dmzonedtoolspep
libzbdpep1
sudo
task-ssh-server
task-web-server
sshguard
htop
whois
rkhunter
debsecan
net-tools
cockpit
cockpit-podman
cockpit-machines
cockpit-pcp
podman
nfs-common
firewalld
samba
cups
gvfs-backends
git
wget
curl
tuned
" >> $uchinanchu/fusato/config/package-lists/package.list.chroot
@ -95,6 +89,7 @@ cp $uchinanchu/peprepo/* $uchinanchu/fusato/config/archives
cp $uchinanchu/pepfirewall/* $uchinanchu/fusato/config/includes.chroot/etc/firewalld/zones
cp $uchinanchu/pepinstaller/preseed/preseed.cfg $uchinanchu/fusato/config/includes.installer
cp $uchinanchu/pepscripts/* $uchinanchu/fusato/config/includes.installer/usr/lib/finish-install.d
cp $uchinanchu/pepinstaller/scripts/debsrv/* $uchinanchu/fusato/config/includes.chroot/usr/local/bin
# Copy recursive files and sub-directories, containing symlinks.
cp -r $uchinanchu/peploadersplash/boot $uchinanchu/fusato/config/includes.binary

View File

@ -8,8 +8,5 @@
### Missing files no longer cause builds to fail.
# Remove software
# apt remove -y firefox-esr
# apt remove -y termit
#apt --purge --yes autoremove nvidia*
apt --purge --yes autoremove raspi-firmware
apt --purge --yes autoremove nvidia*

View File

@ -1,27 +0,0 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppemrintOS Team (peppermintosteam@proton.me)
# List of services to be enabled
services=("firewalld" "cockpit" "ssh" "sshguard" "apache2")
# Loop to enable each service
for service in "${services[@]}"; do
# Check if the service is already enabled
if systemctl is-enabled "$service" >/dev/null 2>&1; then
echo "Service $service is already enabled."
else
# Enable the service
systemctl enable "$service"
echo "Service $service has been successfully enabled."
fi
done
# Reload the services
systemctl daemon-reload
echo "Completed."

View File

@ -0,0 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppemrintOS Team (peppermintosteam@proton.me)
### install cockpit server manager
apt -y install cockpit cockpit-machines cockpit-podman

View File

@ -0,0 +1,38 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppemrintOS Team (peppermintosteam@proton.me
# Install required SELinux packages
apt -y install selinux-basics selinux-policy-default auditd
# Initialize SELinux
selinux-activate
# Restart auditd service
systemctl restart auditd
# Enable SELinux policy activation on boot
systemctl enable selinux-policy-activate
# Disable AppArmor
systemctl disable apparmor
systemctl stop apparmor
apt -y purge apparmor
# Additional configuration (optional)
# Here you can add commands to adjust policies or configure additional rules
# Set SELinux to enforcing mode
/usr/sbin/setenforce 1
# Configure file contexts (example)
/sbin/restorecon -Rv /etc/
# Allow HTTPD scripts and modules to connect to the network (example)
/usr/sbin/setsebool -P httpd_can_network_connect 1
exit 0

View File

@ -0,0 +1,226 @@
#!/bin/bash
# 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 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 started." 10 30
}
# Function to stop Apache
stop_apache() {
sudo systemctl stop apache2
dialog --msgbox "Apache stopped." 10 30
}
# Function to restart Apache
restart_apache() {
sudo systemctl restart apache2
dialog --msgbox "Apache restarted." 10 30
}
# Function to enable Apache at boot
enable_apache_at_boot() {
sudo systemctl enable apache2
dialog --msgbox "Apache enabled at boot." 10 30
}
# Function to disable Apache at boot
disable_apache_at_boot() {
sudo systemctl disable apache2
dialog --msgbox "Apache disabled at boot." 10 30
}
# Function to secure Apache installation
secure_apache() {
echo "Apache does not require additional security configuration."
dialog --msgbox "Apache installation secured." 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 [ $? -ne 0 ]; then
return
fi
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@$DOMAIN
ServerName $DOMAIN
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 "Virtual host for $DOMAIN configured successfully." 10 60
fi
}
# 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>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -z "$SITE" ]]; then
dialog --msgbox "No site configuration file name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Site" \
--title "Enable/Disable Apache Site" \
--menu "Choose an action:" 10 40 2 \
1 "Enable" \
2 "Disable" \
3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
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>&-)
if [ $? -ne 0 ]; then
return
fi
if [[ -z "$MODULE" ]]; then
dialog --msgbox "No module name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Apache Module" \
--title "Enable/Disable Apache Module" \
--menu "Choose an action:" 10 40 2 \
1 "Enable" \
2 "Disable" \
3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
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 [ $? -ne 0 ]; then
return
fi
if [[ -n "$DOMAIN" ]]; then
sudo certbot --apache -d $DOMAIN
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 12 \
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>&-)
# Check if user canceled
if [ $? -ne 0 ]; then
break
fi
clear
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
}
# Show main configuration menu
configure_apache

View File

@ -0,0 +1,231 @@
#!/bin/bash
# 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
else
echo "Docker is already installed."
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)
# Check if user canceled
if [ $? -eq 1 ]; then
return
fi
case $OPTION in
1) NETWORK=$(dialog --inputbox "Enter Docker network name:" 10 40 3>&1 1>&2 2>&3)
if [ $? -ne 1 ]; then
sudo docker network create $NETWORK
fi ;;
2) manage_docker_containers ;;
3) manage_docker_images ;;
4) manage_docker_volumes ;;
5) manage_docker_compose ;;
6) return ;;
*) 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)
# Check if user canceled
if [ $? -eq 1 ]; then
return
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)
if [ $? -ne 1 ]; then
sudo docker start $CONTAINER
fi ;;
3) CONTAINER=$(dialog --inputbox "Enter the container ID or name:" 10 40 3>&1 1>&2 2>&3)
if [ $? -ne 1 ]; then
sudo docker stop $CONTAINER
fi ;;
4) return ;;
*) 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)
# Check if user canceled
if [ $? -eq 1 ]; then
return
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)
if [ $? -ne 1 ]; then
sudo docker pull $IMAGE
fi ;;
3) IMAGE=$(dialog --inputbox "Enter the image ID or name:" 10 40 3>&1 1>&2 2>&3)
if [ $? -ne 1 ]; then
sudo docker rmi $IMAGE
fi ;;
4) return ;;
*) 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)
# Check if user canceled
if [ $? -eq 1 ]; then
return
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)
if [ $? -ne 1 ]; then
sudo docker volume create $VOLUME
fi ;;
3) VOLUME=$(dialog --inputbox "Enter the volume name or ID:" 10 40 3>&1 1>&2 2>&3)
if [ $? -ne 1 ]; then
sudo docker volume rm $VOLUME
fi ;;
4) return ;;
*) 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)
# Check if user canceled
if [ $? -eq 1 ]; then
return
fi
case $ACTION in
1) docker_compose_up ;;
2) docker_compose_down ;;
3) docker_compose_remove ;;
4) return ;;
*) 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 [ $? -ne 1 ] && [ -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 [ $? -ne 1 ] && [ -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 [ $? -ne 1 ] && [ -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 4 \
1 "Install/Check Docker" \
2 "Configure Docker" \
3 "Exit" \
3>&1 1>&2 2>&3)
# Check if user canceled
if [ $? -eq 1 ]; then
break
fi
case $CHOICE in
1) install_docker_if_needed ;;
2) configure_docker ;;
3) break ;;
*) dialog --msgbox "Invalid option." 10 30 ;;
esac
done
echo "Server utilities installation and configuration script completed."
}
# Display main menu
main_menu

View File

@ -0,0 +1,145 @@
k#!/bin/bash
# Function to enable firewalld
enable_firewalld() {
systemctl enable firewalld
systemctl start firewalld
dialog --msgbox "firewalld enabled and started." 10 30
}
# Function to disable firewalld
disable_firewalld() {
systemctl stop firewalld
systemctl disable firewalld
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
firewall-cmd --permanent --add-service=$SERVICE
firewall-cmd --reload
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
firewall-cmd --permanent --remove-service=$SERVICE
firewall-cmd --reload
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
firewall-cmd --permanent --add-port=$PORT
firewall-cmd --reload
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
firewall-cmd --permanent --remove-port=$PORT
firewall-cmd --reload
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
firewall-cmd --zone=$ZONE --add-interface=$INTERFACE --permanent
firewall-cmd --reload
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
}
# Execute the main function to configure firewalld
configure_firewalld

View File

@ -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

View File

@ -0,0 +1,221 @@
#!/bin/bash
# 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."
dialog --msgbox "Failed to install MariaDB. Exiting." 10 30
exit 1
fi
else
dialog --msgbox "MariaDB is already installed." 10 30
fi
}
# Function to start MariaDB
start_mariadb() {
sudo systemctl start mariadb
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB started successfully." 10 30
else
dialog --msgbox "Failed to start MariaDB." 10 30
fi
}
# Function to stop MariaDB
stop_mariadb() {
sudo systemctl stop mariadb
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB stopped successfully." 10 30
else
dialog --msgbox "Failed to stop MariaDB." 10 30
fi
}
# Function to restart MariaDB
restart_mariadb() {
sudo systemctl restart mariadb
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB restarted successfully." 10 30
else
dialog --msgbox "Failed to restart MariaDB." 10 30
fi
}
# Function to enable MariaDB at boot
enable_mariadb_at_boot() {
sudo systemctl enable mariadb
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB enabled at boot successfully." 10 30
else
dialog --msgbox "Failed to enable MariaDB at boot." 10 30
fi
}
# Function to disable MariaDB at boot
disable_mariadb_at_boot() {
sudo systemctl disable mariadb
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB disabled at boot successfully." 10 30
else
dialog --msgbox "Failed to disable MariaDB at boot." 10 30
fi
}
# Function to secure MariaDB installation
secure_mariadb() {
sudo mysql_secure_installation
if [[ $? -eq 0 ]]; then
dialog --msgbox "MariaDB installation secured successfully." 10 30
else
dialog --msgbox "Failed to secure MariaDB installation." 10 30
fi
}
# Function to create a database
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;"
if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' created successfully." 10 60
else
dialog --msgbox "Failed to create database '$DATABASE'." 10 60
fi
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);"
if [[ $? -eq 0 ]]; then
dialog --msgbox "Table '$TABLE' created in database '$DATABASE' successfully." 10 60
else
dialog --msgbox "Failed to create table '$TABLE' in database '$DATABASE'." 10 60
fi
fi
}
# 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);"
if [[ $? -eq 0 ]]; then
dialog --msgbox "Data inserted into table '$TABLE' in database '$DATABASE' successfully." 10 60
else
dialog --msgbox "Failed to insert data into table '$TABLE' in database '$DATABASE'." 10 60
fi
fi
}
# 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
RESULT=$(mysql -e "USE $DATABASE; $QUERY")
if [[ $? -eq 0 ]]; then
dialog --msgbox "Query executed successfully. Result:\n$RESULT" 20 80
else
dialog --msgbox "Failed to execute query on table '$TABLE' in database '$DATABASE'." 10 60
fi
fi
fi
}
# 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
if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' backed up to '$DATABASE.sql' successfully." 10 60
else
dialog --msgbox "Failed to backup database '$DATABASE'." 10 60
fi
fi
}
# 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
if [[ $? -eq 0 ]]; then
dialog --msgbox "Database '$DATABASE' restored successfully." 10 60
else
dialog --msgbox "Failed to restore database '$DATABASE'." 10 60
fi
else
dialog --msgbox "File not found or invalid." 10 60
fi
fi
}
# Function to configure MariaDB
configure_mariadb() {
while true; do
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>&-)
# Check if user canceled
if [ $? -ne 0 ]; then
clear
break
fi
clear
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
}
# Show main configuration menu
configure_mariadb

View File

@ -0,0 +1,220 @@
#!/bin/bash
# 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 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 started." 10 30
}
# Function to stop Nginx
stop_nginx() {
sudo systemctl stop nginx
dialog --msgbox "Nginx stopped." 10 30
}
# Function to restart Nginx
restart_nginx() {
sudo systemctl restart nginx
dialog --msgbox "Nginx restarted." 10 30
}
# Function to enable Nginx at boot
enable_nginx_at_boot() {
sudo systemctl enable nginx
dialog --msgbox "Nginx enabled at boot." 10 30
}
# Function to disable Nginx at boot
disable_nginx_at_boot() {
sudo systemctl disable nginx
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>&-)
if [[ -z "$SITE" ]]; then
dialog --msgbox "No site configuration file name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Site" \
--title "Enable/Disable Nginx Site" \
--menu "Choose an action:" 10 40 2 \
1 "Enable" \
2 "Disable" \
3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
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>&-)
if [[ -z "$MODULE" ]]; then
dialog --msgbox "No module name entered. Returning to menu." 10 30
return
fi
ACTION=$(dialog --clear --backtitle "Enable/Disable Nginx Module" \
--title "Enable/Disable Nginx Module" \
--menu "Choose an action:" 10 40 2 \
1 "Enable" \
2 "Disable" \
3>&1 1>&2 2>&3 3>&-)
if [ $? -ne 0 ]; then
return
fi
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 12 \
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>&-)
# Check if user canceled
if [ $? -ne 0 ]; then
break
fi
clear
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
}
# Show main configuration menu
configure_nginx

View File

@ -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 "Return to Main Menu" \
3>&1 1>&2 2>&3 3>&-)
# Check if user canceled
if [ $? -ne 0 ]; then
break
fi
clear
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

View File

@ -0,0 +1,222 @@
#!/bin/bash
# Função para instalar PostgreSQL, se necessário
install_postgresql_if_needed() {
if ! dpkg -l postgresql > /dev/null 2>&1; then
echo "PostgreSQL não está instalado. Instalando..."
if sudo apt-get install -y postgresql; then
echo "PostgreSQL instalado com sucesso."
dialog --msgbox "PostgreSQL instalado com sucesso." 10 30
else
echo "Falha ao instalar PostgreSQL. Saindo."
dialog --msgbox "Falha ao instalar PostgreSQL. Saindo." 10 30
exit 1
fi
else
dialog --msgbox "PostgreSQL já está instalado." 10 30
fi
}
# Função para iniciar PostgreSQL
start_postgresql() {
sudo systemctl start postgresql
if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL iniciado com sucesso." 10 30
else
dialog --msgbox "Falha ao iniciar PostgreSQL." 10 30
fi
}
# Função para parar PostgreSQL
stop_postgresql() {
sudo systemctl stop postgresql
if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL parado com sucesso." 10 30
else
dialog --msgbox "Falha ao parar PostgreSQL." 10 30
fi
}
# Função para reiniciar PostgreSQL
restart_postgresql() {
sudo systemctl restart postgresql
if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL reiniciado com sucesso." 10 30
else
dialog --msgbox "Falha ao reiniciar PostgreSQL." 10 30
fi
}
# Função para habilitar PostgreSQL na inicialização
enable_postgresql_at_boot() {
sudo systemctl enable postgresql
if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL habilitado na inicialização com sucesso." 10 30
else
dialog --msgbox "Falha ao habilitar PostgreSQL na inicialização." 10 30
fi
}
# Função para desabilitar PostgreSQL na inicialização
disable_postgresql_at_boot() {
sudo systemctl disable postgresql
if [[ $? -eq 0 ]]; then
dialog --msgbox "PostgreSQL desabilitado na inicialização com sucesso." 10 30
else
dialog --msgbox "Falha ao desabilitar PostgreSQL na inicialização." 10 30
fi
}
# Função para garantir a instalação do PostgreSQL
secure_postgresql() {
sudo passwd postgres
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_password';"
if [[ $? -eq 0 ]]; then
dialog --msgbox "Instalação do PostgreSQL protegida com sucesso." 10 30
else
dialog --msgbox "Falha ao proteger a instalação do PostgreSQL." 10 30
fi
}
# Função para criar um banco de dados
create_database() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados a ser criado:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; then
sudo -u postgres createdb $DATABASE
if [[ $? -eq 0 ]]; então
dialog --msgbox "Banco de dados '$DATABASE' criado com sucesso." 10 60
else
dialog --msgbox "Falha ao criar o banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para criar uma tabela
create_table() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela a ser criada:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; então
sudo -u postgres psql -d $DATABASE -c "CREATE TABLE $TABLE (id SERIAL PRIMARY KEY);"
if [[ $? -eq 0 ]]; então
dialog --msgbox "Tabela '$TABLE' criada no banco de dados '$DATABASE' com sucesso." 10 60
else
dialog --msgbox "Falha ao criar a tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para inserir dados em uma tabela
insert_data() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela para inserir dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
DATA=$(dialog --inputbox "Digite os dados para inserir na tabela (por exemplo, 'valor1, valor2'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" && -n "$DATA" ]]; então
sudo -u postgres psql -d $DATABASE -c "INSERT INTO $TABLE VALUES ($DATA);"
if [[ $? -eq 0 ]]; então
dialog --msgbox "Dados inseridos na tabela '$TABLE' no banco de dados '$DATABASE' com sucesso." 10 60
else
dialog --msgbox "Falha ao inserir dados na tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para consultar dados de uma tabela
query_data() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados:" 10 40 3>&1 1>&2 2>&3 3>&-)
TABLE=$(dialog --inputbox "Digite o nome da tabela para consultar:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" && -n "$TABLE" ]]; então
QUERY=$(dialog --inputbox "Digite a consulta SQL (por exemplo, 'SELECT * FROM $TABLE;'):" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$QUERY" ]]; então
RESULT=$(sudo -u postgres psql -d $DATABASE -c "$QUERY")
if [[ $? -eq 0 ]]; então
dialog --msgbox "Consulta executada com sucesso. Resultado:\n$RESULT" 20 80
else
dialog --msgbox "Falha ao executar a consulta na tabela '$TABLE' no banco de dados '$DATABASE'." 10 60
fi
fi
fi
}
# Função para fazer backup do banco de dados
backup_database() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados para fazer backup:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; então
sudo -u postgres pg_dump $DATABASE > $DATABASE.sql
if [[ $? -eq 0 ]]; então
dialog --msgbox "Banco de dados '$DATABASE' feito backup para '$DATABASE.sql' com sucesso." 10 60
else
dialog --msgbox "Falha ao fazer backup do banco de dados '$DATABASE'." 10 60
fi
fi
}
# Função para restaurar o banco de dados
restore_database() {
DATABASE=$(dialog --inputbox "Digite o nome do banco de dados para restaurar:" 10 40 3>&1 1>&2 2>&3 3>&-)
if [[ -n "$DATABASE" ]]; então
FILE=$(dialog --inputbox "Digite o caminho para o arquivo SQL para restaurar:" 10 60 3>&1 1>&2 2>&3 3>&-)
if [[ -f "$FILE" ]]; então
sudo -u postgres psql -d $DATABASE < $FILE
if [[ $? -eq 0 ]]; então
dialog --msgbox "Banco de dados '$DATABASE' restaurado com sucesso." 10 60
else
dialog --msgbox "Falha ao restaurar o banco de dados '$DATABASE'." 10 60
fi
else
dialog --msgbox "Arquivo não encontrado ou inválido." 10 60
fi
fi
}
# Função para configurar PostgreSQL
configure_postgresql() {
while true; do
CHOICE=$(dialog --clear --backtitle "Configurar PostgreSQL" \
--title "Menu do PostgreSQL" \
--menu "Escolha uma opção:" 20 60 14 \
1 "Instalar/Verificar PostgreSQL" \
2 "Iniciar PostgreSQL" \
3 "Parar PostgreSQL" \
4 "Reiniciar PostgreSQL" \
5 "Habilitar PostgreSQL na Inicialização" \
6 "Desabilitar PostgreSQL na Inicialização" \
7 "Proteger Instalação do PostgreSQL" \
8 "Criar Banco de Dados" \
9 "Criar Tabela" \
10 "Inserir Dados na Tabela" \
11 "Consultar Dados da Tabela" \
12 "Fazer Backup do Banco de Dados" \
13 "Restaurar Banco de Dados" \
14 "Retornar ao Menu Principal" \
3>&1 1>&2 2>&3 3>&-)
clear
# Verificar se o usuário cancelou
if [ $? -eq 1 ]; então
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 "Opção inválida." 10 30 ;;
esac
done
}
# Mostrar menu de configuração principal
configure_postgresql

View File

@ -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

View File

@ -0,0 +1,230 @@
#!/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) systemctl restart ssh ;;
3) systemctl status ssh ;;
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
apt update
apt install -y openssh-server
systemctl start ssh
systemctl enable ssh
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
systemctl stop ssh
systemctl disable ssh
apt remove -y openssh-server
dialog --msgbox "OpenSSH Server uninstalled." 10 60
}
# Function to view SSH logs
view_ssh_logs() {
dialog --msgbox "$(journalctl -u ssh --no-pager)" 30 80
}
# 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
systemctl restart ssh
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
systemctl restart ssh
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
systemctl restart ssh
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() {
dpkg -l openssh-server >/dev/null 2>&1
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
}
# Execute the main function to configure SSH
configure_ssh

View File

@ -0,0 +1,158 @@
#!/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
cat <<EOF | sudo tee /etc/network/interfaces >/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
# Restart networking service
sudo systemctl restart networking
# Check if configuration applied successfully
if ifconfig $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() {
CURRENT_SETTINGS=$(ip addr show)
dialog --msgbox "Current Network Settings:\n\n$CURRENT_SETTINGS" 20 80
}
# Execute the main function to configure host settings
configure_host

View File

@ -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

View File

@ -0,0 +1,94 @@
#!/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
PACKAGES=("vim"
"nano"
"emacs"
"mcedit"
"joe"
"wget"
"curl"
"lynx"
"htop"
"iftop"
"iotop"
"net-tools"
"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 indices into package names
packages_to_install=()
for index in $selections; do
packages_to_install+=("${PACKAGES[$((index - 1))]}")
done
# Call function to install selected packages
install_selected_packages "${packages_to_install[@]}"
echo "Script completed."

View File

@ -0,0 +1,85 @@
#!/bin/bash
# Directory where the scripts are located
SCRIPT_DIR="/usr/local/bin"
# 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 Docker" \
13 "Exit" \
3>&1 1>&2 2>&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 "$SCRIPT_DIR/configure_ssh.sh" ;;
2) sudo "$SCRIPT_DIR/configure_static_ip.sh" ;;
3) sudo "$SCRIPT_DIR/update_and_install.sh" ;;
4) sudo "$SCRIPT_DIR/configure_firewalld.sh" ;;
5) sudo "$SCRIPT_DIR/configure_hostname.sh" ;;
6) sudo "$SCRIPT_DIR/create_user.sh" ;;
7) sudo "$SCRIPT_DIR/configure_nginx.sh" ;;
8) sudo "$SCRIPT_DIR/configure_apache2.sh" ;;
9) sudo "$SCRIPT_DIR/configure_postfix.sh" ;;
10) sudo "$SCRIPT_DIR/configure_mariadb.sh" ;;
11) sudo "$SCRIPT_DIR/configure_postgresql.sh" ;;
12) sudo "$SCRIPT_DIR/configure_docker.sh" ;;
13) 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. PHP: Configure PHP and related settings.
13. Docker: Configure Docker and manage containers.
14. Exit: Exit the configuration tool.
Please select an option from the menu to begin." 20 60
# Check if user canceled the welcome message
if [[ $? -ne 0 ]]; then
clear
echo "Welcome message closed or canceled. Exiting..."
exit 0
fi
# Display main menu
main_menu

View File

@ -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
<VirtualHost *:80>
ServerAdmin webmaster@$DOMAIN
ServerName $DOMAIN
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 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
<VirtualHost *:80>
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
</VirtualHost>
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,130 @@
#!/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

View File

@ -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

View File

@ -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 <<EOF | sudo tee /etc/network/interfaces >/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 <<EOF | sudo tee /etc/network/interfaces.d/$interface >/dev/null
iface $interface inet static
address $ip_address
netmask $netmask
gateway $gateway
dns-nameservers $dns_server
EOF
rc-service networking restart
;;
"runit")
cat <<EOF | sudo tee /etc/network.d/$interface >/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

View File

@ -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

View File

@ -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."

View File

@ -0,0 +1,81 @@
#!/bin/bash
# Directory where the scripts are located
SCRIPT_DIR="/usr/local/bin"
# 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)
# 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 "$SCRIPT_DIR/configure_ssh.sh" ;;
2) sudo "$SCRIPT_DIR/configure_static_ip.sh" ;;
3) sudo "$SCRIPT_DIR/update_and_install.sh" ;;
4) sudo "$SCRIPT_DIR/configure_firewalld.sh" ;;
5) sudo "$SCRIPT_DIR/configure_hostname.sh" ;;
6) sudo "$SCRIPT_DIR/create_user.sh" ;;
7) sudo "$SCRIPT_DIR/configure_nginx.sh" ;;
8) sudo "$SCRIPT_DIR/configure_apache2.sh" ;;
9) sudo "$SCRIPT_DIR/configure_postfix.sh" ;;
10) sudo "$SCRIPT_DIR/configure_mariadb.sh" ;;
11) sudo "$SCRIPT_DIR/configure_postgresql.sh" ;;
12) sudo "$SCRIPT_DIR/configure_sqlite.sh" ;;
13) sudo "$SCRIPT_DIR/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

View File

@ -8,11 +8,11 @@
# Copy files to the chroot directory
echo "Copying files to chroot..."
cp /preseed/grub/grub /target/etc/default
cp /preseed/grub/grub /cdrom/etc/default
# update grub and initramfs
chroot /target update-initramfs -u
chroot /target update-grub
chroot /cdrom update-initramfs -u
chroot /cdrom update-grub
exit 0

View File

@ -1,12 +0,0 @@
#!/bin/sh -e
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppermintOS Team (peppermintosteam@proton.me)
# This script removes unwanted files after Debian installation.
# Remove unwanted files
chroot /target apt -y remove --autoremove raspi-firmware
rm -r /target/boot/firmware

39
pepscripts/07grub-config Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh -e
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppermintOS Team (peppermintosteam@proton.me)
# This script configures grub defaults after Debian installation.
# Defines the variables
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Peppermint"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_GFXMODE=1360x768
GRUB_THEME="/boot/grub/themes/peppermint/theme.txt"
GRUB_DISABLE_OS_PROBER=false
# GRUB configuration file path
GRUB_CONFIG_FILE="/target/etc/default/grub"
# Modify the GRUB file
sed -i "s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=$GRUB_DEFAULT/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=$GRUB_TIMEOUT/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"$GRUB_DISTRIBUTOR\"/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"$GRUB_CMDLINE_LINUX_DEFAULT\"/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"$GRUB_CMDLINE_LINUX\"/" $GRUB_CONFIG_FILE
sed -i "s/^#GRUB_GFXMODE=.*/GRUB_GFXMODE=$GRUB_GFXMODE/" $GRUB_CONFIG_FILE
# Add GRUB_THEME if it doesn't exist
if ! grep -q "^GRUB_THEME=" $GRUB_CONFIG_FILE; then
echo "GRUB_THEME=\"$GRUB_THEME\"" >> $GRUB_CONFIG_FILE
else
sed -i "s#^GRUB_THEME=.*#GRUB_THEME=\"$GRUB_THEME\"#" $GRUB_CONFIG_FILE
fi
sed -i "s/^#GRUB_DISABLE_OS_PROBER=.*/GRUB_DISABLE_OS_PROBER=$GRUB_DISABLE_OS_PROBER/" $GRUB_CONFIG_FILE
# Run update-grub after modifying the file
chroot /target update-grub

View File

@ -7,8 +7,22 @@
# This script updates the system after Debian installation.
# Update the system
chroot /target apt update
chroot /target apt upgrade -y
if ! chroot /target apt update; then
echo "Failed to update package lists. Aborting." >&2
exit 1
fi
# Upgrade the system
if ! chroot /target apt upgrade -y; then
echo "Failed to upgrade packages. Aborting." >&2
exit 1
fi
# Clean up unnecessary packages
chroot /target apt autoremove -y
if ! chroot /target apt autoremove -y; then
echo "Failed to remove unnecessary packages. Continuing anyway." >&2
fi
echo "System update completed successfully."
exit 0