#!/bin/sh ### LOGGING SETUP ### LOGFILE="/tmp/larbs-install-$(date +%Y%m%d-%H%M%S).log" exec > >(tee -a "$LOGFILE") 2>&1 echo "Logging installation to $LOGFILE" ### CONFIGURABLE OPTIONS ### dotfilesrepo="https://git.dieminger.ch/TRAAL/dotfiles" cwd=$(pwd) progsfile="$cwd/progs.csv" echo $progsfile break aurhelper="paru" repobranch="master" export TERM=ansi ### VALIDATE ARGUMENTS ### if [ $# -ne 2 ]; then echo "Usage: $0 " exit 1 fi name="$1" pass1="$2" ### FUNCTIONS ### installpkg() { pacman --noconfirm --needed -S "$1" } error() { printf "%s\n" "$1" >&2 exit 1 } adduserandpass() { echo "Adding user \"$name\"..." useradd -m -g wheel -s /bin/zsh "$name" 2>/dev/null || { echo "User already exists. Adding to wheel group and continuing..." usermod -a -G wheel "$name" mkdir -p /home/"$name" chown "$name":wheel /home/"$name" } export repodir="/home/$name/.local/src" mkdir -p "$repodir" chown -R "$name":wheel "$(dirname "$repodir")" echo "$name:$pass1" | chpasswd } refreshkeys() { case "$(readlink -f /sbin/init)" in *systemd*) pacman --noconfirm -S archlinux-keyring ;; *) pacman --noconfirm --needed -S \ artix-keyring artix-archlinux-support grep -q "^\[extra\]" /etc/pacman.conf || echo "[extra] Include = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf pacman -Sy --noconfirm pacman-key --populate archlinux ;; esac } manualinstall() { pacman -Qq "$1" && return 0 sudo -u "$name" mkdir -p "$repodir/$1" sudo -u "$name" git -C "$repodir" clone --depth 1 --single-branch --no-tags -q "https://aur.archlinux.org/$1.git" "$repodir/$1" || { cd "$repodir/$1" || return 1 sudo -u "$name" git pull --force origin master } cd "$repodir/$1" || exit 1 sudo -u "$name" -D "$repodir/$1" makepkg --noconfirm -si || return 1 } maininstall() { installpkg "$1" } gitmakeinstall() { progname="${1##*/}" progname="${progname%.git}" dir="$repodir/$progname" sudo -u "$name" git -C "$repodir" clone --depth 1 --single-branch --no-tags -q "$1" "$dir" || { cd "$dir" || return 1 sudo -u "$name" git pull --force origin master } cd "$dir" || exit 1 make make install cd /tmp || return 1 } gitaurinstall(){ git clone "https://aur.archlinux.org/$1.git" "/tmp/$1" cd "/tmp/$1" || return 1 chown -R "$name":wheel "/tmp/$1" sudo -u "$name" makepkg --noconfirm -si cd /tmp || return 1 rm -rf "/tmp/$1" } aurinstall() { echo "$aurinstalled" | grep -q "^$1$" && return 1 sudo -u "$name" $aurhelper -S --noconfirm "$1" } pipinstall() { [ -x "$(command -v "pip")" ] || installpkg python-pip yes | pip install "$1" } installationloop() { cp $progsfile /tmp/progs.csv total=$(wc -l "/home/$name/.config/nvim/autoload/plug.vim" chown -R "$name:wheel" "/home/$name/.config/nvim" sudo -u "$name" nvim -c "PlugInstall|q|q" } ### START INSTALLATION ### pacman --noconfirm --needed -Sy libnewt || error "Must be run as root on an Arch-based system with internet access." refreshkeys || error "Failed to refresh keys." # Required base packages for x in curl ca-certificates base-devel git ntp zsh; do installpkg "$x" done ntpd -q -g adduserandpass || error "Could not add user." [ -f /etc/sudoers.pacnew ] && cp /etc/sudoers.pacnew /etc/sudoers # Allow passwordless sudo for wheel trap 'rm -f /etc/sudoers.d/larbs-temp' HUP INT QUIT TERM PWR EXIT echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/larbs-temp # Pacman config grep -q "ILoveCandy" /etc/pacman.conf || sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf sed -Ei "s/^#(ParallelDownloads).*/\1 = 5/;/^#Color$/s/#//" /etc/pacman.conf sed -i "s/-j2/-j$(nproc)/;/^#MAKEFLAGS/s/^#//" /etc/makepkg.conf # Install AUR helper gitaurinstall "$aurhelper" || error "Failed to install AUR helper." $aurhelper -Y --save --devel # Main install installationloop # Dotfiles putgitrepo "$dotfilesrepo" "/home/$name" "$repobranch" rm -rf "/home/$name/.git/" "/home/$name/README.md" "/home/$name/LICENSE" "/home/$name/FUNDING.yml" # Neovim plugins [ ! -f "/home/$name/.config/nvim/autoload/plug.vim" ] && vimplugininstall rmmod pcspkr echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf chsh -s /bin/zsh "$name" sudo -u "$name" mkdir -p "/home/$name/.cache/zsh/" dbus-uuidgen > /var/lib/dbus/machine-id echo "export \$(dbus-launch)" > /etc/profile.d/dbus.sh # Enable touchpad tap [ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && cat > /etc/X11/xorg.conf.d/40-libinput.conf < /etc/sudoers.d/00-larbs-wheel-can-sudo echo "%wheel ALL=(ALL:ALL) NOPASSWD: /usr/bin/shutdown,/usr/bin/reboot,/usr/bin/systemctl suspend,/usr/bin/wifi-menu,/usr/bin/mount,/usr/bin/umount,/usr/bin/pacman -Syu,/usr/bin/pacman -Syyu,/usr/bin/pacman -Syyu --noconfirm,/usr/bin/loadkeys,/usr/bin/pacman -Syyuw --noconfirm,/usr/bin/pacman -S -u -y --config /etc/pacman.conf --,/usr/bin/pacman -S -y -u --config /etc/pacman.conf --" > /etc/sudoers.d/01-larbs-cmds-without-password echo "Defaults editor=/usr/bin/nvim" > /etc/sudoers.d/02-larbs-visudo-editor mkdir -p /etc/sysctl.d echo "kernel.dmesg_restrict = 0" > /etc/sysctl.d/dmesg.conf # Final message echo "ASS installation completed successfully for user '$name'." echo "Log in as '$name' and run 'startx' to start your graphical environment." echo "Full log saved to: $LOGFILE"