#!/bin/env fish set -l dir (status dirname) source "$dir/../Scripts/config.fish" source "$dir/../Scripts/hooks.fish" if [ (id -u) -eq 0 ] set -l name (getOSConfig setupUser.name) set -l sudoConfig "/etc/sudoers.d/PortValhalla" rm ~/.bash_profile runHook createUser || \ begin useradd \ --comment "PortValhalla setup user" \ --system \ --no-user-group \ --groups nix-users \ --create-home \ --uid (getOSConfig setupUser.id --json) \ "$name" end and begin echo "$name ALL=(ALL:ALL) NOPASSWD: ALL" end > "$sudoConfig" and sudo --preserve-env --set-home --user "$name" "$INSTALLER_SCRIPT" rm "$sudoConfig" userdel -rf "$name" else if not type -q getDeploymentScript function getDeploymentScript echo "No deployment script specified! No software will be installed." 1>&2 false end end set -l deployScript (getDeploymentScript) runHook initialize || true and runHook installOS || true and runHook addUsers || begin source "$dir/users.fish" end and runHook installSoftware || begin if [ -n "$deployScript" ] source $deployScript end end runHook initializeUsers || begin if [ -n "$deployScript" ] source "$dir/../Scripts/config.fish" for name in (getUsers | jq '.[]' --raw-output0 | string split0) source $deployScript userConfig $name end end end and runHook postInstall || true and sudo git config remove-section --system safe and begin set -l projectPath (realpath "$(status dirname)/../../..") cd (dirname "$projectPath") sudo rm -rf "$projectPath" end and echo "The installation finished successfully!" and echo "This machine will reboot in 5 seconds..." and echo "Press CTRL-C to abort..." and sleep 5 and systemctl reboot -i end