PortValhalla/scripts/Common/OS/users.fish

41 lines
1.1 KiB
Fish
Raw Normal View History

2024-07-19 22:46:02 +00:00
#!/bin/env fish
set -l dir (status dirname)
2024-11-01 12:12:16 +00:00
source "$dir/../../lib/settings.fish"
set -l users (getUsers)
2024-07-19 22:46:02 +00:00
2024-09-22 22:23:41 +00:00
echo "Creating users..."
2024-07-19 22:46:02 +00:00
2024-12-05 15:34:24 +00:00
for name in (echo "$users" | jq '.[]' --raw-output0 | string split0 || true)
2024-09-22 22:23:41 +00:00
echo "Creating user `$name`..."
2024-09-22 15:50:05 +00:00
function getUserInfo -V name -a config
getUserConfig "$name" "$config" $argv[2..]
2024-07-19 22:46:02 +00:00
end
2024-10-06 19:25:34 +00:00
set -l groups (getUserInfo groups --apply 'builtins.concatStringsSep ","')
2024-09-22 15:50:05 +00:00
set -l displayName (getUserInfo displayName --json)
set -l shell (getUserInfo defaultShell --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 echo "$displayName" | jq --exit-status > /dev/null
echo "--comment"
echo "$displayName" | jq --raw-output
end
2024-09-12 19:47:50 +00:00
) (
if [ -n "$groups" ]
echo "--groups"
echo "$groups"
end
) "$name"
2024-07-19 22:46:02 +00:00
2024-10-06 19:25:34 +00:00
if echo "$shell" | jq --exit-status >/dev/null
sudo chsh "$name" --shell (which (echo "$shell" | jq --raw-output))
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