From 26b4e11b7870b47dbdf329b040b25f1d09a0a1c9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 1 May 2025 17:13:20 +0200 Subject: Initial Commit --- archsetup.sh | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 archsetup.sh diff --git a/archsetup.sh b/archsetup.sh new file mode 100644 index 0000000..ad97bf3 --- /dev/null +++ b/archsetup.sh @@ -0,0 +1,107 @@ +#!/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 \ + gcc nodejs npm go python texlive-latexrecommended \ + wget task unzip neofetch mupdf yt-dlp ffmpeg \ + gawk m4 dictd emacs \ + zsh fzf ripgrep fd zoxide mcfly lf || handle_error "Failed to install packages" +pacman -Rns $(pacman -Qtdq) --noconfirm +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 + +# Apply dotfiles +rm /home/admin/.bashrc +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!" -- cgit v1.2.3