PLEX + Opening ports installation
Choose your system:
Variants:
Install/Uninstall script (Clean /
Warning: Undefined array key "
Deprecated: htmlspecialchars(): Passing null to parameter " in /var/www/scripts/PHP_HTML/maininstall.php on line 49
Warning: Trying to access array offset on null in /var/www/scripts/PHP_HTML/maininstall.php on line 49
Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/scripts/PHP_HTML/maininstall.php on line 49
)
#!/bin/bash
# Nginx Management - Multi-Distro Edition with Progress Bar and Improved UI/UX
# Author: ChatGPT (improved version)
# Date: 2025
# Requirements: dialog, systemctl, tar
set -euo pipefail
# --- CONFIGURATION ---
NGINX_SERVICE="nginx"
BACKUP_DIR="/root/nginx_backups"
LOG_FILE="/var/log/nginx/error.log"
SCRIPT_NAME="$(basename "$0")"
LANG=C.UTF-8 # Ensure UTF-8 for dialog
# --- DISTRIBUTION DETECTION ---
detect_distro() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
DISTRO=$ID
VERSION_ID=$VERSION_ID
else
DISTRO="unknown"
VERSION_ID="unknown"
fi
}
# --- PACKAGE MANAGER DETECTION ---
detect_package_manager() {
if command -v yum &> /dev/null; then
PKG_MANAGER="yum"
elif command -v apt-get &> /dev/null; then
PKG_MANAGER="apt"
else
PKG_MANAGER="unknown"
fi
}
# --- UTILITY FUNCTIONS ---
check_root() {
if [[ $EUID -ne 0 ]]; then
dialog --title "Błąd" --msgbox "🚫 Proszę uruchomić skrypt jako root!" 7 50
exit 1
fi
}
install_dialog_if_missing() {
if ! command -v dialog &> /dev/null; then
echo "Instaluję dialog..."
if [[ $PKG_MANAGER == "yum" ]]; then
yum install -y dialog
elif [[ $PKG_MANAGER == "apt" ]]; then
apt-get update
apt-get install -y dialog
else
echo "Nieobsługiwany menedżer pakietów, proszę zainstalować 'dialog' ręcznie."
exit 1
fi
fi
}
show_msg() {
local title="$1"
local msg="$2"
dialog --title "$title" --msgbox "$msg" 12 60
}
# --- PROGRESS BAR HELPERS ---
progress_bar() {
# args: 1-desc text, rest commands to run sequentially
local desc="$1"
shift
local commands=("$@")
{
echo "0"
echo "$desc"
local i=0
local steps=${#commands[@]}
for cmd in "${commands[@]}"; do
eval "$cmd"
i=$((i + 1))
local percent=$((i * 100 / steps))
echo "$percent"
echo "$desc"
done
} | dialog --title "Progres" --gauge "$desc" 10 70 0
}
# --- NGINX FUNCTIONS ---
install_nginx() {
progress_bar "🔧 Instalacja Nginx..." \
"if [[ $PKG_MANAGER == 'yum' ]]; then yum install -y nginx; elif [[ $PKG_MANAGER == 'apt' ]]; then apt-get update; apt-get install -y nginx; else exit 1; fi" \
"systemctl enable $NGINX_SERVICE" \
"systemctl start $NGINX_SERVICE"
show_msg "Nginx" "✅ Nginx został zainstalowany i uruchomiony."
}
uninstall_nginx() {
dialog --yesno "⚠️ Czy na pewno chcesz odinstalować Nginx?\nTwoje pliki konfiguracyjne pozostaną." 8 60
if [[ $? -eq 0 ]]; then
progress_bar "🗑️ Odinstalowywanie Nginx..." \
"systemctl stop $NGINX_SERVICE || true" \
"if [[ $PKG_MANAGER == 'yum' ]]; then yum remove -y nginx; elif [[ $PKG_MANAGER == 'apt' ]]; then apt-get remove -y nginx; fi"
show_msg "Nginx" "✅ Nginx został odinstalowany."
else
show_msg "Nginx" "❌ Odinstalowanie anulowane."
fi
}
start_nginx() {
progress_bar "▶️ Uruchamianie Nginx..." "systemctl start $NGINX_SERVICE"
show_msg "Nginx" "✅ Nginx został uruchomiony."
}
stop_nginx() {
progress_bar "⏸️ Zatrzymywanie Nginx..." "systemctl stop $NGINX_SERVICE"
show_msg "Nginx" "✅ Nginx został zatrzymany."
}
restart_nginx() {
progress_bar "🔄 Restartowanie Nginx..." "systemctl restart $NGINX_SERVICE"
show_msg "Nginx" "✅ Nginx został zrestartowany."
}
status_nginx() {
if systemctl is-active --quiet "$NGINX_SERVICE"; then
local status="✅ uruchomiony"
else
local status="❌ zatrzymany"
fi
show_msg "Status Nginx" "Nginx jest $status."
}
backup_nginx() {
mkdir -p "$BACKUP_DIR"
TS=$(date +%F_%H-%M-%S)
TARGET="$BACKUP_DIR/nginx_backup_$TS.tar.gz"
progress_bar "💾 Tworzenie backupu konfiguracji..." \
"sleep 1" \
"tar czf \"$TARGET\" /etc/nginx 2>/dev/null" \
"chmod 600 \"$TARGET\""
show_msg "Backup" "✅ Backup został utworzony:\n$TARGET"
}
restore_nginx() {
FILE=$(dialog --stdout --title "Wybierz plik backupu" --fselect "$BACKUP_DIR/" 15 70)
if [[ -f "$FILE" ]]; then
dialog --yesno "⚠️ Przywrócić backup z pliku:\n$FILE ?" 8 60
if [[ $? -eq 0 ]]; then
progress_bar "🔄 Przywracanie backupu..." \
"systemctl stop $NGINX_SERVICE || true" \
"tar xzf \"$FILE\" -C /" \
"systemctl start $NGINX_SERVICE"
show_msg "Restore" "✅ Backup został przywrócony z:\n$FILE"
else
show_msg "Restore" "❌ Przywracanie anulowane."
fi
else
show_msg "Restore" "❌ Nie wybrano pliku backupu!"
fi
}
show_logs() {
if [[ -f "$LOG_FILE" ]]; then
dialog --title "📄 Logi błędów Nginx" --textbox "$LOG_FILE" 20 80
else
show_msg "Logi" "⚠️ Plik z logami nie istnieje."
fi
}
show_about() {
dialog --title "ℹ️ O programie" --msgbox "Nginx Management Script\nAutor: ChatGPT\nWersja: 2025\nSkrypt zarządza instalacją, startem, backupem i logami Nginx.\n\nWymagania:\ndialog, systemctl, tar\n\n© 2025" 12 60
}
# --- MAIN MENU ---
main_menu() {
detect_distro
detect_package_manager
check_root
install_dialog_if_missing
while true; do
CHOICE=$(dialog --clear \
--backtitle "Zarządzanie Nginx - $DISTRO $VERSION_ID" \
--title "Menu główne" \
--menu "Wybierz opcję:" 20 70 12 \
1 "🌐 Zainstaluj Nginx" \
2 "🗑️ Odinstaluj Nginx" \
3 "▶️ Uruchom Nginx" \
4 "⏸️ Zatrzymaj Nginx" \
5 "🔄 Restartuj Nginx" \
6 "📊 Sprawdź status Nginx" \
7 "💾 Backup konfiguracji" \
8 "🔄 Przywróć konfigurację" \
9 "📄 Pokaż logi błędów" \
10 "ℹ️ O programie" \
11 "❌ Wyjdź" \
3>&1 1>&2 2>&3)
case $CHOICE in
1) install_nginx ;;
2) uninstall_nginx ;;
3) start_nginx ;;
4) stop_nginx ;;
5) restart_nginx ;;
6) status_nginx ;;
7) backup_nginx ;;
8) restore_nginx ;;
9) show_logs ;;
10) show_about ;;
11) clear; exit 0 ;;
*) break ;;
esac
done
}
# --- SCRIPT ENTRY POINT ---
main_menu
Use the following command to auto-download and run:
Warning: Undefined array key "
Deprecated: htmlspecialchars(): Passing null to parameter " in /var/www/scripts/PHP_HTML/autoscripts.php on line 87
Warning: Trying to access array offset on null in /var/www/scripts/PHP_HTML/autoscripts.php on line 87
curl -fsSL -o script.sh "https://krotek.serveblog.net/how-to-install/MEDIA-SERVER/PLEX/scripts.php?variant=clean&type=script&system=%3Cbr+%2F%3E%3Cb%3EDeprecated%3C%2Fb%3E%3A++htmlspecialchars%28%29%3A+Passing+null+to+parameter+" && chmod +x script.sh && sudo ./script.sh