Update auto_server_setup.sh

This commit is contained in:
Marco Gallegos
2025-04-29 10:56:19 -06:00
committed by GitHub
parent cf34482fdb
commit 3a833d82af

View File

@@ -1,18 +1,19 @@
#!/usr/bin/env bash #!/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 set -euo pipefail
LOG(){ printf "\n\e[1;32m▶ %s\e[0m\n" "$*"; } LOG(){ printf "\n\e[1;32m▶ %s\e[0m\n" "$*"; }
# -------- Ajusta aquí ---------- # -------- Ajusta aquí ----------
SERVER_USER="${SUDO_USER:-$USER}" # usuario que se añadi a docker/zerotier SERVER_USER="${SUDO_USER:-$USER}" # usuario añadido a docker/zerotier
INSTALL_PIHOLE="yes" # pon "no" para omitir Pi-hole INSTALL_PIHOLE="yes" # "no" para omitir Pi-hole
INSTALL_CASAOS="yes" # pon "no" para omitir CasaOS 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…" LOG "Actualizando APT y herramientas básicas…"
apt update && apt -y full-upgrade apt update && apt -y full-upgrade
apt install -y git curl gnupg lsb-release nano \ 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…" LOG "Instalando Zsh y Oh-My-Zsh…"
apt install -y zsh apt install -y zsh
RUNZSH=no CHSH=no sh -c \ RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended #
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions \ 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" sed -i 's/^plugins=(\(.*\))/plugins=(\1 zsh-autosuggestions)/' "${HOME}/.zshrc"
chsh -s "$(command -v zsh)" "$SERVER_USER" 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…" LOG "Instalando fzf y btop…"
apt install -y fzf btop # :contentReference[oaicite:0]{index=0} apt install -y fzf btop
} }
################################### ###################################
# 4. Certbot (Lets Encrypt) # 4. Certbot (Lets Encrypt)
################################### ###################################
install_certbot(){ install_certbot() {
LOG "Instalando Certbot (snap)…" LOG "Instalando Certbot (snap)…"
snap install core --classic >/dev/null 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 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…" LOG "Instalando Docker Engine…"
install -m0755 -d /etc/apt/keyrings install -m0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.asc gpg --dearmor -o /etc/apt/keyrings/docker.asc
echo \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \ 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 update
apt install -y docker-ce docker-ce-cli containerd.io \ 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" usermod -aG docker "$SERVER_USER"
} }
################################### ###################################
# 6. ZeroTier One (red P2P segura) # 6. ZeroTier One
################################### ###################################
install_zerotier(){ install_zerotier() {
LOG "Instalando ZeroTier…" LOG "Instalando ZeroTier…"
curl -s https://install.zerotier.com | bash # curl -s https://install.zerotier.com | bash
usermod -aG zerotier-one "$SERVER_USER" usermod -aG zerotier-one "$SERVER_USER"
systemctl enable --now zerotier-one systemctl enable --now zerotier-one
} }
################################### ###################################
# 7. Portainer (en contenedor) # 7. Portainer
################################### ###################################
install_portainer(){ install_portainer() {
LOG "Desplegando Portainer CE…" LOG "Desplegando Portainer CE…"
docker volume create portainer_data docker volume create portainer_data
docker run -d --name portainer \ docker run -d --name portainer \
@@ -91,48 +90,48 @@ install_portainer(){
--restart=always \ --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \ -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 [[ "$INSTALL_CASAOS" == "no" ]] && return
LOG "Instalando CasaOS…" 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 [[ "$INSTALL_PIHOLE" == "no" ]] && return
LOG "Instalando Pi-hole… (asistente CLI)" LOG "Instalando Pi-hole… (modo unattended)"
export PIHOLE_SKIP_OS_CHECK=true 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) # 10. Plex Media Server (nativo)
################################### ###################################
install_plex(){ install_plex() {
LOG "Instalando Plex Media Server…" LOG "Instalando Plex Media Server…"
install -m0755 -d /etc/apt/keyrings install -m0755 -d /etc/apt/keyrings
curl https://downloads.plex.tv/plex-keys/PlexSign.key | \ curl https://downloads.plex.tv/plex-keys/PlexSign.key | \
gpg --dearmor -o /etc/apt/keyrings/plex.asc gpg --dearmor -o /etc/apt/keyrings/plex.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/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" | \ 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 update
apt install -y plexmediaserver # apt install -y plexmediaserver
systemctl enable --now plexmediaserver systemctl enable --now plexmediaserver
} }
######################## ############################
# Ejecución en cascada # Ejecución en cascada
######################## ############################
main(){ main() {
install_base install_base
install_shell install_shell
install_utils install_utils
@@ -144,21 +143,22 @@ main(){
install_pihole install_pihole
install_plex install_plex
LOG "🎉 Instalación completa." LOG "Instalación completa."
LOG "🔗 Accesos: LOG "Accesos:\n • Portainer → https://<IP>:9443\n • CasaOS → http://<IP>\n • Plex → http://<IP>:32400/web\n • Pi-hole → http://<IP>/admin"
• Portainer → https://localhost:9443
• CasaOS → http://localhost
• Plex → http://localhost:32400/web
• Pi-hole → http://localhost/admin
printf "\n¿Deseas reiniciar ahora? [y/N]: " if [[ "$AUTO_REBOOT" == "yes" ]]; then
read -r REPLY LOG "Reiniciando en 10 s… (Ctrl-C para abortar)"
if [[ ${REPLY,,} == "y" ]]; then sleep 10 && reboot
LOG "Reiniciando…"
reboot
else 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 fi
} }
main "$@" main \"$@\"