PortValhalla/scripts/Common/OS/users.fish

33 lines
932 B
Fish
Raw Normal View History

2024-07-19 22:46:02 +00:00
#!/bin/env fish
set -l dir (status dirname)
source "$dir/../Scripts/config.fish"
set -l users (getUsers)
2024-07-19 22:46:02 +00:00
for name in (echo "$users" | jq '.[]' --raw-output0 | string split0)
function getUserConfig -S -a config
getConfig "valhalla.users.$name.$config" $argv[2..]
end
set -l displayName (getUserConfig displayName --json)
set -l shell (getUserConfig displayName --json)
2024-07-19 22:46:02 +00:00
2024-07-19 22:59:11 +00:00
sudo useradd --create-home (
2024-07-19 22:46:02 +00:00
if [ displayName != "null" ]
echo "--comment"
echo "$displayName" | jq --raw-output
end
) --groups (getUserConfig groups --apply 'builtins.concatStringsSep ","') \
"$name"
if echo "$shell" | jq --exit-status > /dev/null
sudo chsh "$name" --shell "$shell"
end
2024-07-19 23:03:20 +00:00
echo "Please Choose a New Password for User `$name`"
2024-07-19 22:46:02 +00:00
2024-07-19 22:59:11 +00:00
while ! sudo passwd "$name"
2024-07-19 22:46:02 +00:00
echo "An error occurred! Please try again."
end
end