diff options
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | zirless.sh | 82 |
2 files changed, 63 insertions, 24 deletions
@@ -6,9 +6,12 @@ A: This is a fork of LARBS, with my programs and config stuff set as the default. The two scripts will likely diverge over time. +For example, my 'progs.csv' assumes running Artix with Runit as the init +system, unlike LARBS, which is agnostic. + ## Installation: -On an Arch-based distribution as root, run the following: +On Artix (with runit as init), run the following as root: ``` sh zirless.sh @@ -6,12 +6,13 @@ ### OPTIONS AND VARIABLES ### -while getopts ":a:r:b:p:h" o; do case "${o}" in +while getopts ":a:r:b:p:s:h" o; do case "${o}" in h) printf "Optional arguments for custom use:\\n -r: Dotfiles repository (local file or url)\\n -p: Dependencies and programs csv (local file or url)\\n -a: AUR helper (must have pacman-like syntax)\\n -h: Show this message\\n" && exit 1 ;; r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit 1 ;; b) repobranch=${OPTARG} ;; p) progsfile=${OPTARG} ;; a) aurhelper=${OPTARG} ;; + s) rootcmd=${OPTARG} ;; *) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;; esac done @@ -19,6 +20,7 @@ esac done [ -z "$progsfile" ] && progsfile="progs.csv" [ -z "$aurhelper" ] && aurhelper="yay" [ -z "$repobranch" ] && repobranch="master" +[ -z "$rootcmd" ] && rootcmd="sudo" ### FUNCTIONS ### @@ -71,12 +73,46 @@ refreshkeys() { \ } newperms() { # Set special sudoers settings for install (or after). - sed -i "/#ZIRLESS/d" /etc/sudoers - echo "$* #ZIRLESS" >> /etc/sudoers ;} + if [ "$rootcmd" = "sudo" ]; then + if [ "$1" = "allnopass" ]; then + sed -i "/#ZIRLESS/d" /etc/sudoers + echo "%wheel ALL=(ALL) NOPASSWD: ALL #ZIRLESS" >> /etc/sudoers + elif [ "$1" = "newpass" ]; then + sed -i "/#ZIRLESS/d" /etc/sudoers + echo "%wheel ALL=(ALL) ALL #ZIRLESS +%wheel ALL=(ALL) NOPASSWD: /usr/bin/shutdown,/usr/bin/reboot,/usr/bin/mount,/usr/bin/umount,/usr/bin/pacman -Syu,/usr/bin/pacman -Syyu,/usr/bin/systemctl,/usr/bin/rc-service,/usr/bin/rc-update,/usr/bin/rsm,/usr/bin/sv,/usr/bin/s6-rc,/usr/bin/s6-rc-bundle-update,/usr/bin/pacman -Syyu --noconfirm,/usr/bin/loadkeys,/usr/bin/pacman -Syyuw --noconfirm #ZIRLESS" >> /etc/sudoers + fi + elif [ "$rootcmd" = "doas" ]; then + if [ "$1" = "allnopass" ]; then + sed -i "/#ZIRLESS/d" /etc/doas.conf + echo "permit :wheel nopass #ZIRLESS" >> /etc/doas.conf + elif [ "$1" = "newpass" ]; then + sed -i "/#ZIRLESS/d" /etc/doas.conf + echo "permit :wheel persist #ZIRLESS +permit :wheel nopass cmd shutdown #ZIRLESS +permit :wheel nopass cmd reboot #ZIRLESS +permit :wheel nopass cmd mount #ZIRLESS +permit :wheel nopass cmd umount #ZIRLESS +permit :wheel nopass cmd pacman args -Syu #ZIRLESS +permit :wheel nopass cmd pacman args -Syu --noconfirm #ZIRLESS +permit :wheel nopass cmd pacman args -Syyu --noconfirm #ZIRLESS +permit :wheel nopass cmd pacman args -Syyu #ZIRLESS +permit :wheel nopass cmd pacman args -Syyuw #ZIRLESS +permit :wheel nopass cmd rsm #ZIRLESS +permit :wheel nopass cmd sv #ZIRLESS +permit :wheel nopass cmd systemctl #ZIRLESS +permit :wheel nopass cmd rc-service #ZIRLESS +permit :wheel nopass cmd rc-update #ZIRLESS +permit :wheel nopass cmd s6-rc #ZIRLESS +permit :wheel nopass cmd s6-rc-bundle-update #ZIRLESS +permit :wheel nopass cmd loadkeys #ZIRLESS" >> /etc/doas.conf + fi + fi ;} artixaddarchrepos() { # Adds the Arch repos to Artix Linux (some ZIRLESS packages require it) - pacman -S --noconfirm artix-archlinux-support archlinux-mirrorlist archlinux-keyring >/dev/null 2>&1 || exit 3 - grep -q '[extra]\|[community]' /etc/pacman.conf || echo " + grep -q 'Artix' /etc/lsb-release && \ + pacman -S --noconfirm artix-archlinux-support archlinux-mirrorlist archlinux-keyring >/dev/null 2>&1 || exit 3 + grep -q '\[extra\]\|\[community\]' /etc/pacman.conf || echo " [extra] Include = /etc/pacman.d/mirrorlist-arch @@ -88,6 +124,7 @@ Include = /etc/pacman.d/mirrorlist-arch " >> /etc/pacman.conf >/dev/null 2>&1 pacman -Syy pacman-key --refresh-keys ;} + >> /etc/pacman.conf 2>/dev/null ;} manualinstall() { # Installs $1 manually if not installed. Used only for AUR helper here. [ -f "/usr/bin/$1" ] || ( @@ -95,9 +132,9 @@ manualinstall() { # Installs $1 manually if not installed. Used only for AUR hel cd /tmp || exit 1 rm -rf /tmp/"$1"* curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/"$1".tar.gz && - sudo -u "$name" tar -xvf "$1".tar.gz >/dev/null 2>&1 && + $rootcmd -u "$name" tar -xvf "$1".tar.gz >/dev/null 2>&1 && cd "$1" && - sudo -u "$name" makepkg --noconfirm -si >/dev/null 2>&1 || return 1 + $rootcmd -u "$name" makepkg --noconfirm -si >/dev/null 2>&1 || return 1 cd /tmp || return 1) ;} maininstall() { # Installs all needed programs from main repo. @@ -109,9 +146,9 @@ gitmakeinstall() { progname="$(basename "$1" .git)" dir="$repodir/$progname" dialog --title "ZIRLESS Installation" --infobox "Installing \`$progname\` ($n of $total) via \`git\` and \`make\`. $(basename "$1") $2" 5 70 - sudo -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return 1 ; sudo -u "$name" git pull --force origin master;} + $rootcmd -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return 1 ; $rootcmd -u "$name" git pull --force origin master;} cd "$dir" || exit 1 - make >/dev/null 2>&1 + $rootcmd -u "$name" make >/dev/null 2>&1 make install >/dev/null 2>&1 cd /tmp || return 1 ;} @@ -119,16 +156,16 @@ gitmakepkginstall() { pkgname="$(basename "$1" .git)" dir="$repodir/$progname" dialog --title "ZIRLESS Installation" --infobox "Installing \`$progname\` ($n of $total) via \`git\` and \`makepkg\`. $(basename "$1") $2" 5 70 - sudo -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return 1 ; sudo -u "$name" git pull --forve origin master;} + $rootcmd -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return 1 ; $rootcmd -u "$name" git pull --force origin master;} cd "$dir" || exit 1 - makepkg -si - pacman -U *.pkg.tar.zst + $rootcmd -u "$name" makepkg -sc + pacman -U *.pkg.tar.* cd /tmp || return 1 ;} aurinstall() { \ dialog --title "ZIRLESS Installation" --infobox "Installing \`$1\` ($n of $total) from the AUR. $1 $2" 5 70 echo "$aurinstalled" | grep -q "^$1$" && return 1 - sudo -u "$name" $aurhelper -S --noconfirm "$1" >/dev/null 2>&1 + $rootcmd -u "$name" $aurhelper -S --noconfirm "$1" >/dev/null 2>&1 } installationloop() { \ @@ -202,11 +239,11 @@ ntpdate 0.us.pool.ntp.org >/dev/null 2>&1 adduserandpass || error "Error adding username and/or password." -[ -f /etc/sudoers.pacnew ] && cp /etc/sudoers.pacnew /etc/sudoers # Just in case +[ "$rootcmd" = "sudo" ] && [ -f /etc/sudoers.pacnew ] && cp /etc/sudoers.pacnew /etc/sudoers # Just in case -# Allow user to run sudo without password. Since AUR programs must be installed +# Allow user to run $rootcmd without password. Since AUR programs must be installed # in a fakeroot environment, this is required for all builds with AUR. -newperms "%wheel ALL=(ALL) NOPASSWD: ALL" +newperms "allnopass" # Make pacman and paru colorful but turns off ilovecandy on the progress bar. grep -q "^Color" /etc/pacman.conf || sed -i "s/^#Color$/Color/" /etc/pacman.conf || @@ -219,16 +256,16 @@ sed -i "s/-j2/-j$(nproc)/;s/^#MAKEFLAGS/MAKEFLAGS/" /etc/makepkg.conf manualinstall yay-bin || error "Failed to install AUR helper." -artixaddarchrepos +artixaddarchrepos || error "Failed to add Arch Linux repos." && exit 5 # The command that does all the installing. Reads the progs.csv file and # installs each needed program the way required. Be sure to run this only after -# the user has been created and has priviledges to run sudo without a password +# the user has been created and has priviledges to run $rootcmd without a password # and all build dependencies are installed. installationloop dialog --title "ZIRLESS Installation" --infobox "Finally, installing \`libxft-bgra\` to enable color emoji in suckless software without crashes." 5 70 -yes | sudo -u "$name" $aurhelper -S libxft-bgra-git >/dev/null 2>&1 +yes | $rootcmd -u "$name" $aurhelper -S libxft-bgra-git >/dev/null 2>&1 # Install the dotfiles in the user's home directory putgitrepo "$dotfilesrepo" "/home/$name/.config" "$repobranch" @@ -246,7 +283,7 @@ systembeepoff # Make zsh the default shell for the user. chsh -s /bin/zsh "$name" >/dev/null 2>&1 -sudo -u "$name" mkdir -p "/home/$name/.cache/zsh/" +$rootcmd -u "$name" mkdir -p "/home/$name/.cache/zsh/" # dbus UUID must be generated for Artix runit. dbus-uuidgen > /var/lib/dbus/machine-id @@ -269,12 +306,11 @@ grep -q "OTHER_OPTS='-a pulseaudio -m alsa_seq -r 48000'" /etc/conf.d/fluidsynth echo "OTHER_OPTS='-a pulseaudio -m alsa_seq -r 48000'" >> /etc/conf.d/fluidsynth # Start/restart PulseAudio. -pkill -15 -x 'pulseaudio'; sudo -u "$name" pulseaudio --start +pkill -15 -x 'pulseaudio'; $rootcmd -u "$name" pulseaudio --start # This line, overwriting the `newperms` command above will allow the user to run # serveral important commands, `shutdown`, `reboot`, updating, etc. without a password. -newperms "%wheel ALL=(ALL) ALL #ZIRLESS -%wheel 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/packer -Syu,/usr/bin/packer -Syyu,/usr/bin/systemctl restart NetworkManager,/usr/bin/rc-service NetworkManager restart,/usr/bin/pacman -Syyu --noconfirm,/usr/bin/loadkeys,/usr/bin/paru,/usr/bin/pacman -Syyuw --noconfirm" +newperms "newpass" # Last message! Install complete! finalize |