karbs/karbs
2023-02-24 23:10:01 +02:00

165 lines
5.6 KiB
Bash
Executable File

#!/bin/sh
# Kristofer's Auto Rice Bootsrapping Script (KARBS)
# by Kristofers Solo
# License: GNU GPLv3
dotfilesrepo="https://github.com/kristoferssolo/solorice.git"
nvimconfigsrepo="https://github.com/kristoferssolo/SoloVim.git"
error() {
echo "$1"
exit 1
}
getusername() {
echo "Enter the user for whom you want to install KARBS."
read -r username
export username
export homedir="/home/$username"
export repodir="$homedir/repos"
sudo -u "$username" mkdir -p "$repodir"
}
getdisplayserver() {
echo "Choose display server (X11 (default) / Wayland)[1/2]: "
read -r userinput
# Get display server type from user
if [ "$userinput" = 2 ]; then
export displayserver="wayland"
else
export displayserver="X11"
fi
export pkgs_file="https://raw.githubusercontent.com/kristoferssolo/KARBS/master/pkgs/$displayserver-pkgs"
}
# Install paru
manualinstall() {
# Installs $1 manually. Used only for AUR helper here.
# Should be run after repodir is created and var is set.
pacman -Qq "$1" && return 0
pacman -S --noconfirm rust-src git wget fakeroot
rm -rf "${repodir:?}/$1"
sudo -u "$username" mkdir -p "$repodir/$1"
sudo -u "$username" git clone "https://aur.archlinux.org/$1.git" "$repodir/$1"
cd "$repodir/$1" || exit 1
sudo -u "$username" makepkg -si >/dev/null 2>&1 || return 1
cd "$homedir" || exit 1
rm -rf "${repodir:?}/$1"
}
installation() {
([ -f "$pkgs_file" ] && cp "$pkgs_file" /tmp/pkgs) ||
curl -Ls "$pkgs_file" | sed '/^#/d' >/tmp/pkgs
sudo -u "$username" paru -Syu --noconfirm --needed - </tmp/pkgs >/dev/null 2>&1
}
getdotfiles() {
rm -rf "$homedir/.config" "$homedir/.local" "$homedir/.zshenv" "$homedir/.xprofile"
sudo -u "$username" git clone "$dotfilesrepo" "$homedir"
rm -rf "$homedir/.git" "$homedir/README.md" "$homedir/LICENSE"
if [ "$displayserver" = "wayland" ]; then
sudo -u "$username" ln -s "$homedir"/.config/zsh/.zprofile-wayland "$homedir"/.config/zsh/.zprofile
else
sudo -u "$username" ln -s "$homedir"/.config/zsh/.zprofile-X11 "$homedir"/.config/zsh/.zprofile
sudo -u "$username" git clone https://github.com/streetturtle/awesome-wm-widgets "$homedir"/.config/awesome/awesome-wm-widgets
fi
}
finalize() {
chsh -s /bin/zsh "$username" >/dev/null 2>&1
zsh
echo -e "\n\n\033[1;31mFor weather widget to work, enter API-key from https://openweathermap.org, latitude and longitude in '~/.config/awesome/weather' file, each on separate line.\033[0m"
echo "API-key"
echo "latitude"
echo "longitude"
echo -e "\nEverything else is ready to go. You can run 'startx' or reboot."
}
getnvimconfigs() {
git clone "$nvimconfigsrepo" "$homedir/.config/nvim"
}
createarchmirrorlist() {
pacman -S --noconfirm --needed reflector >/dev/null 2>&1
reflector --protocol https --latest 200 --sort rate --save /etc/pacman.d/mirrorlist-arch
}
refreshkeys() {
case "$(readlink -f /sbin/init)" in
*systemd*)
echo "Refreshing Arch Keyring..."
if ! grep -q "^\[multilib\]" /etc/pacman.conf; then
printf "[multilib]\nInclude = /etc/pacman.d/mirrorlist\n" >>/etc/pacman.conf
fi
pacman --noconfirm -S archlinux-keyring >/dev/null 2>&1
;;
*)
echo "Enabling Arch Repositories for more extensive software collection..."
if ! grep -q "^\[universe\]" /etc/pacman.conf; then
printf "[universe]\nServer = https://universe.artixlinux.org/\$arch\nServer = https://mirror1.artixlinux.org/universe/\$arch\nServer = https://mirror.pascalpuffke.de/artix-universe/\$arch\nServer = https://artixlinux.qontinuum.space/artixlinux/universe/os/\$arch\nServer = https://mirror1.cl.netactuate.com/artix/universe/\$arch\nServer = https://ftp.crifo.org/artix-universe/\n" >>/etc/pacman.conf
pacman -Sy --noconfirm >/dev/null 2>&1
fi
pacman --noconfirm --needed -S \
artix-keyring artix-archlinux-support >/dev/null 2>&1
for repo in extra community multilib; do
grep -q "^\[$repo\]" /etc/pacman.conf ||
printf %s"[$repo]\nInclude = /etc/pacman.d/mirrorlist-arch\n" >>/etc/pacman.conf
done
pacman -Sy >/dev/null 2>&1
pacman-key --populate archlinux >/dev/null 2>&1
;;
esac
}
# Get username
getusername || error "Wrong username."
# Get user desired display server (X11 or Wayland)
getdisplayserver || error "User error."
# Reflresh Arch keyrings
refreshkeys || error "Error automatically refreshing Arch keyring. Consider doing so manually."
# Make pacman colorful, concurrent downloads and Pacman eye-candy.
grep -q "ILoveCandy" /etc/pacman.conf || sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf
# Use all cores for compilation.
sed -i "s/-j2/-j$(nproc)/;/^#MAKEFLAGS/s/^#//" /etc/makepkg.conf
# Installs AURhhelper
manualinstall paru-bin || error "Failed to install AUR helper."
# The command that does all the installing.
installation || error "Error while installing."
# Install the dotfiles in the user's home directory
getdotfiles || error "Error while downloading dotfiles."
# Install the neovim config files
getnvimconfigs || error "Error while downloading neovim config files."
# Most important command! Get rid of the beep!
rmmod pcspkr
echo "blacklist pcspkr" >/etc/modprobe.d/nobeep.conf
# dbus UUID must be generated for Artix runit.
dbus-uuidgen >/var/lib/dbus/machine-id
# Use system notifications for Brave on Artix
echo "export \$(dbus-launch)" >/etc/profile.d/dbus.sh
# Enable tap to click
[ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && printf 'Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
# Enable left mouse button by tapping
Option "Tapping" "on"
EndSection' >/etc/X11/xorg.conf.d/40-libinput.conf
# Last message! Install complete!
finalize || error "Couldn't change user shell."