mirror of
https://github.com/marcogll/scripts_mg.git
synced 2026-01-13 13:25:15 +00:00
Update auto_server_setup.sh
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/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,
|
# Home-server Ubuntu 22.04/24.04 con Docker, Portainer, ZeroTier, Tailscale,
|
||||||
# Plex, Samba, Oh-My-Zsh (+plugins/alias) y Oh-My-Posh (clean-detailed)
|
# Plex, Samba, Oh-My-Zsh (plugins + alias) y Oh-My-Posh (tema clean-detailed)
|
||||||
# + Meslo Nerd Font. Barra de progreso con emojis anclada arriba. 🚀🛠️
|
# + Meslo Nerd Font. Barra de progreso con emojis anclada arriba. 🚀🛠️
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -9,75 +9,79 @@ set -euo pipefail
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
# Barra de progreso «pegada» #
|
# Barra de progreso «pegada» #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
STEPS_TOTAL=12 # aumenta/reduce si añades o quitas “next”
|
STEPS_TOTAL=12
|
||||||
STEP_NOW=0
|
STEP_NOW=0
|
||||||
bar() {
|
bar() {
|
||||||
clear
|
clear
|
||||||
local w=20 f=$((STEP_NOW*w/STEPS_TOTAL)) e=$((w-f))
|
local width=20 # ancho de la barra
|
||||||
printf "%s %3d%% %s\n\n" \
|
local filled=$(( STEP_NOW*width/STEPS_TOTAL ))
|
||||||
"$(printf '%0.s🟩' $(seq 1 $f))$(printf '%0.s⬜' $(seq 1 $e))" \
|
local empty=$(( width-filled ))
|
||||||
$((STEP_NOW*100/STEPS_TOTAL)) "$1"
|
local line
|
||||||
|
line="$(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"
|
||||||
}
|
}
|
||||||
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"; }
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Comprobación de root #
|
# Comprobación de root #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
[[ $(id -u) -eq 0 ]] || { echo "⚠️ Ejecuta este script con sudo o como root." >&2; exit 1; }
|
[[ $(id -u) -eq 0 ]] || { echo "⚠️ Ejecuta con sudo o como root." >&2; exit 1; }
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 0. Hostname (muestra actual y deja por defecto) #
|
# 0. Hostname #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "🖥️ Configurando hostname"
|
next "🖥️ Configurando hostname"
|
||||||
HOST_DEFAULT="$(hostname)"
|
DEFAULT_HOST="$(hostname)"
|
||||||
read -rp "➤ Nuevo hostname [$HOST_DEFAULT]: " NEW_HOST
|
read -rp "➤ Nuevo hostname [$DEFAULT_HOST]: " NEW_HOST
|
||||||
NEW_HOST="${NEW_HOST:-$HOST_DEFAULT}"
|
NEW_HOST="${NEW_HOST:-$DEFAULT_HOST}"
|
||||||
echo "$NEW_HOST" > /etc/hostname
|
echo "$NEW_HOST" >/etc/hostname
|
||||||
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEW_HOST/" /etc/hosts || true
|
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEW_HOST/" /etc/hosts || true
|
||||||
hostname "$NEW_HOST"
|
hostname "$NEW_HOST"
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 1. Preguntas iniciales (con valores por defecto) #
|
# 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; SERVER_USER="${tmp:-$DEFAULT_USER}"
|
read -rp "➤ Usuario Linux a configurar [$DEFAULT_USER]: " tmp; SERVER_USER="${tmp:-$DEFAULT_USER}"
|
||||||
|
|
||||||
read -rp "➤ Instalar Pi-hole? [Y/n]: " p; INSTALL_PIHOLE="$( [[ ${p,,} =~ ^n ]] && echo no || echo yes )"
|
read -rp "➤ Instalar Pi-hole? [Y/n]: " p; 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 "➤ 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 )"
|
read -rp "➤ Reinicio automático al final? [Y/n]: " r; AUTO_REBOOT="$( [[ ${r,,} =~ ^n ]] && echo no || echo yes )"
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 2. Paquetes base + Zsh + plugins + alias #
|
# 2. Paquetes base (lista con descripción) #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "📦 Instalando paquetes base"
|
next "📦 Instalando paquetes base"
|
||||||
declare -A BASE_PKGS=(
|
declare -A BASE_PKGS=(
|
||||||
[git]="sistema de control de versiones"
|
[git]="control de versiones"
|
||||||
[curl]="cliente de descargas HTTP(S)"
|
[curl]="cliente HTTP(S)"
|
||||||
[gnupg]="cifrado y firmas GPG"
|
[gnupg]="cifrado/Firmas GPG"
|
||||||
[lsb-release]="info de versión Ubuntu"
|
[lsb-release]="info versión Ubuntu"
|
||||||
[nano]="editor de texto"
|
[nano]="editor de texto"
|
||||||
[build-essential]="herramientas de compilación"
|
[build-essential]="herramientas de compilación"
|
||||||
[ca-certificates]="certificados SSL"
|
[ca-certificates]="certificados SSL"
|
||||||
[software-properties-common]="gestión de repositorios PPA"
|
[software-properties-common]="gestión de repositorios"
|
||||||
[apt-transport-https]="APT vía HTTPS"
|
[apt-transport-https]="APT vía HTTPS"
|
||||||
[fontconfig]="caché de fuentes (fc-cache)"
|
[fontconfig]="caché de fuentes (fc-cache)"
|
||||||
[zsh]="shell Z sh"
|
[zsh]="shell Zsh"
|
||||||
[fzf]="búsqueda fuzzy"
|
[fzf]="búsqueda fuzzy"
|
||||||
[btop]="monitor de recursos"
|
[btop]="monitor recursos"
|
||||||
[ufw]="firewall sencillo"
|
[ufw]="firewall sencillo"
|
||||||
[unzip]="descompresor ZIP"
|
[unzip]="descompresor ZIP"
|
||||||
[whiptail]="menús en shell"
|
[whiptail]="menús shell"
|
||||||
)
|
)
|
||||||
echo -e "• Lista de paquetes a instalar:"
|
echo "• Se instalarán:"
|
||||||
for pkg in "${!BASE_PKGS[@]}"; do printf " - %-15s %s\n" "$pkg" "${BASE_PKGS[$pkg]}"; done
|
for pkg in "${!BASE_PKGS[@]}"; do printf " - %-15s %s\n" "$pkg" "${BASE_PKGS[$pkg]}"; 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 "${!BASE_PKGS[@]}"
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 3. Oh-My-Zsh + plugins + alias #
|
||||||
|
##############################################################################
|
||||||
next "💎 Oh-My-Zsh + plugins/alias"
|
next "💎 Oh-My-Zsh + plugins/alias"
|
||||||
sudo -u "$SERVER_USER" sh -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"
|
||||||
@@ -96,13 +100,12 @@ EOF
|
|||||||
chsh -s "$(command -v zsh)" "$SERVER_USER"
|
chsh -s "$(command -v zsh)" "$SERVER_USER"
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 3. Oh-My-Posh + Meslo Nerd Font (instalación manual) #
|
# 4. Oh-My-Posh + Meslo Nerd Font (manual) #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
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
|
||||||
TMPF=$(mktemp -d)
|
TMPF=$(mktemp -d)
|
||||||
curl -fsSL https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip \
|
curl -fsSL https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip -o "$TMPF/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"
|
||||||
@@ -114,7 +117,7 @@ OMP_LINE='eval "$(oh-my-posh init zsh --config ~/.poshthemes/clean-detailed.omp.
|
|||||||
grep -qxF "$OMP_LINE" "$ZSHRC" || echo "$OMP_LINE" >> "$ZSHRC"
|
grep -qxF "$OMP_LINE" "$ZSHRC" || echo "$OMP_LINE" >> "$ZSHRC"
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 4. Certbot #
|
# 5. Certbot #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "🔐 Certbot"
|
next "🔐 Certbot"
|
||||||
snap install core --classic >/dev/null || true
|
snap install core --classic >/dev/null || true
|
||||||
@@ -123,14 +126,14 @@ 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 #
|
# 6. Docker + Portainer + ZeroTier + Tailscale #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "🐳 Docker, Portainer, ZeroTier, Tailscale"
|
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
|
||||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
|
||||||
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
|
||||||
@@ -142,26 +145,25 @@ 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) #
|
# 7. CasaOS (opcional) #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
[[ $INSTALL_CASAOS == yes ]] && { next "🏠 CasaOS"; curl -fsSL https://get.casaos.io | bash; }
|
[[ $INSTALL_CASAOS == yes ]] && { next "🏠 CasaOS"; curl -fsSL https://get.casaos.io | bash; }
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 7. 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; }
|
[[ $INSTALL_PIHOLE == yes ]] && { next "🚫 Pi-hole"; export PIHOLE_SKIP_OS_CHECK=true; curl -sSL https://install.pi-hole.net | bash -s -- --unattended; }
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 8. 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" \
|
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 #
|
# 10. Samba #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "📁 Samba"
|
next "📁 Samba"
|
||||||
apt install -y samba
|
apt install -y samba
|
||||||
@@ -184,7 +186,7 @@ EOF
|
|||||||
systemctl restart smbd nmbd
|
systemctl restart smbd nmbd
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 10. Resumen final #
|
# 11. Resumen #
|
||||||
##############################################################################
|
##############################################################################
|
||||||
next "✅ Resumen"
|
next "✅ Resumen"
|
||||||
echo -e "🔑 Accesos:"
|
echo -e "🔑 Accesos:"
|
||||||
@@ -192,13 +194,4 @@ 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
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user