PortValhalla/scripts/Common/OS/install.fish

58 lines
1.4 KiB
Fish
Executable file

#!/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 (getConfig valhalla.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 wheel,nix-users \
--create-home \
--uid (getConfig valhalla.setupUser.id --json) \
"$name"
end
and begin
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end > "$sudoConfig"
and sudo --preserve-env="CONFIG_NAME" --user "$name" "$INSTALLER_SCRIPT"
rm "$sudoConfig"
userdel -r "$name"
else
source "$dir/../Software/bash/main.fish"
if not type -q getDeploymentScript
function getDeploymentScript
echo "No deployment script specified! No software will be installed." 1>&2
false
end
end
runHook initialize || true
runHook installOS || true
runHook addUsers || begin
source "$dir/users.fish"
end
runHook installSoftware || begin
set -l script (getDeploymentScript)
if [ -n "$script" ]
source $script
end
end
runHook initializeConfig || true
runHook postInstall || true
end