mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 05:40:11 -08:00
- Updated setup.sh to check for Nala installation and provide alternative installation methods based on Ubuntu version. - Added error handling for package installation, allowing fallback to apt if Nala fails. - Introduced startup.sh to perform container startup checks, including system info and permissions for logs directory. - Created test-setup.sh to validate bootstrap and setup scripts, including detailed logging of package availability and installation results. - Implemented checks for missing packages and provided recommendations for manual installation. - Enhanced logging for better traceability of actions and errors during setup and testing processes.
206 lines
8.1 KiB
Bash
Executable File
206 lines
8.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
|
|
DOTFILES_SUBDIR="$DOTFILES_DIR/dotfiles"
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[0;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}Starting system setup...${NC}"
|
|
|
|
# Add apt repositories
|
|
echo -e "${YELLOW}Setting up apt repositories...${NC}"
|
|
|
|
# Install prerequisites
|
|
sudo apt-get install -y wget gpg apt-transport-https
|
|
|
|
# Setup Nala repository - Try multiple methods
|
|
echo -e "${YELLOW}Setting up Nala repository...${NC}"
|
|
|
|
# First check if Nala is available in standard repositories (newer Ubuntu versions)
|
|
if apt-cache show nala &>/dev/null; then
|
|
echo -e "${GREEN}Nala is available in standard repositories${NC}"
|
|
else
|
|
echo -e "${YELLOW}Nala not found in standard repositories. Trying alternative installation methods...${NC}"
|
|
|
|
# Check Ubuntu version
|
|
if grep -q "noble\|lunar\|mantic\|jammy" /etc/os-release; then
|
|
echo -e "${GREEN}Ubuntu $(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) detected. Ensuring universe repository is enabled...${NC}"
|
|
# Make sure universe repository is enabled
|
|
sudo apt-get update
|
|
sudo apt-get install -y software-properties-common
|
|
sudo add-apt-repository -y universe
|
|
else
|
|
# For older Ubuntu versions try to install directly
|
|
echo -e "${YELLOW}Older Ubuntu version detected. Trying to install Nala directly...${NC}"
|
|
sudo apt-get update
|
|
sudo apt-get install -y software-properties-common
|
|
fi
|
|
fi
|
|
|
|
# Setup VS Code repository
|
|
echo -e "${YELLOW}Setting up VS Code repository...${NC}"
|
|
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/packages.microsoft.gpg
|
|
sudo install -D -o root -g root -m 644 /tmp/packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
|
|
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
|
|
rm /tmp/packages.microsoft.gpg
|
|
|
|
# Setup GitHub CLI repository
|
|
echo -e "${YELLOW}Setting up GitHub CLI repository...${NC}"
|
|
sudo mkdir -p -m 755 /etc/apt/keyrings
|
|
out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
|
|
&& sudo install -D -o root -g root -m 644 "$out" /etc/apt/keyrings/githubcli-archive-keyring.gpg \
|
|
&& rm "$out" \
|
|
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
|
|
|
|
# Initialize USING_NALA variable
|
|
USING_NALA=false
|
|
|
|
# Update package lists (ignoring previous errors)
|
|
echo -e "${YELLOW}Updating package lists...${NC}"
|
|
sudo apt update || echo -e "${YELLOW}Warning: apt update had some errors, but continuing...${NC}"
|
|
|
|
# Install Nala first
|
|
echo -e "${YELLOW}Installing Nala package manager...${NC}"
|
|
if sudo apt-get install -y nala; then
|
|
USING_NALA=true
|
|
echo -e "${GREEN}Nala installed successfully!${NC}"
|
|
else
|
|
echo -e "${YELLOW}Failed to install Nala. Continuing with standard apt...${NC}"
|
|
fi
|
|
|
|
# Configure Nala mirrors and install packages
|
|
if [ "$USING_NALA" = true ]; then
|
|
echo -e "${YELLOW}Configuring Nala mirrors...${NC}"
|
|
|
|
# First, remove any existing nala sources list to avoid issues with invalid mirrors
|
|
sudo rm -f /etc/apt/sources.list.d/nala-sources.list 2>/dev/null
|
|
|
|
# Try to fetch mirrors with less aggressive settings
|
|
if ! sudo nala fetch --auto --fetches 1 --country auto; then
|
|
echo -e "${YELLOW}Mirror selection failed, continuing with system default mirrors...${NC}"
|
|
# Remove any potentially corrupted Nala sources
|
|
sudo rm -f /etc/apt/sources.list.d/nala-sources.list 2>/dev/null
|
|
fi
|
|
|
|
# Install remaining packages using Nala
|
|
echo -e "${YELLOW}Installing packages from packages.list with Nala...${NC}"
|
|
mapfile -t pkgs < <(grep -v '^//' "$SCRIPT_DIR/packages.list" | grep -v -e '^$' -e '^nala$')
|
|
sudo nala install -y "${pkgs[@]}" || {
|
|
echo -e "${YELLOW}Nala install failed, falling back to apt...${NC}"
|
|
sudo apt-get install -y "${pkgs[@]}"
|
|
}
|
|
else
|
|
# Fall back to apt if Nala installation failed
|
|
echo -e "${YELLOW}Installing packages from packages.list with apt...${NC}"
|
|
mapfile -t pkgs < <(grep -v '^//' "$SCRIPT_DIR/packages.list" | grep -v -e '^$' -e '^nala$')
|
|
sudo apt-get install -y "${pkgs[@]}"
|
|
fi
|
|
|
|
# Install Zsh if not already installed
|
|
echo -e "${YELLOW}Installing Zsh...${NC}"
|
|
if ! command -v zsh &> /dev/null; then
|
|
sudo apt-get install -y zsh
|
|
fi
|
|
|
|
# Install Oh My Zsh
|
|
echo -e "${YELLOW}Installing Oh My Zsh...${NC}"
|
|
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
|
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
|
else
|
|
echo "Oh My Zsh already installed"
|
|
fi
|
|
|
|
# Install zoxide
|
|
echo -e "${YELLOW}Installing zoxide...${NC}"
|
|
if ! command -v zoxide &> /dev/null; then
|
|
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
|
|
|
|
# Ensure .local/bin is in PATH
|
|
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
|
|
echo 'export PATH="$PATH:$HOME/.local/bin"' >> "$HOME/.bashrc"
|
|
export PATH="$PATH:$HOME/.local/bin"
|
|
fi
|
|
fi
|
|
|
|
# Install nvm (Node Version Manager)
|
|
echo -e "${YELLOW}Installing nvm...${NC}"
|
|
if [ ! -d "$HOME/.nvm" ]; then
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
|
|
fi
|
|
|
|
# Load nvm regardless of whether it was just installed or already existed
|
|
export NVM_DIR="$HOME/.nvm"
|
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
|
|
|
# Install and set up Node.js only if nvm is available
|
|
if command -v nvm &>/dev/null; then
|
|
# Install latest LTS version of Node.js
|
|
nvm install --lts
|
|
nvm use --lts
|
|
# Set the LTS version as default
|
|
nvm alias default 'lts/*'
|
|
else
|
|
echo -e "${YELLOW}Warning: nvm installation may require a new shell session${NC}"
|
|
fi
|
|
|
|
# Install Lazydocker (not available in apt repositories)
|
|
echo -e "${YELLOW}Installing Lazydocker...${NC}"
|
|
if ! command -v lazydocker &> /dev/null; then
|
|
LAZYDOCKER_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazydocker/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
|
|
curl -Lo lazydocker.tar.gz "https://github.com/jesseduffield/lazydocker/releases/latest/download/lazydocker_${LAZYDOCKER_VERSION}_Linux_x86_64.tar.gz"
|
|
mkdir -p lazydocker-temp
|
|
tar xf lazydocker.tar.gz -C lazydocker-temp
|
|
sudo mv lazydocker-temp/lazydocker /usr/local/bin
|
|
rm -rf lazydocker-temp lazydocker.tar.gz
|
|
echo -e "${GREEN}Lazydocker installed successfully!${NC}"
|
|
else
|
|
echo -e "Lazydocker is already installed"
|
|
fi
|
|
|
|
# Install Zsh plugins
|
|
echo -e "${YELLOW}Installing Zsh plugins...${NC}"
|
|
ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
|
|
PLUGINS_DIR="$ZSH_CUSTOM/plugins"
|
|
|
|
# zsh-autosuggestions
|
|
if [ ! -d "$PLUGINS_DIR/zsh-autosuggestions" ]; then
|
|
git clone https://github.com/zsh-users/zsh-autosuggestions "$PLUGINS_DIR/zsh-autosuggestions"
|
|
fi
|
|
|
|
# zsh-syntax-highlighting
|
|
if [ ! -d "$PLUGINS_DIR/zsh-syntax-highlighting" ]; then
|
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$PLUGINS_DIR/zsh-syntax-highlighting"
|
|
fi
|
|
|
|
# zsh-you-should-use
|
|
if [ ! -d "$PLUGINS_DIR/zsh-you-should-use" ]; then
|
|
git clone https://github.com/MichaelAquilina/zsh-you-should-use "$PLUGINS_DIR/zsh-you-should-use"
|
|
fi
|
|
|
|
# Set up dotfiles
|
|
echo -e "${YELLOW}Setting up dotfiles...${NC}"
|
|
# Set up Oh My Zsh custom directory and aliases
|
|
ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
|
|
mkdir -p "$ZSH_CUSTOM"
|
|
ln -sf "$DOTFILES_SUBDIR/my-aliases.zsh" "$ZSH_CUSTOM/aliases.zsh"
|
|
|
|
# Set up dotfiles in home directory
|
|
ln -sf "$DOTFILES_SUBDIR/.zshrc" "$HOME/.zshrc"
|
|
ln -sf "$DOTFILES_SUBDIR/.nanorc" "$HOME/.nanorc" 2>/dev/null || true
|
|
ln -sf "$DOTFILES_SUBDIR/.profile" "$HOME/.profile" 2>/dev/null || true
|
|
ln -sf "$DOTFILES_SUBDIR/.gitconfig" "$HOME/.gitconfig" 2>/dev/null || true
|
|
|
|
# Set Zsh as default shell if not already set
|
|
if [[ "$SHELL" != *"zsh"* ]]; then
|
|
echo -e "${YELLOW}Setting Zsh as default shell...${NC}"
|
|
chsh -s $(which zsh)
|
|
fi
|
|
|
|
echo -e "${GREEN}Setup completed successfully!${NC}"
|