diff options
Diffstat (limited to 'mail/dovecot/pkg-install')
-rw-r--r-- | mail/dovecot/pkg-install | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/mail/dovecot/pkg-install b/mail/dovecot/pkg-install index bbb0c9d3195..e6cba076921 100644 --- a/mail/dovecot/pkg-install +++ b/mail/dovecot/pkg-install @@ -30,46 +30,60 @@ yesno() { done } -make_account() { - local u g gcos +create_account() { + local port user uid group gid gcos home shell - u=$1 - g=$2 - gcos=$3 + port=$1 + user=${2%:*} + uid=${2#*:} + group=${3%:*} + gid=${3#*:} + gcos=$4 + home=$5 + shell=$6 - if pw group show "${g}" >/dev/null 2>&1; then - echo "You already have a group \"${g}\", so I will use it." + pw_user_uid=$(pw usershow -n "${user}" 2>/dev/null | cut -d: -f3) + pw_uid_user=$(pw usershow -u "${uid}" 2>/dev/null | cut -d: -f1) + pw_group_gid=$(pw groupshow -n "${group}" 2>/dev/null | cut -d: -f3) + pw_gid_group=$(pw groupshow -g "${gid}" 2>/dev/null | cut -d: -f1) + + if [ -z "${pw_group_gid}" -a -z "${pw_gid_group}" ]; then + echo "You need a ${group} group; creating it..." + pw groupadd "${group}" -g "${gid}" || exit + echo "Done." + elif [ "${gid}" = "${pw_group_gid}" -a "${group}" = "${pw_gid_group}" ]; then + echo "Using existing ${group} group." else - echo "You need a group \"${g}\"." - if which -s pw && yesno "Would you like me to create it" y - then - pw groupadd ${g} || exit - echo "Done." - else - echo "Please create it, and try again." - exit 1 - fi + echo "${port} has reserved the groupname '${group}' and gid '${gid}':" + [ -n "${pw_group_gid}" -a "${gid}" != "${pw_group_gid}" ] \ + && echo "ERROR: groupname '${group}' already in use by gid '${pw_group_gid}'" + [ -n "${pw_gid_group}" -a "${group}" != "${pw_gid_group}" ] \ + && echo "ERROR: gid '${gid}' already in use by group '${pw_gid_group}'" + echo "Please resolve these issues and try again." + exit 1 fi - - if pw user show "${u}" >/dev/null 2>&1; then - echo "You already have a user \"${u}\", so I will use it." + + if [ -z "${pw_user_uid}" -a -z "${pw_uid_user}" ]; then + echo "You need a ${user} user; creating it..." + pw useradd "${user}" -u "${uid}" -g "${group}" -c "${gcos}" -d "${home}" -s "${shell}" + echo "Done." + elif [ "${uid}" = "${pw_user_uid}" -a "${user}" = "${pw_uid_user}" ]; then + echo "Using existing ${user} user." else - echo "You need a user \"${u}\"." - if which -s pw && yesno "Would you like me to create it" y - then - pw useradd ${u} -g ${g} -c "${gcos}" -d /nonexistent -s /sbin/nologin -h - || exit - echo "Done." - else - echo "Please create it, and try again." - exit 1 - fi + echo "${port} has reserved the username '${user}' and uid '${uid}':" + [ -n "${pw_user_uid}" -a "${uid}" != "${pw_user_uid}" ] \ + && echo "ERROR: username '${user}' already in use by uid '${pw_user_uid}'" + [ -n "${pw_uid_user}" -a "${user}" != "${pw_uid_user}" ] \ + && echo "ERROR: uid '${uid}' already in use by user '${pw_uid_user}'" + echo "Please resolve these issues and try again." + exit 1 fi } case $2 in PRE-INSTALL) - make_account dovecot dovecot "Dovecot" + create_account Dovecot dovecot:143 dovecot:143 "Dovecot User" /var/empty /sbin/nologin ;; POST-INSTALL) |