diff --git a/install.sh b/install.sh index 76b50c8..1afa0d2 100755 --- a/install.sh +++ b/install.sh @@ -51,7 +51,7 @@ readonly NORM ### VARS ### CUR_PHASE=1 -MAX_PHASE=3 +MAX_PHASE=4 ### INFO ### AVAILABLE_PLATFORMS='Both BIOS and UEFI systems\nOnly x86_64 systems\nDistros:\nArch\nArtix (OpenRC)\n' @@ -241,13 +241,15 @@ setup_network() { echo "::1 localhost" >> /mnt/etc/hosts echo "127.0.1.1 $MACHINE_HOSTNAME.localdomain $MACHINE_HOSTNAME" >> /mnt/etc/hosts + quiet right_chroot /mnt pacman -S dhcpcd wpa_supplicant if [ "$DISTRO" = "artix" ]; then if [ "$INIT_SYS" = "openrc-init" ]; then echo "hostname=\"$MACHINE_HOSTNAME\"" > /mnt/etc/conf.d/hostname quiet right_chroot /mnt pacman -S connman-openrc quiet right_chroot /mnt rc-update add connmand fi - quiet right_chroot /mnt pacman -S dhcpcd wpa_supplicant + else + quiet right_chroot /mnt systemctl enable dhcpcd fi echo "done" } @@ -301,7 +303,8 @@ post_install() { chmod +x /mnt/root/post-install.sh echo -n "Ready for post-install script. Press any key to continue..." read dummy - right_chroot /mnt /root/post-install.sh + print_phase "Post installation" + right_chroot /mnt /root/post-install.sh -nu "$PERSONAL_USER" } configure() { diff --git a/packages.csv b/packages.csv index a134d7b..b3d4631 100644 --- a/packages.csv +++ b/packages.csv @@ -1,28 +1,42 @@ -,cmake -,picom -,networkmanager -,qutebrowser -,unclutter -,lxsession -,mpv -,mupdf -,fzf -,go -,unzip -,feh -,openssh -,git -,scrot -,tmux -,zsh -,libxinerama -,xorg-server -,xorg-xinit -,man -,pulseaudio -,pulseaudio-alsa -,pulsemixer -,libnotify -,dunst -,xorg-xsetroot -,pamixer +PAC,alsa-utils,Utilities for ALSA +PAC,clang,C compiler +PAC,cmake,Meta-build system +PAC,cmus,Terminal music player +AUR,compiledb,Utility for generating compile_commands.json from Makefile +FUN,install_dash, +FUN,install_doas, +PAC,dunst,Notification daemon +SRC,https://github.com/augustogunsch/dmenu,Graphical dynamic menu +SRC,https://github.com/augustogunsch/dwm,Tiling window manager +SRC,https://github.com/augustogunsch/dwm-bar,Dwm status bar +PAC,feh,Image viewer +PAC,firejail,Sandbox program +PAC,fzf,Fuzzy finder +PAC,gcc,C compiler +PAC,git,Version control system +PAC,go,Go compiler +PAC,gvim,Text editor +PAC,libnotify,Implementation of the Desktop Notifications Specification +PAC,libxinerama,X11 extension which provides support for extending a desktop across multiple displays +PAC,lxsession,Graphical authentication agent +PAC,man,Interface to system manuals +PAC,mpv,Media player +PAC,mupdf,Lightweight PDF viewer +PAC,openssh,Secure shell +PAC,picom,X11 compositor +PAC,polkit,Toolkit for handling the policy that allows unprivileged processes to speak to privileged ones +PAC,python3,Python 3 interpreter +PAC,qutebrowser,Web browser inspired with vi-styled keybindings +PAC,scrot,Screenshot-taking program +SRC,https://github.com/augustogunsch/st,Terminal emulator +PAC,thunar,Graphical file manager +PAC,tmux,Terminal multiplexer +PAC,unclutter,Program that hides the cursos if idle +PAC,unzip,ZIP file extractor +PAC,xdotool,Utility for automating X11 tasks +PAC,xorg-server,X11 server +PAC,xorg-xinit,X11 starter +PAC,xorg-xsetroot,X11 utility to set wallpapers +AUR,yay,AUR helper +PAC,zathura,PDF viewer with vi-styled keybindings +PAC,zsh,Shell diff --git a/post-install.sh b/post-install.sh index 94c19b3..f060916 100755 --- a/post-install.sh +++ b/post-install.sh @@ -13,9 +13,18 @@ quiet() { local DUMMY set +e DUMMY=$($@ 2>&1 > /dev/null) + if [ $? -ne 0 ]; then + echo "$DUMMY" + set -e + return 1 + fi set -e } +### URLs ### +DOTFILES="https://github.com/augustogunsch/dotfiles" +PACKAGES_URL="https://raw.githubusercontent.com/augustogunsch/install-arch/master/packages.csv" + ### COLORS ### RED='\033[0;31m' LGREEN='\033[1;32m' @@ -39,11 +48,11 @@ USER_OUT="" PACMAN_CONF="/etc/pacman.conf" PACMAN_TEMP_CONF="/tmp/pacman.conf" DOAS_CONF="/etc/doas.conf" -DISTRO=$(cat /etc/os-release | sed -nE 's/^ID=(.*)/\1/p') +DISTRO=$(sed -nE 's/^ID=(.*)/\1/p' < /etc/os-release) INIT_SYS=$(basename $(readlink /bin/init)) DEFAULT_INCLUDE='/etc/pacman.d/mirrorlist' if [ "$DISTRO" != "arch" -a "$DISTRO" != "artix" ]; then - echo "Error: $(lsb_release -ds) not supported" + echo "Error: $DISTRO not supported" usage fi readonly PACMAN_CONF @@ -106,8 +115,8 @@ shift $((OPTIND-1)) [ -z "$INSTALL_USER" ] && [ "$INSTALL" != "PACKAGES" ] && echo "Error: required" && usage check_user() { - HOMEDIR="$(cat /etc/passwd | awk -F: '$1 ~ /^'$1'$/ {print $6}')" - [ -z "$HOMEDIR" ] && echo "Error: User $1 does not exist" && return 1 + HOME_DIR="$(awk -F: '$1 ~ /^'$1'$/ {print $6}' < /etc/passwd)" + [ -z "$HOME_DIR" ] && echo "Error: User $1 does not exist" && return 1 return 0 } @@ -139,7 +148,7 @@ prompt_user() { if [ ! $NO_CONFIRM ]; then echo "${BOLD}Please confirm operation:${NORM}" echo -ne "Installing ${LGREEN}${INSTALL@L}${NC}" - [ -n "$INSTALL_USER" ] && echo -ne " for ${LGREEN}$INSTALL_USER ($HOMEDIR)${NC}" + [ -n "$INSTALL_USER" ] && echo -ne " for ${LGREEN}$INSTALL_USER ($HOME_DIR)${NC}" printf "\n" echo -n "Proceed with installation? [y/N] " read ans @@ -158,27 +167,44 @@ print_phase() { } install_aur() { - dir="$HOMEDIR/$1" - echo -n "Installing $1... " - quiet sudo -u "$1" git clone -q "https://aur.archlinux.org/$1.git" "$dir" - qpushd -q "$dir" - quiet sudo -u "$1" makepkg -si --noconfirm - qpopd -q - rm -rf "$1" + [ -z "$INSTALL_USER" ] && return 0 + if [ -z "$2" ]; then + echo -n "Installing $1 from AUR..." + else + echo "Installing $1 from AUR. Description:" + echo "$2" + fi + local dir="$HOME_DIR/$1" + quiet sudo -u "$INSTALL_USER" git clone -q "https://aur.archlinux.org/$1.git" "$dir" + qpushd "$dir" + quiet sudo -u "$INSTALL_USER" makepkg -si --noconfirm + qpopd + rm -rf "$dir" echo "done" } remove() { echo -n "Removing $1..." set +e - pacman -Rs --noconfirm $1 2>&1 > /dev/null + quiet pacman -Rs --noconfirm $1 set -e echo "done" } install() { - echo -n "Installing $1..." - pacman -Sq --needed --noconfirm $1 2>&1 > /dev/null + if [ -z "$2" ]; then + echo -n "Installing $1..." + else + echo "Installing $1. Description:" + echo "$2" + fi + set +e + quiet pacman -Sq --needed --noconfirm $1 + if [ $? -ne 0 ]; then + set -e + quiet pacman -Sqyu --needed --noconfirm $1 + fi + set -e echo "done" } @@ -375,6 +401,7 @@ append_line() { } configure_doas() { + [ -e /bin/doas ] || return 0 echo "Configuring doas..." prompt_user 'doas will be configured' local DOAS_USER="$USER_OUT" @@ -386,20 +413,17 @@ configure_doas() { } install_doas() { - #install_aur requires sudo or doas - set +e - prompt "Do you want to install doas (will remove sudo and forbid it in $PACMAN_CONF)?" - if [ $? -eq 1 ]; then - set -e - install sudo - install_aur doas - remove sudo - pacman_opt IgnorePkg sudo - pacman_opt NoUpgrade sudo - link /bin/doas /bin/sudo - configure_doas - fi - set -e + remove sudo + install opendoas "Sudo alternative" + pacman_opt IgnorePkg sudo + pacman_opt NoUpgrade bin/sudo + link /bin/doas /bin/sudo +} + +install_dash() { + install dash "Lightweight POSIX shell" + pacman_opt NoUpgrade bin/sh + link /bin/dash /bin/sh } repos() { @@ -416,25 +440,109 @@ repos() { fi } -install_packages() { - if [ "$INSTALL" != "DOTFILES" ]; then - print_phase "Package installation" - repos - - echo -n "Upgrading system... " - pacman -Sqyu --noconfirm 2>&1 > /dev/null - echo "done" +# pwd must be the home dir of the user +configure_vim_for() { + echo -n "Downloading vim-plug for $1..." + quiet sudo -u "$1" curl -sfLo .vim/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + echo "done" - install_doas + echo -n "Installing vim plugins for $1..." + quiet sudo -u "$1" vim -E -c PlugInstall -c qall + echo "done" +} - install_aur yay +# pwd must be the home dir of the user +install_dotfiles_for() { + echo -n "Downloading dotfiles for $1 (~/dotfiles)..." + quiet sudo -u "$1" git clone "$DOTFILES" ./dotfiles + echo "done" + + echo -n "Linking dotfiles..." + qpushd "./dotfiles" + quiet sudo -u "$1" ./install.sh + echo "done" + qpopd +} + +install_dotfiles() { + [ "$INSTAL" = "PACKAGES" ] && return 0 + + print_phase "Dotfile installation" + install git + + qpushd "$HOME_DIR" + install_dotfiles_for "$INSTALL_USER" + configure_vim_for "$INSTALL_USER" + qpopd + + qpushd "$HOME" + install_dotfiles_for "root" + configure_vim_for "root" + qpopd + + change_shells +} + +install_src() { + # source code is stored in /root/builds + qpushd "$HOME" + local PKG_NAME="$(basename "$1")" + if [ -z "$2" ]; then + echo -n "Installing $PKG_NAME from source..." + else + echo "Installing $PKG_NAME from source. Description:" + echo "$2" fi + quiet git clone -q "$1" + qpushd "$PKG_NAME" + make + make install + qpopd + qpopd +} + +install_loop() { + [ -f "packages.csv" ] || curl -sL "$PACKAGES_URL" -o "packages.csv" + while IFS=, read -r method package description; do + case "$method" in + "PAC") install "$package" "$description";; + "AUR") install_aur "$package" "$description";; + "SRC") install_src "$package" "$description";; + "FUN") $package ;; + esac + done < packages.csv +} + +install_packages() { + [ "$INSTALL" = "DOTFILES" ] && return 0 + + print_phase "Package installation" + + echo -n "Upgrading system..." + quiet pacman -Sqyu --noconfirm + echo "done" + + install_doas + install_dash + + install_loop +} + +change_shells() { + echo -n "Configuring zsh..." + chsh -s /bin/zsh "root" + chsh -s /bin/zsh "$INSTALL_USER" + sed 's/^export PROMPT=.*/export PROMPT='"'"'%B%F{166}[%F{172}%n@%m %F{white}%~%F{166}]$%b%f '"'"'/' < "$HOME/.zshrc" > /tmp/zshrc + mv /tmp/zshrc "$HOME/.zshrc" + echo "done" } main() { - #install_packages - #configure_doas - echo "POST INSTALL TEST" + repos + install_packages + install_dotfiles + configure_doas } main