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,54 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# auto_server_setup_extended.sh — 2025-04-30
|
||||
# Configura un home-server Ubuntu 22.04/24.04 con Docker, Portainer,
|
||||
# ZeroTier, Tailscale, Plex, Samba, Oh-My-Zsh, Oh-My-Posh, etc.
|
||||
# auto_server_setup_extended.sh — 2025-05-02
|
||||
# Home-server Ubuntu 22.04/24.04: Docker, Portainer, ZeroTier, Tailscale,
|
||||
# Plex, Samba, Oh-My-Zsh, Oh-My-Posh (clean-detailed) + Meslo Nerd Font.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
################################################################################
|
||||
# Barra de progreso simple (texto) #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# Barra de progreso #
|
||||
##############################################################################
|
||||
STEPS_TOTAL=12 # ajusta si añades/eliminas pasos
|
||||
STEP_NOW=0
|
||||
bar() {
|
||||
local width=50
|
||||
local filled=$(( STEP_NOW*width/STEPS_TOTAL ))
|
||||
local empty=$(( width-filled ))
|
||||
local w=50
|
||||
local f=$(( STEP_NOW*w/STEPS_TOTAL ))
|
||||
local e=$(( w-f ))
|
||||
printf "\r[%s%s] %3d%% %s" \
|
||||
"$(printf '%0.s#' $(seq 1 $filled))" \
|
||||
"$(printf '%0.s-' $(seq 1 $empty))" \
|
||||
"$(printf '%0.s#' $(seq 1 $f))" \
|
||||
"$(printf '%0.s-' $(seq 1 $e))" \
|
||||
$(( STEP_NOW*100/STEPS_TOTAL )) \
|
||||
"$1"
|
||||
}
|
||||
next() { STEP_NOW=$(( STEP_NOW+1 )); bar "$1"; echo; }
|
||||
LOG() { echo -e "\n\033[1;32m▶ $*\033[0m"; }
|
||||
|
||||
################################################################################
|
||||
# Comprobaciones previas #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# Comprobaciones previas #
|
||||
##############################################################################
|
||||
if [[ "$(id -u)" -ne 0 ]]; then
|
||||
echo "⚠️ Este script debe ejecutarse como root (sudo)." >&2
|
||||
echo "⚠️ Ejecuta este script con sudo o como root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
################################################################################
|
||||
# 0. Hostname y recordatorio Oh-My-Posh profile #
|
||||
################################################################################
|
||||
next "Configurando hostname"
|
||||
read -rp "➤ Nombre para el servidor (hostname): " NEW_HOST
|
||||
[ -n "$NEW_HOST" ] && {
|
||||
##############################################################################
|
||||
# 0. Hostname y recordatorio del perfil OMP #
|
||||
##############################################################################
|
||||
next "Hostname"
|
||||
read -rp "➤ Nuevo hostname: " NEW_HOST
|
||||
if [[ -n "$NEW_HOST" ]]; then
|
||||
echo "$NEW_HOST" > /etc/hostname
|
||||
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEW_HOST/" /etc/hosts || true
|
||||
hostname "$NEW_HOST"
|
||||
}
|
||||
fi
|
||||
|
||||
echo -e "\n📝 Copia tu perfil Oh-My-Posh (.omp.json) a ~/ antes de continuar"
|
||||
read -rp " (pulsa Enter para seguir)… "
|
||||
echo -e "\n📝 Si tienes un perfil Oh-My-Posh (.omp.json) personal, súbelo a ~/."
|
||||
read -rp " Pulsa Enter para continuar… "
|
||||
|
||||
################################################################################
|
||||
# 1. Preguntas interactivas generales #
|
||||
################################################################################
|
||||
next "Preguntas iniciales"
|
||||
##############################################################################
|
||||
# 1. Preguntas interactivas generales #
|
||||
##############################################################################
|
||||
next "Parámetros iniciales"
|
||||
DEFAULT_USER="${SUDO_USER:-$USER}"
|
||||
read -rp "➤ Usuario Linux a configurar [$DEFAULT_USER]: " TMP
|
||||
SERVER_USER="${TMP:-$DEFAULT_USER}"
|
||||
@@ -62,9 +62,9 @@ INSTALL_CASAOS="$( [[ ${cas,,} =~ ^n ]] && echo no || echo yes )"
|
||||
read -rp "➤ Reinicio automático al final? [Y/n]: " reb
|
||||
AUTO_REBOOT="$( [[ ${reb,,} =~ ^n ]] && echo no || echo yes )"
|
||||
|
||||
################################################################################
|
||||
# 2. Paquetes base + Zsh + utilidades #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# 2. Paquetes base + Zsh + plugins + alias #
|
||||
##############################################################################
|
||||
next "Paquetes base"
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt update && apt -y full-upgrade
|
||||
@@ -75,57 +75,68 @@ apt install -y git curl gnupg lsb-release nano build-essential \
|
||||
next "Oh-My-Zsh + plugins"
|
||||
sudo -u "$SERVER_USER" sh -c \
|
||||
'curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash -s -- --unattended'
|
||||
|
||||
# Plugins: autosuggestions + syntax-highlighting + colorize
|
||||
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"
|
||||
sudo -u "$SERVER_USER" sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions)/' \
|
||||
"/home/$SERVER_USER/.zshrc"
|
||||
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"
|
||||
|
||||
ZSHRC="/home/$SERVER_USER/.zshrc"
|
||||
sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting colorize)/' "$ZSHRC"
|
||||
|
||||
# Alias y PATH adicionales
|
||||
grep -qxF "alias cls='clear'" "$ZSHRC" || cat >> "$ZSHRC" <<'EOF'
|
||||
|
||||
# --- Custom aliases ---
|
||||
alias cls='clear'
|
||||
alias clima='curl wttr.in/Saltillo'
|
||||
alias pip='pip3'
|
||||
export PATH=$HOME/.local/bin:$HOME/.npm-global/bin:$PATH
|
||||
EOF
|
||||
|
||||
chsh -s "$(command -v zsh)" "$SERVER_USER"
|
||||
|
||||
################################################################################
|
||||
# 3. Oh-My-Posh + Meslo Nerd Font #
|
||||
################################################################################
|
||||
next "Oh-My-Posh + Meslo Nerd Font"
|
||||
##############################################################################
|
||||
# 3. Oh-My-Posh + Meslo Nerd Font (clean-detailed) #
|
||||
##############################################################################
|
||||
next "Oh-My-Posh + Meslo"
|
||||
curl -fsSL https://ohmyposh.dev/install.sh | bash -s -- -d /usr/local/bin
|
||||
|
||||
TMP_FONT_DIR=$(mktemp -d)
|
||||
curl -fsSL https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Meslo.zip -o "$TMP_FONT_DIR/meslo.zip"
|
||||
unzip -q "$TMP_FONT_DIR/meslo.zip" -d "$TMP_FONT_DIR"
|
||||
mkdir -p /usr/local/share/fonts
|
||||
cp "$TMP_FONT_DIR"/*.ttf /usr/local/share/fonts/
|
||||
# Instalar fuente Meslo con la herramienta integrada
|
||||
oh-my-posh font install meslo --path /usr/local/share/fonts
|
||||
fc-cache -f
|
||||
|
||||
# Tema clean-detailed
|
||||
sudo -u "$SERVER_USER" mkdir -p "/home/$SERVER_USER/.poshthemes"
|
||||
if [[ -f "/home/$SERVER_USER/catppuccin_mocha.omp.json" ]]; then
|
||||
cp "/home/$SERVER_USER/catppuccin_mocha.omp.json" "/home/$SERVER_USER/.poshthemes/"
|
||||
else
|
||||
curl -fsSL https://raw.githubusercontent.com/catppuccin/oh-my-posh/main/themes/catppuccin_mocha.omp.json \
|
||||
-o "/home/$SERVER_USER/.poshthemes/catppuccin_mocha.omp.json"
|
||||
fi
|
||||
chmod 644 "/home/$SERVER_USER/.poshthemes/catppuccin_mocha.omp.json"
|
||||
OMP_LINE='eval "$(oh-my-posh init zsh --config ~/.poshthemes/catppuccin_mocha.omp.json)"'
|
||||
grep -qxF "$OMP_LINE" "/home/$SERVER_USER/.zshrc" || echo "$OMP_LINE" >> "/home/$SERVER_USER/.zshrc"
|
||||
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"
|
||||
chmod 644 "/home/$SERVER_USER/.poshthemes/clean-detailed.omp.json"
|
||||
|
||||
################################################################################
|
||||
# 4. Certbot #
|
||||
################################################################################
|
||||
OMP_LINE='eval "$(oh-my-posh init zsh --config ~/.poshthemes/clean-detailed.omp.json)"'
|
||||
grep -qxF "$OMP_LINE" "$ZSHRC" || echo "$OMP_LINE" >> "$ZSHRC"
|
||||
|
||||
##############################################################################
|
||||
# 4. Certbot #
|
||||
##############################################################################
|
||||
next "Certbot"
|
||||
snap install core --classic >/dev/null || true
|
||||
snap refresh core
|
||||
snap install --classic certbot
|
||||
ln -sf /snap/bin/certbot /usr/bin/certbot
|
||||
|
||||
################################################################################
|
||||
# 5. Docker + Portainer + ZeroTier + Tailscale #
|
||||
################################################################################
|
||||
next "Docker, Portainer, ZeroTier, Tailscale"
|
||||
##############################################################################
|
||||
# 5. Docker + Portainer + ZeroTier + Tailscale #
|
||||
##############################################################################
|
||||
next "Docker/Portainer/ZeroTier/Tailscale"
|
||||
install -m0755 -d /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
source /etc/os-release
|
||||
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 install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
usermod -aG docker "$SERVER_USER"
|
||||
|
||||
docker volume create portainer_data
|
||||
@@ -140,40 +151,40 @@ curl -s https://install.zerotier.com | bash
|
||||
curl -fsSL https://tailscale.com/install.sh | sh
|
||||
tailscale up --ssh --accept-dns=false || true
|
||||
|
||||
################################################################################
|
||||
# 6. CasaOS (opcional) #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# 6. CasaOS (opcional) #
|
||||
##############################################################################
|
||||
if [[ "$INSTALL_CASAOS" == "yes" ]]; then
|
||||
next "CasaOS"
|
||||
curl -fsSL https://get.casaos.io | bash
|
||||
fi
|
||||
|
||||
################################################################################
|
||||
# 7. Pi-hole (opcional) #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# 7. Pi-hole (opcional) #
|
||||
##############################################################################
|
||||
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
|
||||
|
||||
################################################################################
|
||||
# 8. Plex Media Server #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# 8. Plex Media Server #
|
||||
##############################################################################
|
||||
next "Plex"
|
||||
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
|
||||
apt update && apt install -y plexmediaserver
|
||||
|
||||
################################################################################
|
||||
# 9. Samba #
|
||||
################################################################################
|
||||
##############################################################################
|
||||
# 9. Samba #
|
||||
##############################################################################
|
||||
next "Samba"
|
||||
apt install -y samba
|
||||
read -rp "➤ Carpeta a compartir (ruta completa): " SAMBA_DIR
|
||||
mkdir -p "$SAMBA_DIR"
|
||||
read -rp "➤ Nombre de usuario Samba: " SAMBA_USER
|
||||
read -rp "➤ Usuario Samba: " SAMBA_USER
|
||||
read -srp "➤ Contraseña Samba: " SAMBA_PASS; echo
|
||||
adduser --gecos "" --disabled-password "$SAMBA_USER"
|
||||
echo "$SAMBA_USER:$SAMBA_PASS" | chpasswd
|
||||
@@ -189,17 +200,17 @@ cat >> /etc/samba/smb.conf <<EOF
|
||||
EOF
|
||||
systemctl restart smbd nmbd
|
||||
|
||||
################################################################################
|
||||
# 10. Resumen y reinicio #
|
||||
################################################################################
|
||||
next "Resumen final"
|
||||
echo -e "\n🔑 Accesos principales:"
|
||||
##############################################################################
|
||||
# 10. Resumen final #
|
||||
##############################################################################
|
||||
next "Resumen"
|
||||
echo -e "\n🔑 Accesos:"
|
||||
echo " • Portainer → https://$NEW_HOST:9443"
|
||||
echo " • Plex → http://$NEW_HOST:32400/web"
|
||||
[[ "$INSTALL_PIHOLE" == "yes" ]] && echo " • Pi-hole → http://$NEW_HOST/admin"
|
||||
[[ "$INSTALL_CASAOS" == "yes" ]] && echo " • CasaOS → http://$NEW_HOST"
|
||||
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 correctamente."
|
||||
echo -e "\n⚠️ Selecciona la fuente «MesloLGS NF» en tu terminal local para ver Oh-My-Posh."
|
||||
|
||||
if [[ "$AUTO_REBOOT" == "yes" ]]; then
|
||||
echo -e "\nReiniciando en 10 s… (Ctrl-C para abortar)"
|
||||
|
||||
Reference in New Issue
Block a user