2024-11-01 14:32:43 +00:00
|
|
|
set -l dir (status dirname)
|
|
|
|
|
2024-11-04 00:34:22 +00:00
|
|
|
function runActionSetup -V dir
|
2024-11-01 14:32:43 +00:00
|
|
|
source "$dir/hooks.fish"
|
|
|
|
source "$dir/nix.fish"
|
|
|
|
source "$dir/settings.fish"
|
2024-11-03 21:32:47 +00:00
|
|
|
echo "Installing dependencies..."
|
|
|
|
and runHook --force installValhallaDeps 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.'
|
|
|
|
and echo "Preparing nix..."
|
2024-11-01 14:32:43 +00:00
|
|
|
and runHook prepareNix || installNixPkgs
|
|
|
|
|
2024-11-04 00:34:22 +00:00
|
|
|
and echo "Flagging repository as safe..."
|
2024-11-25 14:19:01 +00:00
|
|
|
and sudo git config --system --add safe.directory (realpath -m "$(status dirname)/../..")
|
2024-11-04 00:34:22 +00:00
|
|
|
and runHook actionPreRun || true
|
|
|
|
end
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-25 14:19:01 +00:00
|
|
|
function runActionConfigure -V dir
|
2024-11-05 16:39:06 +00:00
|
|
|
and if [ -z "$CONFIG_NAME" ]
|
2024-11-25 14:19:01 +00:00
|
|
|
source "$dir/settings.fish"
|
2024-11-05 16:39:06 +00:00
|
|
|
selectProfile config
|
2024-11-25 14:19:01 +00:00
|
|
|
set -gx CONFIG_NAME "$config"
|
2024-11-05 16:39:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-04 00:34:22 +00:00
|
|
|
function disposeAction -V dir
|
|
|
|
source "$dir/hooks.fish"
|
2024-11-05 16:39:06 +00:00
|
|
|
source "$dir/nix.fish"
|
2024-11-04 00:34:43 +00:00
|
|
|
runHook actionPostRun || true
|
2024-11-05 16:39:06 +00:00
|
|
|
and uninstallNixPkgs
|
2024-11-28 21:12:15 +00:00
|
|
|
and sudo git config --remove-section --system safe || true
|
2024-11-04 00:34:22 +00:00
|
|
|
end
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-04 00:34:22 +00:00
|
|
|
function runAction -V dir
|
|
|
|
runActionSetup
|
2024-11-05 16:39:06 +00:00
|
|
|
and runActionConfigure
|
2024-11-04 00:34:22 +00:00
|
|
|
and $argv
|
|
|
|
and disposeAction
|
2024-11-01 14:32:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function runSetupUserAction -V dir
|
2024-11-25 14:19:01 +00:00
|
|
|
source "$dir/settings.fish"
|
|
|
|
runActionSetup
|
|
|
|
runActionConfigure
|
|
|
|
set -l name (getOSConfig setupUser.name)
|
|
|
|
|
|
|
|
if [ "$USER" != "$name" ]
|
2024-11-04 00:34:22 +00:00
|
|
|
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-25 14:19:01 +00:00
|
|
|
if [ (id -u) -ne 0 ]
|
2024-11-27 04:24:53 +00:00
|
|
|
sudo --set-home --preserve-env env "PATH=$PATH" $cmdline
|
2024-11-04 00:34:22 +00:00
|
|
|
else
|
2024-11-25 14:19:01 +00:00
|
|
|
if [ -z "$TMUX" ]
|
2024-11-28 21:11:27 +00:00
|
|
|
tmux new-session env (env) $cmdline
|
2024-11-25 14:19:01 +00:00
|
|
|
else
|
|
|
|
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-25 14:19:01 +00:00
|
|
|
begin
|
|
|
|
echo "Creating setup user"
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-25 14:19:01 +00:00
|
|
|
and useradd \
|
2024-11-29 00:13:58 +00:00
|
|
|
--comment "PortValhalla Setup User" \
|
|
|
|
--system \
|
|
|
|
--groups nix-users \
|
|
|
|
--create-home \
|
|
|
|
--uid (getOSConfig setupUser.id --json) \
|
|
|
|
"$name"
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-25 14:19:01 +00:00
|
|
|
and begin
|
|
|
|
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
|
|
|
|
end >"$sudoConfig"
|
2024-11-01 14:32:43 +00:00
|
|
|
|
2024-11-27 04:24:53 +00:00
|
|
|
and sudo --preserve-env --set-home --user "$name" env "PATH=$PATH" $cmdline
|
2024-11-25 14:19:01 +00:00
|
|
|
disposeAction
|
|
|
|
rm "$sudoConfig"
|
|
|
|
userdel -rf "$name"
|
|
|
|
end
|
|
|
|
end
|
2024-11-01 14:32:43 +00:00
|
|
|
end
|
2024-11-04 00:34:22 +00:00
|
|
|
else
|
|
|
|
$argv
|
2024-11-01 14:32:43 +00:00
|
|
|
end
|
|
|
|
end
|