1
0
Fork 0

various bugfixes

This commit is contained in:
Luca Bilke 2024-07-20 12:55:31 +00:00
parent 61c444f807
commit afdf2c4adc
Signed by: luca
GPG Key ID: F6E11C9BAA7C82F5
3 changed files with 41 additions and 28 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
bootstrapper.log
bootstrap.log

View File

@ -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

View File

@ -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.[]' <config.yml); do
command="$(echo "$p" | yq -r '.command[0]')"
pre_command="$(echo "$p" | yq -r '.pre[]' 2>/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[]' <config.yml)
counter=1
@ -249,6 +250,8 @@ enable_services() {
for service in $services; do
info "Enabling service ${counter} of ${num_services}: ${service}"
[ ! -L "/var/service/${service}" ] && ln -s "/etc/sv/${service}" "/var/service/"
counter=$((counter + 1))
done 2>&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