Force running actions as setup-user

This commit is contained in:
Manuel Thalmann 2024-11-25 15:19:01 +01:00
parent bd394560a3
commit bb441b38d0

View file

@ -10,14 +10,15 @@ function runActionSetup -V dir
and runHook prepareNix || installNixPkgs
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
end
function runActionConfigure
function runActionConfigure -V dir
and if [ -z "$CONFIG_NAME" ]
source "$dir/settings.fish"
selectProfile config
set -x CONFIG_NAME "$config"
set -gx CONFIG_NAME "$config"
end
end
@ -37,30 +38,33 @@ function runAction -V dir
end
function runSetupUserAction -V dir
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"
runActionSetup
runActionConfigure
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
set -l env "CONFIG_NAME=$CONFIG_NAME"
set -l name (getOSConfig setupUser.name)
and begin
if [ "$USER" != "$name" ]
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
if [ (id -u) -ne 0 ]
sudo --set-home --preserve-env $cmdline
else
if [ -z "$TMUX" ]
tmux new-session -e "$env" $cmdline
else
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
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"
@ -71,6 +75,8 @@ function runSetupUserAction -V dir
rm "$sudoConfig"
userdel -rf "$name"
end
end
end
else
$argv
end