Update auto_server_setup.sh

This commit is contained in:
Marco Gallegos
2025-05-02 12:23:26 -06:00
committed by GitHub
parent 40d6026687
commit 8dbe4f00cb

View File

@@ -1,41 +1,41 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# auto_server_setup_emoji.sh — 2025-05-02 # auto_server_setup_emoji_top.sh — 2025-05-02
# Home-server Ubuntu 22.04/24.04 con Docker, Portainer, ZeroTier, Tailscale, # Home-server Ubuntu 22.04/24.04 con Docker, Portainer, ZeroTier, Tailscale,
# Plex, Samba, Oh-My-Zsh + plugins, Oh-My-Posh (clean-detailed) + Meslo Nerd Font. # Plex, Samba, Oh-My-Zsh (+plugins y alias), Oh-My-Posh (clean-detailed) + Meslo Nerd Font.
# Incluye barra de progreso con emojis. 🚀🛠️ # Barra de progreso con emojis FLOTANTE en la parte superior. 🚀🛠️
set -euo pipefail set -euo pipefail
################################################################################ ##############################################################################
# Barra de progreso con emojis # # Barra de progreso «pegada» arriba #
################################################################################ ##############################################################################
STEPS_TOTAL=12 # actualiza si cambias el número de “next” STEPS_TOTAL=12 # actualiza si añades/elimina pasos
STEP_NOW=0 STEP_NOW=0
bar() { bar() {
local width=20 clear # mantiene la barra en la línea 1
local filled=$(( STEP_NOW*width/STEPS_TOTAL )) local w=20
local empty=$(( width-filled )) local f=$(( STEP_NOW*w/STEPS_TOTAL ))
local bar local e=$(( w-f ))
bar="$(printf '%0.s🟩' $(seq 1 $filled))" local progress
bar+="$(printf '%0.s' $(seq 1 $empty))" progress="$(printf '%0.s🟩' $(seq 1 $f))"
progress+="$(printf '%0.s⬜' $(seq 1 $e))"
local pct=$(( STEP_NOW*100/STEPS_TOTAL )) local pct=$(( STEP_NOW*100/STEPS_TOTAL ))
printf "\r%s %3d%% %s\n" "$bar" "$pct" "$1" printf "%s %3d%% %s\n\n" "$progress" "$pct" "$1"
} }
next() { STEP_NOW=$(( STEP_NOW+1 )); bar "$1"; } next() { STEP_NOW=$(( STEP_NOW+1 )); bar "$1"; }
LOG() { echo -e "\n\033[1;32m▶ $*\033[0m"; } LOG() { echo -e "\033[1;32m▶ $*\033[0m"; }
################################################################################ ##############################################################################
# Comprobación de root # # Comprobación de root #
################################################################################ ##############################################################################
if [[ "$(id -u)" -ne 0 ]]; then if [[ "$(id -u)" -ne 0 ]]; then
echo "⚠️ Ejecuta este script con sudo o como root." >&2 echo "⚠️ Ejecuta este script con sudo o como root." >&2
exit 1 exit 1
fi fi
################################################################################ ##############################################################################
# 0. Hostname # # 0. Hostname #
################################################################################ ##############################################################################
next "🖥️ Configurando hostname" next "🖥️ Configurando hostname"
read -rp "➤ Nuevo hostname: " NEW_HOST read -rp "➤ Nuevo hostname: " NEW_HOST
if [[ -n "$NEW_HOST" ]]; then if [[ -n "$NEW_HOST" ]]; then
@@ -44,9 +44,9 @@ if [[ -n "$NEW_HOST" ]]; then
hostname "$NEW_HOST" hostname "$NEW_HOST"
fi fi
################################################################################ ##############################################################################
# 1. Preguntas iniciales # # 1. Preguntas iniciales #
################################################################################ ##############################################################################
next "❓ Preguntas iniciales" next "❓ Preguntas iniciales"
DEFAULT_USER="${SUDO_USER:-$USER}" DEFAULT_USER="${SUDO_USER:-$USER}"
read -rp "➤ Usuario Linux a configurar [$DEFAULT_USER]: " TMP read -rp "➤ Usuario Linux a configurar [$DEFAULT_USER]: " TMP
@@ -61,9 +61,9 @@ INSTALL_CASAOS="$( [[ ${cas,,} =~ ^n ]] && echo no || echo yes )"
read -rp "➤ Reinicio automático al final? [Y/n]: " reb read -rp "➤ Reinicio automático al final? [Y/n]: " reb
AUTO_REBOOT="$( [[ ${reb,,} =~ ^n ]] && echo no || echo yes )" AUTO_REBOOT="$( [[ ${reb,,} =~ ^n ]] && echo no || echo yes )"
################################################################################ ##############################################################################
# 2. Paquetes base + Zsh + plugins + alias # # 2. Paquetes base + Zsh + plugins + alias #
################################################################################ ##############################################################################
next "📦 Instalando paquetes base" next "📦 Instalando paquetes base"
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
apt update && apt -y full-upgrade apt update && apt -y full-upgrade
@@ -71,7 +71,7 @@ apt install -y git curl gnupg lsb-release nano build-essential \
ca-certificates software-properties-common \ ca-certificates software-properties-common \
apt-transport-https zsh fzf btop ufw unzip whiptail apt-transport-https zsh fzf btop ufw unzip whiptail
next "💎 Oh-My-Zsh + plugins" next "💎 Oh-My-Zsh + plugins/alias"
sudo -u "$SERVER_USER" sh -c \ sudo -u "$SERVER_USER" sh -c \
'curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash -s -- --unattended' 'curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash -s -- --unattended'
@@ -82,7 +82,6 @@ sudo -u "$SERVER_USER" git clone --depth=1 https://github.com/zsh-users/zsh-synt
ZSHRC="/home/$SERVER_USER/.zshrc" ZSHRC="/home/$SERVER_USER/.zshrc"
sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting colorize)/' "$ZSHRC" sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting colorize)/' "$ZSHRC"
grep -qxF "alias cls='clear'" "$ZSHRC" || cat >> "$ZSHRC" <<'EOF' grep -qxF "alias cls='clear'" "$ZSHRC" || cat >> "$ZSHRC" <<'EOF'
# --- Custom aliases --- # --- Custom aliases ---
@@ -91,16 +90,15 @@ alias clima='curl wttr.in/Saltillo'
alias pip='pip3' alias pip='pip3'
export PATH=$HOME/.local/bin:$HOME/.npm-global/bin:$PATH export PATH=$HOME/.local/bin:$HOME/.npm-global/bin:$PATH
EOF EOF
chsh -s "$(command -v zsh)" "$SERVER_USER" chsh -s "$(command -v zsh)" "$SERVER_USER"
################################################################################ ##############################################################################
# 3. Oh-My-Posh + Meslo Nerd Font # # 3. Oh-My-Posh + Meslo Nerd Font #
################################################################################ ##############################################################################
next "🎨 Oh-My-Posh + Meslo" next "🎨 Oh-My-Posh + Meslo"
curl -fsSL https://ohmyposh.dev/install.sh | bash -s -- -d /usr/local/bin curl -fsSL https://ohmyposh.dev/install.sh | bash -s -- -d /usr/local/bin
# Instalar la fuente Meslo Nerd Font (system-wide al correr como root) # Instala la fuente Meslo Nerd Font (system-wide al ser root)
oh-my-posh font install meslo oh-my-posh font install meslo
fc-cache -f fc-cache -f
@@ -112,19 +110,19 @@ chmod 644 "/home/$SERVER_USER/.poshthemes/clean-detailed.omp.json"
OMP_LINE='eval "$(oh-my-posh init zsh --config ~/.poshthemes/clean-detailed.omp.json)"' OMP_LINE='eval "$(oh-my-posh init zsh --config ~/.poshthemes/clean-detailed.omp.json)"'
grep -qxF "$OMP_LINE" "$ZSHRC" || echo "$OMP_LINE" >> "$ZSHRC" grep -qxF "$OMP_LINE" "$ZSHRC" || echo "$OMP_LINE" >> "$ZSHRC"
################################################################################ ##############################################################################
# 4. Certbot # # 4. Certbot #
################################################################################ ##############################################################################
next "🔐 Certbot" next "🔐 Certbot"
snap install core --classic >/dev/null || true snap install core --classic >/dev/null || true
snap refresh core snap refresh core
snap install --classic certbot snap install --classic certbot
ln -sf /snap/bin/certbot /usr/bin/certbot ln -sf /snap/bin/certbot /usr/bin/certbot
################################################################################ ##############################################################################
# 5. Docker + Portainer + ZeroTier + Tailscale # # 5. Docker + Portainer + ZeroTier + Tailscale #
################################################################################ ##############################################################################
next "🐳 Docker & friends" next "🐳 Docker, Portainer, ZeroTier, Tailscale"
install -m0755 -d /etc/apt/keyrings install -m0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
source /etc/os-release source /etc/os-release
@@ -147,35 +145,35 @@ curl -s https://install.zerotier.com | bash
curl -fsSL https://tailscale.com/install.sh | sh curl -fsSL https://tailscale.com/install.sh | sh
tailscale up --ssh --accept-dns=false || true tailscale up --ssh --accept-dns=false || true
################################################################################ ##############################################################################
# 6. CasaOS (opcional) # # 6. CasaOS (opcional) #
################################################################################ ##############################################################################
if [[ "$INSTALL_CASAOS" == "yes" ]]; then if [[ "$INSTALL_CASAOS" == "yes" ]]; then
next "🏠 CasaOS" next "🏠 CasaOS"
curl -fsSL https://get.casaos.io | bash curl -fsSL https://get.casaos.io | bash
fi fi
################################################################################ ##############################################################################
# 7. Pi-hole (opcional) # # 7. Pi-hole (opcional) #
################################################################################ ##############################################################################
if [[ "$INSTALL_PIHOLE" == "yes" ]]; then if [[ "$INSTALL_PIHOLE" == "yes" ]]; then
next "🚫 Pi-hole" next "🚫 Pi-hole"
export PIHOLE_SKIP_OS_CHECK=true export PIHOLE_SKIP_OS_CHECK=true
curl -sSL https://install.pi-hole.net | bash -s -- --unattended curl -sSL https://install.pi-hole.net | bash -s -- --unattended
fi fi
################################################################################ ##############################################################################
# 8. Plex Media Server # # 8. Plex Media Server #
################################################################################ ##############################################################################
next "🎞️ Plex" next "🎞️ Plex"
curl -fsSL https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/plex.gpg curl -fsSL https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/plex.gpg
echo "deb [signed-by=/etc/apt/trusted.gpg.d/plex.gpg] https://downloads.plex.tv/repo/deb/ public main" \ echo "deb [signed-by=/etc/apt/trusted.gpg.d/plex.gpg] https://downloads.plex.tv/repo/deb/ public main" \
> /etc/apt/sources.list.d/plexmediaserver.list > /etc/apt/sources.list.d/plexmediaserver.list
apt update && apt install -y plexmediaserver apt update && apt install -y plexmediaserver
################################################################################ ##############################################################################
# 9. Samba # # 9. Samba #
################################################################################ ##############################################################################
next "📁 Samba" next "📁 Samba"
apt install -y samba apt install -y samba
read -rp "➤ Carpeta a compartir (ruta completa): " SAMBA_DIR read -rp "➤ Carpeta a compartir (ruta completa): " SAMBA_DIR
@@ -196,17 +194,17 @@ cat >> /etc/samba/smb.conf <<EOF
EOF EOF
systemctl restart smbd nmbd systemctl restart smbd nmbd
################################################################################ ##############################################################################
# 10. Resumen final # # 10. Resumen final #
################################################################################ ##############################################################################
next "✅ Resumen" next "✅ Resumen"
echo -e "\n🔑 Accesos principales:" echo -e "🔑 Accesos:"
echo " • Portainer → https://$NEW_HOST:9443" echo " • Portainer → https://$NEW_HOST:9443"
echo " • Plex → http://$NEW_HOST:32400/web" echo " • Plex → http://$NEW_HOST:32400/web"
[[ "$INSTALL_PIHOLE" == "yes" ]] && echo " • Pi-hole → http://$NEW_HOST/admin" [[ "$INSTALL_PIHOLE" == "yes" ]] && echo " • Pi-hole → http://$NEW_HOST/admin"
[[ "$INSTALL_CASAOS" == "yes" ]] && echo " • CasaOS → http://$NEW_HOST" [[ "$INSTALL_CASAOS" == "yes" ]] && echo " • CasaOS → http://$NEW_HOST"
echo " • Samba path → $SAMBA_DIR (usuario: $SAMBA_USER)" echo " • Samba path → $SAMBA_DIR (usuario: $SAMBA_USER)"
echo -e "\n⚠ Selecciona la fuente «MesloLGS NF» en tu terminal local para ver Oh-My-Posh." echo -e "\n⚠ Selecciona la fuente «MesloLGS NF» en tu terminal para ver Oh-My-Posh."
if [[ "$AUTO_REBOOT" == "yes" ]]; then if [[ "$AUTO_REBOOT" == "yes" ]]; then
echo -e "\n🔄 Reiniciando en 10 s… (Ctrl-C para abortar)" echo -e "\n🔄 Reiniciando en 10 s… (Ctrl-C para abortar)"