Update auto_server_setup.sh

This commit is contained in:
Marco Gallegos
2025-05-02 12:45:12 -06:00
committed by GitHub
parent 50dec4a992
commit e1002949ed

View File

@@ -1,24 +1,25 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# auto_server_setup_emoji_top.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, # Ubuntu 22.04 / 24.04 “home-server” all-in-one:
# Plex, Samba, Oh-My-Zsh (plugins + alias) y Oh-My-Posh (tema clean-detailed) # Docker + Portainer + ZeroTier + Tailscale • Plex • Pi-hole • CasaOS
# + Meslo Nerd Font. Barra de progreso con emojis anclada arriba. 🚀🛠️ # Samba share • Oh-My-Zsh (plugins + alias) • Oh-My-Posh + Meslo Nerd Font
# Barra de progreso con emojis anclada arriba. 🚀🛠️
set -euo pipefail set -euo pipefail
############################################################################## ##############################################################################
# Barra de progreso «pegada» # # Barra de progreso anclada #
############################################################################## ##############################################################################
STEPS_TOTAL=12 STEPS_TOTAL=12 # ¡actualiza si añades/eliminas “next”!
STEP_NOW=0 STEP_NOW=0
bar() { bar() {
clear clear
local width=20 # ancho de la barra local width=20
local filled=$(( STEP_NOW*width / STEPS_TOTAL )) local filled=$(( STEP_NOW*width / STEPS_TOTAL ))
local empty=$(( width - filled )) local empty=$(( width - filled ))
local line local gauge
line="$(printf '%0.s🟩' $(seq 1 $filled))$(printf '%0.s⬜' $(seq 1 $empty))" gauge="$(printf '%0.s🟩' $(seq 1 $filled))$(printf '%0.s⬜' $(seq 1 $empty))"
printf "%s %3d%% %s\n\n" "$line" $(( STEP_NOW*100/STEPS_TOTAL )) "$1" printf "%s %3d%% %s\n\n" "$gauge" $(( STEP_NOW*100 / STEPS_TOTAL )) "$1"
} }
next() { STEP_NOW=$(( STEP_NOW + 1 )); bar "$1"; } next() { STEP_NOW=$(( STEP_NOW + 1 )); bar "$1"; }
LOG() { echo -e "\033[1;32m▶ $*\033[0m"; } LOG() { echo -e "\033[1;32m▶ $*\033[0m"; }
@@ -26,7 +27,7 @@ LOG() { echo -e "\033[1;32m▶ $*\033[0m"; }
############################################################################## ##############################################################################
# Comprobación de root # # Comprobación de root #
############################################################################## ##############################################################################
[[ $(id -u) -eq 0 ]] || { echo "⚠️ Ejecuta con sudo o como root." >&2; exit 1; } [[ $(id -u) -eq 0 ]] || { echo "⚠️ Ejecútame con sudo o como root." >&2; exit 1; }
############################################################################## ##############################################################################
# 0. Hostname # # 0. Hostname #
@@ -44,49 +45,48 @@ hostname "$NEW_HOST"
############################################################################## ##############################################################################
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; SERVER_USER="${tmp:-$DEFAULT_USER}" read -rp "➤ Usuario Linux a configurar [$DEFAULT_USER]: " u
read -rp "➤ Instalar Pi-hole? [Y/n]: " p; INSTALL_PIHOLE="$( [[ ${p,,} =~ ^n ]] && echo no || echo yes )" SERVER_USER="${u:-$DEFAULT_USER}"
read -rp "➤ Instalar CasaOS? [Y/n]: " c; INSTALL_CASAOS="$( [[ ${c,,} =~ ^n ]] && echo no || echo yes )" read -rp "➤ Instalar Pi-hole? [Y/n]: " p
read -rp "➤ Reinicio automático al final? [Y/n]: " r; AUTO_REBOOT="$( [[ ${r,,} =~ ^n ]] && echo no || echo yes )" INSTALL_PIHOLE="$( [[ ${p,,} =~ ^n ]] && echo no || echo yes )"
read -rp "➤ Instalar CasaOS? [Y/n]: " c
INSTALL_CASAOS="$( [[ ${c,,} =~ ^n ]] && echo no || echo yes )"
read -rp "➤ Reinicio automático al final? [Y/n]: " r
AUTO_REBOOT="$( [[ ${r,,} =~ ^n ]] && echo no || echo yes )"
############################################################################## ##############################################################################
# 2. Paquetes base (lista con descripción) # # 2. Paquetes base (lista + descripción) #
############################################################################## ##############################################################################
next "📦 Instalando paquetes base" next "📦 Instalando paquetes base"
declare -A BASE_PKGS=( declare -A PKG_DESC=(
[git]="control de versiones" [git]="control de versiones" [curl]="cliente HTTP(S)"
[curl]="cliente HTTP(S)" [gnupg]="cifrado/Firmas GPG" [lsb-release]="info de la distro"
[gnupg]="cifrado/Firmas GPG" [nano]="editor de texto" [build-essential]="compilación C/C++"
[lsb-release]="info versión Ubuntu" [ca-certificates]="certificados SSL" [software-properties-common]="PPAs"
[nano]="editor de texto" [apt-transport-https]="APT sobre HTTPS" [fontconfig]="caché fuentes (fc-cache)"
[build-essential]="herramientas de compilación" [zsh]="shell Zsh" [fzf]="búsqueda fuzzy"
[ca-certificates]="certificados SSL" [btop]="monitor de recursos" [ufw]="firewall sencillo"
[software-properties-common]="gestión de repositorios" [unzip]="descompresor ZIP" [whiptail]="menús en shell"
[apt-transport-https]="APT vía HTTPS"
[fontconfig]="caché de fuentes (fc-cache)"
[zsh]="shell Zsh"
[fzf]="búsqueda fuzzy"
[btop]="monitor recursos"
[ufw]="firewall sencillo"
[unzip]="descompresor ZIP"
[whiptail]="menús shell"
) )
echo "• Se instalarán:" echo "• Se instalarán:"
for pkg in "${!BASE_PKGS[@]}"; do printf " - %-15s %s\n" "$pkg" "${BASE_PKGS[$pkg]}"; done for p in "${!PKG_DESC[@]}"; do printf " - %-18s %s\n" "$p" "${PKG_DESC[$p]}"; done
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
apt update && apt -y full-upgrade apt update && apt -y full-upgrade
apt install -y "${!BASE_PKGS[@]}" apt install -y "${!PKG_DESC[@]}"
############################################################################## ##############################################################################
# 3. Oh-My-Zsh + plugins + alias # # 3. Oh-My-Zsh + plugins + alias #
############################################################################## ##############################################################################
next "💎 Oh-My-Zsh + plugins/alias" next "💎 Oh-My-Zsh + plugins/alias"
sudo -u "$SERVER_USER" bash -c \ sudo -u "$SERVER_USER" bash -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'
sudo -u "$SERVER_USER" git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions \ sudo -u "$SERVER_USER" git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions \
"/home/$SERVER_USER/.oh-my-zsh/custom/plugins/zsh-autosuggestions" "/home/$SERVER_USER/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
sudo -u "$SERVER_USER" git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting \ sudo -u "$SERVER_USER" git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting \
"/home/$SERVER_USER/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" "/home/$SERVER_USER/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
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'
@@ -100,15 +100,18 @@ EOF
chsh -s "$(command -v zsh)" "$SERVER_USER" chsh -s "$(command -v zsh)" "$SERVER_USER"
############################################################################## ##############################################################################
# 4. Oh-My-Posh + Meslo Nerd Font (manual) # # 4. 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
# Font manual (evita bug BubbleTea)
TMPF=$(mktemp -d) TMPF=$(mktemp -d)
curl -fsSL https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip -o "$TMPF/meslo.zip" curl -fsSL https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip -o "$TMPF/meslo.zip"
unzip -q "$TMPF/meslo.zip" -d "$TMPF" unzip -q "$TMPF/meslo.zip" -d "$TMPF"
mkdir -p /usr/local/share/fonts && cp "$TMPF"/*.ttf /usr/local/share/fonts/ mkdir -p /usr/local/share/fonts && cp "$TMPF"/*.ttf /usr/local/share/fonts/
fc-cache -f && rm -rf "$TMPF" fc-cache -f && rm -rf "$TMPF"
sudo -u "$SERVER_USER" mkdir -p "/home/$SERVER_USER/.poshthemes" sudo -u "$SERVER_USER" mkdir -p "/home/$SERVER_USER/.poshthemes"
curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/clean-detailed.omp.json \ curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/clean-detailed.omp.json \
-o "/home/$SERVER_USER/.poshthemes/clean-detailed.omp.json" -o "/home/$SERVER_USER/.poshthemes/clean-detailed.omp.json"
@@ -136,10 +139,12 @@ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.
https://download.docker.com/linux/ubuntu $VERSION_CODENAME stable" >/etc/apt/sources.list.d/docker.list https://download.docker.com/linux/ubuntu $VERSION_CODENAME stable" >/etc/apt/sources.list.d/docker.list
apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
usermod -aG docker "$SERVER_USER" usermod -aG docker "$SERVER_USER"
docker volume create portainer_data docker volume create portainer_data
docker run -d --name portainer -p 8000:8000 -p 9443:9443 --restart=always \ docker run -d --name portainer -p 8000:8000 -p 9443:9443 --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data \ -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data \
portainer/portainer-ce:latest portainer/portainer-ce:latest
curl -s https://install.zerotier.com | bash 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
@@ -147,19 +152,35 @@ tailscale up --ssh --accept-dns=false || true
############################################################################## ##############################################################################
# 7. CasaOS (opcional) # # 7. CasaOS (opcional) #
############################################################################## ##############################################################################
[[ $INSTALL_CASAOS == yes ]] && { next "🏠 CasaOS"; curl -fsSL https://get.casaos.io | bash; } if [[ $INSTALL_CASAOS == yes ]]; then
next "🏠 CasaOS"
# instalar sin docker (ya presente) e ignorar errores no críticos
curl -fsSL https://get.casaos.io | bash -s -- --without-docker || true
# parche rápido si falta binario de app-management
if ! command -v casaos-app-management &>/dev/null && \
[ -f /opt/casaos/bin/casaos-app-management ]; then
ln -s /opt/casaos/bin/casaos-app-management /usr/bin/casaos-app-management
systemctl restart casaos-app-management.service || true
fi
fi
############################################################################## ##############################################################################
# 8. Pi-hole (opcional) # # 8. Pi-hole (opcional) #
############################################################################## ##############################################################################
[[ $INSTALL_PIHOLE == yes ]] && { next "🚫 Pi-hole"; export PIHOLE_SKIP_OS_CHECK=true; curl -sSL https://install.pi-hole.net | bash -s -- --unattended; } if [[ $INSTALL_PIHOLE == yes ]]; then
next "🚫 Pi-hole"
export PIHOLE_SKIP_OS_CHECK=true
curl -sSL https://install.pi-hole.net | bash -s -- --unattended
fi
############################################################################## ##############################################################################
# 9. Plex Media Server # # 9. 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" >/etc/apt/sources.list.d/plexmediaserver.list 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
apt update && apt install -y plexmediaserver apt update && apt install -y plexmediaserver
############################################################################## ##############################################################################
@@ -186,7 +207,7 @@ EOF
systemctl restart smbd nmbd systemctl restart smbd nmbd
############################################################################## ##############################################################################
# 11. Resumen # # 11. Resumen final #
############################################################################## ##############################################################################
next "✅ Resumen" next "✅ Resumen"
echo -e "🔑 Accesos:" echo -e "🔑 Accesos:"
@@ -194,4 +215,13 @@ 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 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."
if [[ $AUTO_REBOOT == yes ]]; then
echo -e "\n🔄 Reiniciando en 10 s… (Ctrl-C para abortar)"
sleep 10 && reboot
else
read -rp $'\n¿Reiniciar ahora? [y/N]: ' ans
[[ ${ans,,} == y ]] && reboot || echo "🚀 Instalación completada sin reinicio."
fi