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