Initialize and dispose actions properly
This commit is contained in:
parent
2959c9bd33
commit
76376be56a
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,30 +9,38 @@ 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 [ -z "$TMUX" ]
|
||||
runActionSetup
|
||||
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
||||
else
|
||||
source "$dir/settings.fish"
|
||||
|
@ -57,14 +65,11 @@ function runSetupUserAction -V dir
|
|||
end >"$sudoConfig"
|
||||
|
||||
and sudo --preserve-env --set-home --user "$name" $cmdline
|
||||
disposeAction
|
||||
rm "$sudoConfig"
|
||||
userdel -rf "$name"
|
||||
end
|
||||
else
|
||||
$argv
|
||||
uninstallNixPkgs
|
||||
end
|
||||
end
|
||||
|
||||
runAction setupUserAction $argv
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue