X-Git-Url: https://git.cameronkatri.com/pw-darwin.git/blobdiff_plain/b7ca0fb0cefab36f28337f65b3ae12b94f637527..cda8e1027a7b18b2894b7422ef611093e5e2a3da:/adduser/adduser.sh diff --git a/adduser/adduser.sh b/adduser/adduser.sh index 7097caf..f645f59 100644 --- a/adduser/adduser.sh +++ b/adduser/adduser.sh @@ -28,20 +28,20 @@ # # err msg -# Display $msg on stderr, unless we're being quiet. -# +# Display $msg on stderr, unless we're being quiet. +# err() { if [ -z "$quietflag" ]; then - echo 1>&2 ${THISCMD}: ERROR: $* + echo 1>&2 ${THISCMD}: ERROR: $* fi } # info msg -# Display $msg on stdout, unless we're being quiet. -# +# Display $msg on stdout, unless we're being quiet. +# info() { if [ -z "$quietflag" ]; then - echo ${THISCMD}: INFO: $* + echo ${THISCMD}: INFO: $* fi } @@ -50,7 +50,7 @@ info() { # is not, output the value of the next higher uid that is available. # If a uid is not specified, output the first available uid, as indicated # by pw(8). -# +# get_nextuid () { _uid=$1 _nextuid= @@ -81,6 +81,7 @@ show_usage() { echo " -E disable this account after creation" echo " -G additional groups to add accounts to" echo " -L login class of the user" + echo " -M file permission for home directory" echo " -N do not read configuration file" echo " -S a nonexistent shell is not an error" echo " -d home directory" @@ -162,8 +163,7 @@ fullpath_from_shell() { # the path is invalid or it is not executable it # will emit an informational message saying so. # -shell_exists() -{ +shell_exists() { _sh="$1" _shellchk="${GREPCMD} '^$_sh$' ${ETCSHELLS} > /dev/null 2>&1" @@ -190,6 +190,7 @@ save_config() { echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF} echo "# Last Modified on `${DATECMD}`." >> ${ADDUSERCONF} echo '' >> ${ADDUSERCONF} + echo "defaultHomePerm=$uhomeperm" >> ${ADDUSERCONF} echo "defaultLgroup=$ulogingroup" >> ${ADDUSERCONF} echo "defaultclass=$uclass" >> ${ADDUSERCONF} echo "defaultgroups=$ugroups" >> ${ADDUSERCONF} @@ -199,6 +200,7 @@ save_config() { echo "udotdir=$udotdir" >> ${ADDUSERCONF} echo "msgfile=$msgfile" >> ${ADDUSERCONF} echo "disableflag=$disableflag" >> ${ADDUSERCONF} + echo "uidstart=$uidstart" >> ${ADDUSERCONF} } # add_user @@ -246,7 +248,12 @@ add_user() { if [ "$uhome" = "$NOHOME" ]; then _home='-d "$uhome"' else - _home='-m -d "$uhome"' + # Use home directory permissions if specified + if [ -n "$uhomeperm" ]; then + _home='-m -d "$uhome" -M "$uhomeperm"' + else + _home='-m -d "$uhome"' + fi fi elif [ -n "$Dflag" -a -n "$uhome" ]; then _home='-d "$uhome"' @@ -448,21 +455,38 @@ get_homedir() { fi } +# get_homeperm +# Reads the account's home directory permissions. +# +get_homeperm() { + uhomeperm=$defaultHomePerm + _input= + _prompt= + + if [ -n "$uhomeperm" ]; then + _prompt="Home directory permissions [${uhomeperm}]: " + else + _prompt="Home directory permissions (Leave empty for default): " + fi + if [ -z "$fflag" ]; then + echo -n "$_prompt" + read _input + fi + + if [ -n "$_input" ]; then + uhomeperm="$_input" + fi +} + # get_uid # Reads a numeric userid in an interactive or batch session. Automatically # allocates one if it is not specified. # get_uid() { - if [ -z "$uuid" ]; then - uuid=${uidstart} - fi - + uuid=${uidstart} _input= _prompt= - # No need to take down uids for a configuration saving run. - [ -n "$configflag" ] && return - if [ -n "$uuid" ]; then _prompt="Uid [$uuid]: " else @@ -598,19 +622,22 @@ input_from_file() { case "$fileline" in \#*|'') ;; - esac - - get_user || continue - get_gecos - get_uid - get_logingroup - get_class - get_shell - get_homedir - get_password - get_expire_dates + *) + get_user || continue + get_gecos + get_uid + get_logingroup + get_class + get_shell + get_homedir + get_homeperm + get_password + get_expire_dates + ugroups="$defaultgroups" - add_user + add_user + ;; + esac done } @@ -619,7 +646,6 @@ input_from_file() { # the user database. # input_interactive() { - _disable= _pass= _passconfirm= @@ -673,6 +699,7 @@ input_interactive() { get_class get_shell get_homedir + get_homeperm while : ; do echo -n "Use password-based authentication? [$_usepass]: " @@ -783,6 +810,7 @@ input_interactive() { printf "%-10s : %s\n" "Class" "$uclass" printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "$ugroups" printf "%-10s : %s\n" "Home" "$uhome" + printf "%-10s : %s\n" "Home Mode" "$uhomeperm" printf "%-10s : %s\n" "Shell" "$ushell" printf "%-10s : %s\n" "Locked" "$_disable" while : ; do @@ -827,6 +855,7 @@ ugecos= ulogingroup= uclass= uhome= +uhomeperm= upass= ushell= udotdir=/usr/share/skel @@ -853,9 +882,10 @@ defaultclass= defaultLgroup= defaultgroups= defaultshell="${DEFAULTSHELL}" +defaultHomePerm= # Make sure the user running this program is root. This isn't a security -# measure as much as it is a usefull method of reminding the user to +# measure as much as it is a useful method of reminding the user to # 'su -' before he/she wastes time entering data that won't be saved. # procowner=${procowner:-`/usr/bin/id -u`} @@ -864,7 +894,7 @@ if [ "$procowner" != "0" ]; then exit 1 fi -# Overide from our conf file +# Override from our conf file # Quickly go through the commandline line to see if we should read # from our configuration file. The actual parsing of the commandline # arguments happens after we read in our configuration file (commandline @@ -884,7 +914,7 @@ if [ -n "$readconfig" ]; then fi fi -# Proccess command-line options +# Process command-line options # for _switch ; do case $_switch in @@ -941,6 +971,10 @@ for _switch ; do esac shift; shift ;; + -M) + defaultHomePerm=$2 + shift; shift + ;; -N) readconfig= shift