Force running actions as setup-user
This commit is contained in:
parent
85fa80c04f
commit
8a2c4b4570
1 changed files with 36 additions and 30 deletions
|
@ -10,14 +10,15 @@ function runActionSetup -V dir
|
||||||
and runHook prepareNix || installNixPkgs
|
and runHook prepareNix || installNixPkgs
|
||||||
|
|
||||||
and echo "Flagging repository as safe..."
|
and echo "Flagging repository as safe..."
|
||||||
and sudo git config --system --add safe.directory (realpath "$(status dirname)/../..")
|
and sudo git config --system --add safe.directory (realpath -m "$(status dirname)/../..")
|
||||||
and runHook actionPreRun || true
|
and runHook actionPreRun || true
|
||||||
end
|
end
|
||||||
|
|
||||||
function runActionConfigure
|
function runActionConfigure -V dir
|
||||||
and if [ -z "$CONFIG_NAME" ]
|
and if [ -z "$CONFIG_NAME" ]
|
||||||
|
source "$dir/settings.fish"
|
||||||
selectProfile config
|
selectProfile config
|
||||||
set -x CONFIG_NAME "$config"
|
set -gx CONFIG_NAME "$config"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,39 +38,44 @@ function runAction -V dir
|
||||||
end
|
end
|
||||||
|
|
||||||
function runSetupUserAction -V dir
|
function runSetupUserAction -V dir
|
||||||
if [ (id -u) -eq 0 ]
|
source "$dir/settings.fish"
|
||||||
|
runActionSetup
|
||||||
|
runActionConfigure
|
||||||
|
set -l env "CONFIG_NAME=$CONFIG_NAME"
|
||||||
|
set -l name (getOSConfig setupUser.name)
|
||||||
|
|
||||||
|
if [ "$USER" != "$name" ]
|
||||||
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
|
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
|
||||||
|
|
||||||
if [ -z "$TMUX" ]
|
if [ (id -u) -ne 0 ]
|
||||||
runActionSetup
|
sudo --set-home --preserve-env $cmdline
|
||||||
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
|
|
||||||
else
|
else
|
||||||
source "$dir/settings.fish"
|
if [ -z "$TMUX" ]
|
||||||
runActionConfigure
|
tmux new-session -e "$env" $cmdline
|
||||||
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
else
|
||||||
set -l name (getOSConfig setupUser.name)
|
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
|
||||||
|
|
||||||
and begin
|
begin
|
||||||
echo "Creating setup user"
|
echo "Creating setup user"
|
||||||
|
|
||||||
and useradd \
|
and useradd \
|
||||||
--comment "PortValhalla Setup User" \
|
--comment "PortValhalla Setup User" \
|
||||||
--system \
|
--system \
|
||||||
--no-user-group \
|
--groups nix-users \
|
||||||
--groups nix-users \
|
--create-home \
|
||||||
--create-home \
|
--uid (getOSConfig setupUser.id --json) \
|
||||||
--uid (getOSConfig setupUser.id --json) \
|
"$name"
|
||||||
"$name"
|
|
||||||
|
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
|
||||||
end
|
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
|
end
|
||||||
else
|
else
|
||||||
$argv
|
$argv
|
||||||
|
|
Loading…
Reference in a new issue