mirror of
https://github.com/marcogll/scripts_mg.git
synced 2026-01-13 13:25:15 +00:00
Update auto_server_setup.sh
This commit is contained in:
@@ -5,9 +5,29 @@
|
||||
# Samba share • Oh-My-Zsh (plugins + alias)
|
||||
# Utilidades básicas (SSH, net-tools, htop, ufw, fail2ban, avahi)
|
||||
# Visual: barra de progreso con emojis 🚀🛠️
|
||||
# Todo el output se registra en /var/log/auto_server_setup.log
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Logfile setup
|
||||
LOGFILE="/var/log/auto_server_setup.log"
|
||||
mkdir -p "$(dirname "$LOGFILE")"
|
||||
: > "$LOGFILE"
|
||||
exec > >(tee -a "$LOGFILE") 2>&1
|
||||
|
||||
LOG() { echo -e "\033[1;32m▶ $*\033[0m"; }
|
||||
# Check ports function
|
||||
check_ports() {
|
||||
local svc="$1"; shift
|
||||
for port in "$@"; do
|
||||
if ss -tulpn | grep -q ":$port "; then
|
||||
LOG "⚠️ Puertos en uso para $svc (puerto $port), omitiendo $svc"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Barra de progreso estética #
|
||||
##############################################################################
|
||||
@@ -15,26 +35,22 @@ STEPS_TOTAL=17
|
||||
STEP_NOW=0
|
||||
bar() {
|
||||
clear
|
||||
local width=30
|
||||
local filled=$(( STEP_NOW * width / STEPS_TOTAL ))
|
||||
local empty=$(( width - filled ))
|
||||
local gauge
|
||||
local width=30 filled=$(( STEP_NOW * width / STEPS_TOTAL )) empty=$(( width - filled )) gauge
|
||||
gauge="$(printf '%0.s🟩' $(seq 1 $filled))$(printf '%0.s⬜' $(seq 1 $empty))"
|
||||
printf "\n %s %3d%% [ %s ]\n" "$gauge" $(( STEP_NOW * 100 / STEPS_TOTAL )) "$1"
|
||||
}
|
||||
next() { STEP_NOW=$(( STEP_NOW + 1 )); bar "$1"; }
|
||||
LOG() { echo -e "\033[1;32m▶ $*\033[0m"; }
|
||||
|
||||
##############################################################################
|
||||
# 0. Root check #
|
||||
##############################################################################
|
||||
next "🔑 Verificando root"
|
||||
[[ $(id -u) -eq 0 ]] || { echo "⚠️ Run as root or sudo." >&2; exit 1; }
|
||||
|
||||
##############################################################################
|
||||
# 1. Wi-Fi Configuration #
|
||||
##############################################################################
|
||||
next "📶 Wi-Fi"
|
||||
# Detect wireless adapter
|
||||
next "📶 Configuración Wi-Fi"
|
||||
if lspci | grep -i wireless >/dev/null || lsusb | grep -i wireless >/dev/null; then
|
||||
LOG "Adaptador Wi-Fi detectado"
|
||||
apt update && apt install -y wpasupplicant wireless-tools
|
||||
@@ -53,7 +69,6 @@ EOF
|
||||
chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
systemctl enable wpa_supplicant
|
||||
systemctl start wpa_supplicant
|
||||
# Try obtaining IP
|
||||
dhclient -v wlan0 || dhclient -v wlp2s0 || true
|
||||
LOG "Wi-Fi configurado"
|
||||
else
|
||||
@@ -63,32 +78,31 @@ fi
|
||||
##############################################################################
|
||||
# 2. Hardware info (neofetch) #
|
||||
##############################################################################
|
||||
next "📊 Hardware Info"
|
||||
next "📊 Info de hardware"
|
||||
command -v neofetch >/dev/null 2>&1 || apt install -y neofetch
|
||||
clear && neofetch
|
||||
|
||||
##############################################################################
|
||||
# 3. Hostname & local domain #
|
||||
##############################################################################
|
||||
next "🖥️ Hostname & Domain"
|
||||
next "🖥️ Hostname & dominio"
|
||||
DEFAULT_HOST="$(hostname)"
|
||||
read -rp "➤ New hostname [${DEFAULT_HOST}]: " NEW_HOST
|
||||
NEW_HOST="${NEW_HOST:-$DEFAULT_HOST}"
|
||||
echo "$NEW_HOST" >/etc/hostname
|
||||
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEW_HOST/" /etc/hosts || true
|
||||
hostname "$NEW_HOST"
|
||||
|
||||
read -rp "➤ Configure local domain? (e.g., server.local) [Y/n]: " DOM
|
||||
if [[ ${DOM,,} =~ ^y ]]; then
|
||||
read -rp "➤ Domain: " LOCAL_DOMAIN
|
||||
echo "127.0.0.1\t$LOCAL_DOMAIN" >>/etc/hosts
|
||||
LOG "Domain local set: $LOCAL_DOMAIN"
|
||||
LOG "Dominio local configurado: $LOCAL_DOMAIN"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 4. Basic utilities #
|
||||
##############################################################################
|
||||
next "🛠️ Utilities"
|
||||
next "🛠️ Instalando utilidades"
|
||||
apt update && apt -y upgrade
|
||||
apt install -y \
|
||||
openssh-server net-tools htop curl wget gnupg2 ca-certificates lsb-release \
|
||||
@@ -97,67 +111,74 @@ apt install -y \
|
||||
##############################################################################
|
||||
# 5. Docker install & permissions #
|
||||
##############################################################################
|
||||
next "🐳 Docker"
|
||||
next "🐳 Instalando Docker"
|
||||
apt install -y apt-transport-https software-properties-common
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
|
||||
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
|
||||
>/etc/apt/sources.list.d/docker.list
|
||||
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" >/etc/apt/sources.list.d/docker.list
|
||||
apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||
systemctl enable docker && systemctl start docker
|
||||
# Allow docker without sudo
|
||||
groupadd docker || true
|
||||
read -rp "➤ User to add to docker group [${SUDO_USER:-$USER}]: " DU
|
||||
read -rp "➤ User for Docker group [${SUDO_USER:-$USER}]: " DU
|
||||
DOCKER_USER="${DU:-${SUDO_USER:-$USER}}"
|
||||
usermod -aG docker "$DOCKER_USER"
|
||||
|
||||
##############################################################################
|
||||
# 6. Portainer #
|
||||
##############################################################################
|
||||
next "🔧 Portainer"
|
||||
next "🔧 Desplegando Portainer"
|
||||
if check_ports "Portainer" 9443; then
|
||||
docker volume create portainer_data
|
||||
docker run -d --name portainer \
|
||||
--restart=always -p 9443:9443 \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v portainer_data:/data portainer/portainer-ce:latest
|
||||
LOG "Portainer: https://$NEW_HOST:9443"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 7. CapRover #
|
||||
##############################################################################
|
||||
next "🚀 CapRover"
|
||||
next "🚀 Desplegando CapRover"
|
||||
if check_ports "CapRover" 80 443 3000; then
|
||||
docker run -d --name caprover --restart=always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /captain:/captain \
|
||||
-p 80:80 -p 443:443 -p 3000:3000 caprover/caprover:latest
|
||||
LOG "CapRover: http://$NEW_HOST:3000"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 8. Nginx Proxy Manager #
|
||||
##############################################################################
|
||||
next "🌐 NPM"
|
||||
next "🌐 Desplegando NPM"
|
||||
if check_ports "Nginx Proxy Manager" 80 443 81; then
|
||||
docker run -d --name nginx-proxy-manager --restart=unless-stopped \
|
||||
-p 80:80 -p 443:443 -p 81:81 \
|
||||
-v /opt/npm/data:/data \
|
||||
-v /opt/npm/letsencrypt:/etc/letsencrypt \
|
||||
jc21/nginx-proxy-manager:latest
|
||||
LOG "Nginx Proxy Manager: http://$NEW_HOST:81"
|
||||
LOG "NPM: http://$NEW_HOST:81"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 9. Plex #
|
||||
##############################################################################
|
||||
next "🎞️ Plex"
|
||||
next "🎞️ Desplegando Plex"
|
||||
if check_ports "Plex" 32400; then
|
||||
docker run -d --name plex --restart=unless-stopped \
|
||||
--network=host \
|
||||
-e TZ="America/Monterrey" \
|
||||
-v /srv/plex/config:/config \
|
||||
-v /srv/plex/media:/data plexinc/pms-docker:latest
|
||||
LOG "Plex: http://$NEW_HOST:32400/web"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 10. Pi-hole #
|
||||
##############################################################################
|
||||
next "🚫 Pi-hole"
|
||||
next "🚫 Desplegando Pi-hole"
|
||||
if check_ports "Pi-hole DNS" 53 && check_ports "Pi-hole UI" 8080; then
|
||||
docker run -d --name pihole --restart=unless-stopped \
|
||||
-p 53:53/tcp -p 53:53/udp -p 8080:80 \
|
||||
-e TZ="America/Monterrey" \
|
||||
@@ -165,18 +186,23 @@ docker run -d --name pihole --restart=unless-stopped \
|
||||
-v /opt/pihole/etc-pihole:/etc/pihole \
|
||||
-v /opt/pihole/etc-dnsmasq.d:/etc/dnsmasq.d pihole/pihole:latest
|
||||
LOG "Pi-hole: http://$NEW_HOST:8080"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 11. CasaOS #
|
||||
##############################################################################
|
||||
next "🏠 CasaOS"
|
||||
next "🏠 Instalando CasaOS"
|
||||
if check_ports "CasaOS" 80 443; then
|
||||
curl -fsSL https://get.casaos.io | bash
|
||||
LOG "CasaOS: http://$NEW_HOST"
|
||||
else
|
||||
LOG "Salteando CasaOS: puertos 80/443 en uso"
|
||||
fi
|
||||
|
||||
##############################################################################
|
||||
# 12. Samba share #
|
||||
##############################################################################
|
||||
next "📁 Samba"
|
||||
next "📁 Configurando Samba"
|
||||
read -rp "➤ Folder to share (full path): " SMB_DIR
|
||||
mkdir -p "$SMB_DIR"
|
||||
read -rp "➤ Samba user: " SMB_USER
|
||||
@@ -197,7 +223,7 @@ LOG "Samba share: //$NEW_HOST/$SMB_USER"
|
||||
##############################################################################
|
||||
# 13. Oh My Zsh + plugins + alias #
|
||||
##############################################################################
|
||||
next "💎 Oh My Zsh"
|
||||
next "💎 Configurando Oh My Zsh"
|
||||
apt install -y zsh git
|
||||
sudo -u "$DOCKER_USER" sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
||||
chsh -s $(which zsh) "$DOCKER_USER"
|
||||
@@ -211,14 +237,14 @@ LOG "Oh My Zsh configured for $DOCKER_USER"
|
||||
##############################################################################
|
||||
# 14. Firewall & Fail2Ban #
|
||||
##############################################################################
|
||||
next "🛡️ Firewall"
|
||||
next "🛡️ Configurando Firewall"
|
||||
ufw allow OpenSSH && ufw allow 81 && ufw allow 3000 && ufw allow 32400 && ufw allow 8080 && ufw --force enable
|
||||
systemctl enable fail2ban && systemctl start fail2ban
|
||||
|
||||
##############################################################################
|
||||
# 15. Final summary #
|
||||
##############################################################################
|
||||
next "✅ Summary"
|
||||
next "✅ Resumen"
|
||||
echo
|
||||
LOG "Access your services:"
|
||||
echo " - Portainer → https://$NEW_HOST:9443"
|
||||
|
||||
Reference in New Issue
Block a user