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,12 +1,13 @@
#!/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ñadi 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
# ---------------------------------
###################################
@@ -26,8 +27,7 @@ install_base(){
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"
sed -i 's/^plugins=(\(.*\))/plugins=(\1 zsh-autosuggestions)/' "${HOME}/.zshrc"
@@ -39,7 +39,7 @@ install_shell(){
###################################
install_utils() {
LOG "Instalando fzf y btop…"
apt install -y fzf btop # :contentReference[oaicite:0]{index=0}
apt install -y fzf btop
}
###################################
@@ -48,7 +48,7 @@ install_utils(){
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
}
@@ -60,28 +60,27 @@ install_docker(){
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
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() {
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() {
LOG "Desplegando Portainer CE…"
@@ -91,7 +90,7 @@ 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
}
###################################
@@ -100,17 +99,17 @@ install_portainer(){
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" == "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
}
###################################
@@ -125,13 +124,13 @@ install_plex(){
https://downloads.plex.tv/repo/deb public main" | \
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() {
install_base
install_shell
@@ -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://<IP>:9443\n • CasaOS → http://<IP>\n • Plex → http://<IP>:32400/web\n • Pi-hole → http://<IP>/admin"
if [[ "$AUTO_REBOOT" == "yes" ]]; then
LOG "Reiniciando en 10 s… (Ctrl-C para abortar)"
sleep 10 && reboot
else
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 lo creas conveniente."
LOG "No se reinició. Hazlo manualmente cuando quieras."
fi
fi
}
main "$@"
main \"$@\"