diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-19 18:02:55 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-19 19:26:54 +0000 |
commit | be11c93d018a07afd1b166a642f5efa2630474f7 (patch) | |
tree | 9b75c05eef50b23016289e2add261f85493951af /setup-user.in | |
parent | 691171323b5b72c9a9d6b59b999c0581301b8d6b (diff) | |
download | alpine-conf-be11c93d018a07afd1b166a642f5efa2630474f7.zip |
setup-user: new setup script
Diffstat (limited to 'setup-user.in')
-rw-r--r-- | setup-user.in | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/setup-user.in b/setup-user.in new file mode 100644 index 0000000..8b9e6cf --- /dev/null +++ b/setup-user.in @@ -0,0 +1,66 @@ +#!/bin/sh + +PREFIX=@PREFIX@ +: ${LIBDIR=$PREFIX/lib} +. "$LIBDIR/libalpine.sh" + +usage() { + cat <<-__EOF__ + usage: setup-user [-h] [-f FULLNAME] [USERNAME] + + Create user account + + options: + -h Show this help + -f Set full name for user + + If USERNAME is not specified user will be prompted. + __EOF__ + exit $1 +} + +while getopts "f:h" opt; do + case $opt in + h) usage 0;; + f) fullname="$OPTARG";; + '?') usage "1" >&2;; + esac +done +shift $(($OPTIND - 1)) + +if [ $# -gt 1 ]; then + usage "1" >&2 +elif [ $# -eq 1 ]; then + username="$1" + nopassword="-D" +else + interactive=1 +fi + +if [ -n "$interactive" ] && [ -z "$fullname" ]; then + ask "Enter full name for user account (or 'skip')" + case "$resp" in + skip) exit 0;; + *) fullname="$resp";; + esac +fi + +if [ -n "$interactive" ] && [ -z "$username" ]; then + while true; do + ask "Enter username for $fullname:" + username="$resp" + if [ -n "$fullname" ]; then + $MOCK adduser -g "$fullname" $nopassword "$username" && break + else + $MOCK adduser $nopassword "$username" && break + fi + done +else + if [ -n "$fullname" ]; then + $MOCK adduser -g "$fullname" $nopassword "$username" + else + $MOCK adduser $nopassword "$username" + fi +fi + + |