Initialize and dispose actions properly
This commit is contained in:
parent
aa2cc7122c
commit
aaa0730f06
2 changed files with 53 additions and 48 deletions
|
@ -66,7 +66,7 @@ function runSetup
|
|||
cp -r "$nixPkgsDir" "$mountDir/$nixPkgsDir"
|
||||
end
|
||||
|
||||
function actionInitialization
|
||||
function actionPreRun
|
||||
echo "Partitioning drives..."
|
||||
and getOSConfig partition.script >"$script"
|
||||
and "$script"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
set -l dir (status dirname)
|
||||
|
||||
function runAction -V dir
|
||||
function runActionSetup -V dir
|
||||
source "$dir/hooks.fish"
|
||||
source "$dir/nix.fish"
|
||||
source "$dir/settings.fish"
|
||||
|
@ -9,62 +9,67 @@ function runAction -V dir
|
|||
and echo "Preparing nix..."
|
||||
and runHook prepareNix || installNixPkgs
|
||||
|
||||
if [ -z "$CONFIG_NAME" ]
|
||||
and if [ -z "$CONFIG_NAME" ]
|
||||
selectProfile config
|
||||
set -x CONFIG_NAME "$config"
|
||||
set -gx CONFIG_NAME "$config"
|
||||
end
|
||||
|
||||
and runHook actionInitialization || true
|
||||
|
||||
echo "Flagging repository as safe..."
|
||||
sudo git config --system --add safe.directory (realpath "$(status dirname)/../..")
|
||||
|
||||
and echo "Flagging repository as safe..."
|
||||
and sudo git config --system --add safe.directory (realpath "$(status dirname)/../..")
|
||||
and runHook actionPreRun || true
|
||||
$argv
|
||||
and runHook actionPostRun || true
|
||||
sudo git config remove-section --system safe || true
|
||||
end
|
||||
|
||||
function disposeAction -V dir
|
||||
source "$dir/hooks.fish"
|
||||
source "$dir/nix.fish"
|
||||
runHook actionPostRun || true
|
||||
and uninstallNixPkgs
|
||||
and sudo git config remove-section --system safe || true
|
||||
end
|
||||
|
||||
function runAction -V dir
|
||||
runActionSetup
|
||||
and $argv
|
||||
and disposeAction
|
||||
end
|
||||
|
||||
function runSetupUserAction -V dir
|
||||
source "$dir/nix.fish"
|
||||
|
||||
function setupUserAction -V dir -V sudoConfig
|
||||
if [ (id -u) -eq 0 ]
|
||||
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
|
||||
if [ (id -u) -eq 0 ]
|
||||
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
|
||||
|
||||
if [ -z "$TMUX" ]
|
||||
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
||||
else
|
||||
source "$dir/settings.fish"
|
||||
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
||||
set -l name (getOSConfig setupUser.name)
|
||||
|
||||
begin
|
||||
echo "Creating setup user"
|
||||
|
||||
and 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" $cmdline
|
||||
rm "$sudoConfig"
|
||||
userdel -rf "$name"
|
||||
end
|
||||
if [ -z "$TMUX" ]
|
||||
runActionSetup
|
||||
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
||||
else
|
||||
$argv
|
||||
uninstallNixPkgs
|
||||
end
|
||||
end
|
||||
source "$dir/settings.fish"
|
||||
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
||||
set -l name (getOSConfig setupUser.name)
|
||||
|
||||
runAction setupUserAction $argv
|
||||
begin
|
||||
echo "Creating setup user"
|
||||
|
||||
and 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" $cmdline
|
||||
disposeAction
|
||||
rm "$sudoConfig"
|
||||
userdel -rf "$name"
|
||||
end
|
||||
else
|
||||
$argv
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue