diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-19 19:01:04 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-19 19:26:54 +0000 |
commit | 2425a623a2437d21bbc176e9f72cd1523bc47486 (patch) | |
tree | 2b46f0f9b5082d0055bf99611e5fd3ba1f767021 /setup-user.in | |
parent | 9a6aa242d38e5c35ba258b371ce287f40e86572d (diff) | |
download | alpine-conf-2425a623a2437d21bbc176e9f72cd1523bc47486.zip |
setup-user: add -g option to specify groups
Diffstat (limited to 'setup-user.in')
-rw-r--r-- | setup-user.in | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/setup-user.in b/setup-user.in index c02c1a2..789ff84 100644 --- a/setup-user.in +++ b/setup-user.in @@ -6,13 +6,14 @@ PREFIX=@PREFIX@ usage() { cat <<-__EOF__ - usage: setup-user [-h] [-f FULLNAME] [-k SSHKEY] [USERNAME] + usage: setup-user [-h] [-f FULLNAME] [-g GROUPS] [-k SSHKEY] [USERNAME] Create user account options: -h Show this help -f Set full name for user + -g Comma or space separated list of groups to add user to -k ssh key or URL to ssh key (eg. https://gitlab.alpinelinux.org/user.keys) or 'none' for no key @@ -21,10 +22,11 @@ usage() { exit $1 } -while getopts "f:hk:" opt; do +while getopts "f:g:hk:" opt; do case $opt in h) usage 0;; f) fullname="$OPTARG";; + g) groups="$OPTARG";; k) keysopt="$OPTARG";; '?') usage "1" >&2;; esac @@ -98,3 +100,9 @@ if [ -n "$sshkeys" ] && [ "$sshkeys" != "none" ]; then mkdir -p "$ROOT"/home/$username/.ssh echo "$sshkeys" > "$ROOT"/home/$username/.ssh/authorized_keys fi + +if [ -n "$groups" ] && [ "$groups" != "none" ]; then + for i in $(echo $groups | tr ',' ' '); do + $MOCK addgroup "$username" "$i" || exit + done +fi |