Initialize and dispose actions properly
This commit is contained in:
parent
1a412dfc0e
commit
be83deff2d
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,62 +9,67 @@ 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" ]
|
||||||
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
runActionSetup
|
||||||
else
|
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
||||||
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
|
|
||||||
else
|
else
|
||||||
$argv
|
source "$dir/settings.fish"
|
||||||
uninstallNixPkgs
|
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
||||||
end
|
set -l name (getOSConfig setupUser.name)
|
||||||
end
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue