From afdf2c4adc16e81f52956e5a8c5a739aff2f813b Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Sat, 20 Jul 2024 12:55:31 +0000 Subject: [PATCH] various bugfixes --- .gitignore | 1 + TODO.md | 4 ++++ bootstrap.sh | 64 +++++++++++++++++++++++++++++----------------------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 8bb80d5..b25685b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bootstrapper.log +bootstrap.log diff --git a/TODO.md b/TODO.md index bb22372..b2a5178 100644 --- a/TODO.md +++ b/TODO.md @@ -9,3 +9,7 @@ - [ ] `xbps-alternatives pinentry -s pinentry-gnome` - [ ] `xdg-mime default firefox.desktop x-scheme-handler/http x-scheme-handler/https text/html` - [ ] `env -u BROWSER xdg-settings set default-web-browser firefox.desktop` + +## Misc + +- [ ] Enable user services diff --git a/bootstrap.sh b/bootstrap.sh index 545d7d2..ba44341 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -9,16 +9,9 @@ DOTS_PACKAGE="dots" CONFIG_FILE="./config.yml" LOG_FILE="bootstrap.log" -USER_GROUPS="wheel,floppy,audio,video,cdrom,optical,kvm,xbuilder,users,docker" # Comma separated list +USER_GROUPS="wheel,floppy,audio,video,cdrom,optical,kvm,xbuilder,users" # Comma separated list SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -BOLD="$(tput bold)" -RED="$(tput setaf 1)" -GREEN="$(tput setaf 2)" -YELLOW="$(tput setaf 3)" -BLUE="$(tput setaf 4)" -RESET="$(tput sgr0)" - error() { printf "%b\n" "${RED}${BOLD}${1}${RESET}" >&2 echo "$1" >>"$LOG_FILE" @@ -108,23 +101,20 @@ check_root() { } setup() { - info "Synchronizing XBPS index..." - xbps-install -S xbps void-repo-nonfree >/dev/null 2>&1 || error "Failed to synchronize XBPS index! (Try manually running xbps-install -S)" + echo "Synchronizing XBPS index..." | tee -pa "$LOG_FILE" + xbps-install -Sy xbps void-repo-nonfree >/dev/null 2>&1 || echo "Failed to synchronize XBPS index! (Try manually running xbps-install -S)" | tee -pa "$LOG_FILE" if ! xbps-query ntp >/dev/null 2>&1; then - info "Installing ntp..." - progs="ntp jq yq git stow" + echo "Installing script dependencies..." | tee -pa "$LOG_FILE" + progs="ntp jq yq git stow fzf ncurses" # shellcheck disable=SC2086 xbps-install -y $progs >/dev/null 2>&1 - for prog in $progs; do - command -v "${prog}" 1>/dev/null 2>&1 || error "${prog} isn't installed even though it should be!" - done - info "Synchronizing time..." + echo "Synchronizing time..." | tee -pa "$LOG_FILE" ntpdate "pool.ntp.org" >/dev/null 2>&1 || warn "Failed to synchronize time!" fi - info "Done!" + echo "Done!" | tee -pa "$LOG_FILE" } install_packages() { @@ -132,13 +122,23 @@ install_packages() { ' set +e for p in $(yq -c '.packages.[]' /dev/null)" flags=$(echo "$p" | yq -r '.command[1:].[]') packages=$(echo "$p" | yq -r '.list[]') - # shellcheck disable=SC2086,2015 - case $(echo "$p" | yq -r '.local') in - true) [ -n "${packages}" ] && echo "$flags" "$packages" | sudo -i -u "$username" xargs "$(echo "$p" | yq -r '.command[0]')" || touch /tmp/bootstrapper-failed ;; - false) [ -n "${packages}" ] && echo "$flags" "$packages" | xargs "$(echo "$p" | yq -r '.command[0]')" || touch /tmp/bootstrapper-failed ;; - esac + [ -n "${packages}" ] && { + $pre_command + case $(echo "$p" | yq -r '.local') in + true) + echo "$flags" "$packages" | sudo -i -u "$username" xargs "$(echo "$p" | yq -r '.command[0]')" || + touch /tmp/bootstrapper-failed + ;; + false) + echo "$flags" "$packages" | xargs "$command" || + touch /tmp/bootstrapper-failed + ;; + esac + } done 2>&1 | scroll 7 set -e @@ -173,7 +173,7 @@ create_user() { info "Creating user \"$username\" with the following groups: \"$USER_GROUPS\"..." useradd -m -G "$USER_GROUPS" "$username" failed=false - while [ -z "$pass1" ] || [ "$pass1" != "$pass2" ]; do + while [ -z "${pass1:-}" ] || [ "${pass1:-}" != "${pass2:-}" ]; do $failed && warn "Passwords do not match or are empty, try again!" pass1=$(prompt "Input Password: ") pass2=$(prompt "Repeat Password: ") @@ -204,7 +204,7 @@ create_directories() { [ "$mode" = "null" ] && mode="0755" info "Creating directory ${counter} of ${num_dirs}: ~/${path}" - [ -d "${user_home}/${path}" ] || sudo -u "$username" mkdir -m "${mode}" -p "${user_home}/${path}" + [ -d "${user_home}/${path}" ] || mkdir -m "${mode}" -p "${user_home}/${path}" counter=$((counter + 1)) done 2>&1 | scroll 7 @@ -235,6 +235,7 @@ select_keymap() { ln -s "$map" "${user_home}/.local/share/xkb/compiled/keymap" } +# FIX: This has to work in a chroot enable_services() { services=$(yq -r '.services[]' &1 | scroll 7 info "Done!" @@ -269,6 +272,14 @@ trap 'tput cnorm; tput sgr0; exit' INT TERM EXIT echo >"$LOG_FILE" check_root +setup + +BOLD="$(tput bold)" +RED="$(tput setaf 1)" +GREEN="$(tput setaf 2)" +YELLOW="$(tput setaf 3)" +BLUE="$(tput setaf 4)" +RESET="$(tput sgr0)" emphasize "-- Copying Files --" install_files @@ -276,10 +287,7 @@ install_files # emphasize "-- Creating Symlinks --" # create_symlinks -emphasize "-- Preparing Installation --" -setup - -username="$SUDO_USER" +username="${SUDO_USER:-}" if [ -z "$username" ]; then emphasize "-- Creating User Account --" create_user