Script para instalar programas en linux v2 [ nota: hay que probarlo ]

PHOTO EMBED

Tue Nov 11 2025 14:18:28 GMT+0000 (Coordinated Universal Time)

Saved by @jrg_300i #yii2

#!/bin/bash

# Colores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Función para imprimir mensajes
print_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }

# -- Actualizar el sistema
print_info "Actualizando sistema..."
sudo apt update && sudo apt upgrade -y

# -- Instalar dependencias básicas
print_info "Instalando dependencias básicas..."
sudo apt install wget curl gpg gnupg2 software-properties-common apt-transport-https ca-certificates -y

# -- Instalar git
print_info "Instalando Git..."
sudo apt install git gitk git-gui meld git-doc -y

# -- Instalar vscode
print_info "Instalando VS Code..."
# Crear directorio para claves
sudo mkdir -p /etc/apt/keyrings

# Agregar clave GPG de Microsoft
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /etc/apt/keyrings/packages.microsoft.gpg

# Agregar repositorio de VS Code CORREGIDO
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list

# Actualizar lista de paquetes e instalar VS Code
sudo apt update
sudo apt install code -y

# -- Instalar google chrome (MÉTODO ACTUALIZADO)
print_info "Instalando Google Chrome..."
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /etc/apt/keyrings/google-chrome.gpg
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt update
sudo apt install google-chrome-stable -y

# -- Instalar php
print_info "Instalando PHP..."
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

# -- Instalar python
print_info "Instalando Python..."
sudo apt install python3 python3-dev python3-venv python3-pip python3-setuptools python3-wheel build-essential -y

# -- Instalar PHP 7.4 y extensiones comunes
print_info "Instalando PHP 7.4..."
sudo apt install php7.4 php7.4-pgsql php7.4-cli php7.4-fpm php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath libapache2-mod-php7.4 -y

# -- Instalar PHP 8.4 y extensiones
print_info "Instalando PHP 8.4..."
sudo apt install php8.4 php8.4-pgsql php8.4-cli php8.4-fpm php8.4-common php8.4-mysql php8.4-zip php8.4-gd php8.4-mbstring php8.4-curl php8.4-xml php8.4-bcmath -y

# -- Instalar composer
print_info "Instalando Composer..."
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

# -- Instalar apache2
print_info "Instalando Apache2..."
sudo apt install apache2 -y

# -- Instalar postgres
print_info "Instalando PostgreSQL..."
sudo mkdir -p /etc/apt/keyrings
curl -fsS https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg
echo "deb [signed-by=/etc/apt/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt install postgresql postgresql-contrib -y

# -- Instalar pgadmin4
print_info "Instalando pgAdmin4..."
sudo mkdir -p /etc/apt/keyrings
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /etc/apt/keyrings/pgadmin-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/pgadmin-keyring.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" | sudo tee /etc/apt/sources.list.d/pgadmin4.list
sudo apt update
sudo apt install pgadmin4-desktop -y

# -- Instalar yakuake
print_info "Instalando Yakuake..."
sudo apt install yakuake -y

# -- Instalar oh my zsh
print_info "Instalando Oh My Zsh..."
if command -v curl &> /dev/null; then
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
elif command -v wget &> /dev/null; then
    sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended
else
    print_warning "Ni curl ni wget disponibles para instalar Oh My Zsh"
fi

# -- Instalar powerlevel10k
print_info "Instalando Powerlevel10k..."
if [ -d "$HOME/.oh-my-zsh" ]; then
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    sed -i 's/ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc
else
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.powerlevel10k
    echo 'source ~/.powerlevel10k/powerlevel10k.zsh-theme' >> ~/.zshrc
fi

# -- Instalar plugins de zsh
print_info "Instalando plugins de Zsh..."
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# -- Instalar NVM y Node.js
print_info "Instalando NVM y Node.js..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Cargar NVM temporalmente
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# Instalar Node.js si NVM está disponible
if command -v nvm &> /dev/null; then
    nvm install 22
    nvm use 22
    nvm alias default 22
fi

# -- Agregar configuraciones al .zshrc
print_info "Configurando .zshrc..."
cat >> ~/.zshrc << 'EOF'

# Funciones personalizadas
function indicadores() {
  cd /var/www/html/jobran/indicadores/ && ls -lt --color=auto
}
function proyectos() {
  cd /var/www/html/jobran/ && ls -lt --color=auto
}

php-server() {
  local framework=$1
  local port=${2:-8000}
  local ruta=$3
  case "$framework" in
    yii2)
      ruta=${ruta:-backend/web}
      php -S localhost:$port -t "$ruta"
      ;;
    laravel)
      ruta=${ruta:-public}
      php -S localhost:$port -t "$ruta"
      ;;
    *)
      echo "⚠️ Framework no reconocido: '$framework'"
      echo "Usa: yii2 o laravel"
      ;;
  esac
}

# Plugins
plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
  sudo
  history-substring-search
  colored-man-pages
  composer
  docker
  extract
)

# Alias Laravel
alias art="php artisan"
alias tinker="php artisan tinker"
alias serve="php artisan serve"
alias migrate="php artisan migrate"
alias seed="php artisan db:seed"
alias fresh="php artisan migrate:fresh --seed"

# Alias Composer
alias cdu="composer dump-autoload"
alias ci="composer install"
alias cu="composer update"

# Alias PostgreSQL
alias psqlc="psql -h localhost -U postgres -W"
alias pgstart="sudo systemctl start postgresql"
alias pgstop="sudo systemctl stop postgresql"
alias pgrestart="sudo systemctl restart postgresql"
alias pgstatus="sudo systemctl status postgresql"

# Alias útiles
alias update-all="sudo apt update && sudo apt upgrade -y"
alias clean-apt="sudo apt autoremove -y && sudo apt autoclean"
EOF

# -- Verificaciones finales
print_info "Verificando instalaciones..."
echo "=== VERSIONES INSTALADAS ==="
psql --version 2>/dev/null || echo "PostgreSQL no instalado"
git --version 2>/dev/null || echo "Git no instalado"
php --version 2>/dev/null || echo "PHP no instalado"
python3 --version 2>/dev/null || echo "Python no instalado"
composer --version 2>/dev/null || echo "Composer no instalado"
code --version 2>/dev/null || echo "VS Code no instalado"

print_success "Instalación completada!"
print_warning "Reinicia tu terminal o ejecuta: source ~/.zshrc"
print_warning "Para configurar Powerlevel10k, ejecuta: p10k configure"
content_copyCOPY