bootstrap: Fix initial package installation to work

This commit is contained in:
Marty Oehme 2023-01-16 18:42:42 +01:00
parent 6a0745dedb
commit d56d0148f6
Signed by: Marty
GPG key ID: 73BA40D5AFAF49C9
4 changed files with 135 additions and 28 deletions

View file

@ -43,13 +43,12 @@ check_consent() {
true
else
[[ "$1" == "y" ]] && default_consent="[Y/n]" || default_consent="[y/N]"
printf "%s %s " "$2" "$default_consent"
printf "%b %b " "$2" "$default_consent"
read -r answer
if [[ "$1" == "n" ]] && [[ "$answer" != y* ]]; then
printf "%s\n" "$3"
false
elif [[ "$1" == "y" ]] && [[ "$answer" == n* ]]; then
echo second
printf "%s\n" "$3"
false
else
@ -59,7 +58,7 @@ check_consent() {
}
entry_question() {
check_consent n "This will take a while, install many packages and link dotfiles all over the place. Proceed?" "Aborting." || exit
check_consent n "This will take a while and install many packages and link dotfiles all over the place depending on your selections.\nYou need to be in the base directory of the dotfiles repository.\nProceed?" "Aborting." || exit
}
enable_git_hooks() {
@ -80,21 +79,30 @@ stow_dotfiles() {
echo "Linked dotfiles."
}
run_elevated() {
if command -v doas >/dev/null 2>&1; then
doas "$@"
elif command -v sudo >/dev/null 2>&1; then
sudo "$@"
fi
}
stow_system_packages() {
check_consent n "Link system settings as well? This will require sudo access." "Not touching system files." || return
sudo stow --dir="$bootstrap_dir" --target="/" -R system-packages/
check_consent n "Link system settings files? This will require sudo access and may overwrite existing files." "Not touching system files." || return
if [ -e "/etc/pacman.conf" ]; then
check_consent n "Found an existing pacman.conf file, installation will error if it exists. Remove file?" && run_elevated rm "/etc/pacman.conf"
fi
run_elevated stow --dir="$bootstrap_dir" --target="/" -R system-packages/
echo "Linked system files."
}
install_packages() {
check_consent n "Install pre-designated packages? This will take a while." "Not installing packages." || return
export BOOTSTRAP_PACKAGES="bootstrap/packages.txt"
check_consent n "Install pre-designated packages? This will take a while, install a lot of packages and require super user privileges." "Not installing packages." || return
if ! "$UNATTENDED"; then
"$bootstrap_dir"/install_packages.sh
else
"$bootstrap_dir"/install_packages.sh -f
fi
unset BOOTSTRAP_PACKAGES
echo "Installed packages."
}
@ -104,12 +112,14 @@ install() {
entry_question
fi
echo "====================== BEGINNING INSTALLATION ============================="
echo "====================== BEGINNING SYSTEM FILE MANAGEMENT ============================="
stow_system_packages
echo "====================== BEGINNING PACKAGE INSTALLATION ============================="
install_packages
echo "=================== BEGINNING DOTFILE MANAGEMENT =========================="
stow_dotfiles
stow_system_packages
echo "================== ENABLING GIT REPOSITORY HOOKS =========================="
enable_git_hooks