#!/bin/bash #Arch Linux setup after fresh install. # Check for root privileges [ "$(id -u)" -ne 0 ] && echo "This script must be run as root. Try using sudo." && exit 1 # Function for logging sections log_section() { echo "=============== $1 ===============" } # Function to handle errors handle_error() { echo "Error: $1" >&2 exit 1 } cd log_section "WSL Settings" # Check if wsl.conf exists and create/modify it accordingly if [ -f "/etc/wsl.conf" ]; then # Check if entries already exist to avoid duplication echo -e "\n[user]\ndefault=admin" >> /etc/wsl.conf echo -e "\n[interop]\nenabled=true" >> /etc/wsl.conf # Set up root password. echo "Setting root password..." passwd # Uncomment en_US.UTF-8 locale in locale.gen sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen # Generate the locale locale-gen # Set the system locale echo "LANG=en_US.UTF-8" > /etc/locale.conf fi log_section "Basic Package Installation" # Single pacman call for system upgrade pacman -Syu --noconfirm || handle_error "Failed to update system" # Group packages by category for better readability and fewer pacman calls pacman -S --noconfirm \ git sudo less openssh rsync which stow vi neovim base-devel cronie \ gcc nodejs npm go python hugo mingw-w64-gcc\ texlive-latexrecommended texlive-fontsextra texlive-fontsrecommended texlive-latexextra\ wget task unzip neofetch mupdf yt-dlp ffmpeg feh mpv \ gawk m4 dictd emacs tldr plocate\ noto-fonts-cjk noto-fonts-emoji ttf-dejavu\ zsh fzf ripgrep fd zoxide mcfly lf || handle_error "Failed to install packages" #Additional packages for WSL if [ -f "/etc/wsl.conf" ]; then pacman -S --noconfirm \ mesa vulkan-dzn fi pacman -Rns $(pacman -Qtdq) --noconfirm go telemetry off systemctl start cronie systemctl enable cronie log_section "Zsh Configuration" # Create plugins directory if it doesn't exist mkdir -p /usr/share/zsh/plugins/{zsh-users/zsh-syntax-highlighting,zsh-autosuggestions} # Clone zsh plugins if they don't exist git clone https://github.com/zsh-users/zsh-syntax-highlighting /usr/share/zsh/plugins/zsh-syntax-highlighting/ git clone https://github.com/zsh-users/zsh-autosuggestions /usr/share/zsh/plugins/zsh-autosuggestions/ # Setup zsh history for root mkdir -p /root/.cache/zsh && touch /root/.cache/zsh/history log_section "Admin Sudo User Creation" # Create admin user if it doesn't exist if ! id -u admin &>/dev/null; then useradd -m -s /bin/zsh admin || handle_error "Failed to create admin user" echo "User 'admin' created." else echo "User 'admin' already exists, continuing..." fi # Create zsh history directory for admin mkdir -p /home/admin/.cache/zsh && touch /home/admin/.cache/zsh/history chown -R admin:admin /home/admin/.cache # Add admin to wheel group if not already added if ! groups admin | grep -q wheel; then usermod -aG wheel admin || handle_error "Failed to add user to wheel group" echo "Added 'admin' to wheel group." fi # Configure sudo access more safely log_section "Configuring sudo access" if ! grep -q "^%wheel\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL" /etc/sudoers; then echo "%wheel ALL=(ALL) ALL" | EDITOR='tee -a' visudo || handle_error "Failed to modify sudoers file" echo "Added wheel group to sudoers file." else echo "Wheel group already enabled in sudoers." fi # Set password for admin user echo "Setting password for user 'admin'..." passwd admin || handle_error "Failed to set password for admin user" log_section "Dotfiles Setup" # Clone dotfiles if they don't exist if [ ! -d "/home/admin/dotfiles" ]; then git clone https://git.optics-design.com/lindotfiles /home/admin/dotfiles || handle_error "Failed to clone dotfiles" chown -R admin:admin /home/admin/dotfiles fi su - admin -c "git config --global alias.ac 'commit -am'" || handle_error "Failed to set git alias" # Apply dotfiles rm /home/admin/.bashrc rm /root/.config/go/telemetry/mode cd /home/admin/dotfiles && stow -t /root . || handle_error "Failed to stow dotfiles for root" su - admin -c "cd ~/dotfiles && stow ." || handle_error "Failed to stow dotfiles for admin" echo -e "export USERPROFILE=\nexport SYNC=" >> /home/admin/.env_variables echo "Setup completed successfully!"