diff --git a/server_scripts/auto_server_setup.sh b/server_scripts/auto_server_setup.sh index ffe0213..9dd55ea 100644 --- a/server_scripts/auto_server_setup.sh +++ b/server_scripts/auto_server_setup.sh @@ -1,18 +1,19 @@ #!/usr/bin/env bash -# setup_home_server.sh — Marco G. & ChatGPT — 2025-04-28 +# auto_server_setup.sh — Marco G. & ChatGPT — 2025-04-28 set -euo pipefail LOG(){ printf "\n\e[1;32m▶ %s\e[0m\n" "$*"; } # -------- Ajusta aquí ---------- -SERVER_USER="${SUDO_USER:-$USER}" # usuario que se añadirá a docker/zerotier -INSTALL_PIHOLE="yes" # pon "no" para omitir Pi-hole -INSTALL_CASAOS="yes" # pon "no" para omitir CasaOS +SERVER_USER="${SUDO_USER:-$USER}" # usuario añadido a docker/zerotier +INSTALL_PIHOLE="yes" # "no" para omitir Pi-hole +INSTALL_CASAOS="yes" # "no" para omitir CasaOS +AUTO_REBOOT="yes" # "no" para reinicio manual # --------------------------------- ################################### -# 1. Base APT + actualizaciones +# 1. Base APT + actualizaciones ################################### -install_base(){ +install_base() { LOG "Actualizando APT y herramientas básicas…" apt update && apt -y full-upgrade apt install -y git curl gnupg lsb-release nano \ @@ -21,69 +22,67 @@ install_base(){ } ################################### -# 2. Zsh + Oh-My-Zsh + autosuggestions +# 2. Zsh + Oh-My-Zsh + autosuggestions ################################### -install_shell(){ +install_shell() { LOG "Instalando Zsh y Oh-My-Zsh…" apt install -y zsh - RUNZSH=no CHSH=no sh -c \ - "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended # + RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions \ - "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions" + "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions" sed -i 's/^plugins=(\(.*\))/plugins=(\1 zsh-autosuggestions)/' "${HOME}/.zshrc" chsh -s "$(command -v zsh)" "$SERVER_USER" } ################################### -# 3. Utilidades extra (fzf, btop) +# 3. Utilidades extra (fzf, btop) ################################### -install_utils(){ +install_utils() { LOG "Instalando fzf y btop…" - apt install -y fzf btop # :contentReference[oaicite:0]{index=0} + apt install -y fzf btop } ################################### -# 4. Certbot (Let’s Encrypt) +# 4. Certbot (Let’s Encrypt) ################################### -install_certbot(){ +install_certbot() { LOG "Instalando Certbot (snap)…" snap install core --classic >/dev/null - snap install certbot --classic # :contentReference[oaicite:1]{index=1} + snap install certbot --classic ln -sf /snap/bin/certbot /usr/bin/certbot } ################################### -# 5. Docker Engine + compose-plugin +# 5. Docker Engine + compose-plugin ################################### -install_docker(){ +install_docker() { LOG "Instalando Docker Engine…" install -m0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ gpg --dearmor -o /etc/apt/keyrings/docker.asc - echo \ -"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \ https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \ - tee /etc/apt/sources.list.d/docker.list >/dev/null + tee /etc/apt/sources.list.d/docker.list >/dev/null apt update apt install -y docker-ce docker-ce-cli containerd.io \ - docker-buildx-plugin docker-compose-plugin # + docker-buildx-plugin docker-compose-plugin usermod -aG docker "$SERVER_USER" } ################################### -# 6. ZeroTier One (red P2P segura) +# 6. ZeroTier One ################################### -install_zerotier(){ +install_zerotier() { LOG "Instalando ZeroTier…" - curl -s https://install.zerotier.com | bash # + curl -s https://install.zerotier.com | bash usermod -aG zerotier-one "$SERVER_USER" systemctl enable --now zerotier-one } ################################### -# 7. Portainer (en contenedor) +# 7. Portainer ################################### -install_portainer(){ +install_portainer() { LOG "Desplegando Portainer CE…" docker volume create portainer_data docker run -d --name portainer \ @@ -91,48 +90,48 @@ install_portainer(){ --restart=always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v portainer_data:/data \ - portainer/portainer-ce:latest # + portainer/portainer-ce:latest } ################################### -# 8. CasaOS (opcional) +# 8. CasaOS (opcional) ################################### -install_casaos(){ +install_casaos() { [[ "$INSTALL_CASAOS" == "no" ]] && return LOG "Instalando CasaOS…" - curl -fsSL https://get.casaos.io | bash # + curl -fsSL https://get.casaos.io | bash } ################################### -# 9. Pi-hole (opcional, nativo) +# 9. Pi-hole (opcional) ################################### -install_pihole(){ +install_pihole() { [[ "$INSTALL_PIHOLE" == "no" ]] && return - LOG "Instalando Pi-hole… (asistente CLI)" + LOG "Instalando Pi-hole… (modo unattended)" export PIHOLE_SKIP_OS_CHECK=true - curl -sSL https://install.pi-hole.net | bash # + curl -sSL https://install.pi-hole.net | bash } ################################### # 10. Plex Media Server (nativo) ################################### -install_plex(){ +install_plex() { LOG "Instalando Plex Media Server…" install -m0755 -d /etc/apt/keyrings curl https://downloads.plex.tv/plex-keys/PlexSign.key | \ gpg --dearmor -o /etc/apt/keyrings/plex.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/plex.asc] \ https://downloads.plex.tv/repo/deb public main" | \ - tee /etc/apt/sources.list.d/plexmediaserver.list >/dev/null + tee /etc/apt/sources.list.d/plexmediaserver.list >/dev/null apt update - apt install -y plexmediaserver # + apt install -y plexmediaserver systemctl enable --now plexmediaserver } -######################## -# Ejecución en cascada -######################## -main(){ +############################ +# Ejecución en cascada +############################ +main() { install_base install_shell install_utils @@ -144,21 +143,22 @@ main(){ install_pihole install_plex - LOG "🎉 Instalación completa." - LOG "🔗 Accesos: - • Portainer → https://localhost:9443 - • CasaOS → http://localhost - • Plex → http://localhost:32400/web - • Pi-hole → http://localhost/admin + LOG "Instalación completa." + LOG "Accesos:\n • Portainer → https://:9443\n • CasaOS → http://\n • Plex → http://:32400/web\n • Pi-hole → http:///admin" - printf "\n¿Deseas reiniciar ahora? [y/N]: " - read -r REPLY - if [[ ${REPLY,,} == "y" ]]; then - LOG "Reiniciando…" - reboot + if [[ "$AUTO_REBOOT" == "yes" ]]; then + LOG "Reiniciando en 10 s… (Ctrl-C para abortar)" + sleep 10 && reboot else - LOG "No se reinició. Hazlo manualmente cuando lo creas conveniente." + printf "\n¿Deseas reiniciar ahora? [y/N]: " + read -r REPLY + if [[ ${REPLY,,} == "y" ]]; then + LOG "Reiniciando…" + reboot + else + LOG "No se reinició. Hazlo manualmente cuando quieras." + fi fi } -main "$@" +main \"$@\"