6 if ! [ $# -eq 5 ]; then
7 echo "Usage: ${0} USERNAME_DEFAULT USERNAME_MAIL USERNAME_REMOTE GROUPNAME DIRECTORY.";
11 echo "Wait for success..."
21 # Thanks Chuck L. for the mac addusers
22 if [ "$UNAME" = "Darwin" ]; then
23 if ! id -u "${USER}" > /dev/null 2>&1; then
25 # Creating for <= 10.4
26 if /usr/bin/sw_vers 2>/dev/null| grep "ProductVersion" | grep -E "10.2.|10.3|10.4" > /dev/null 2>&1; then
27 chmod +x ./init/darwin-addusers.pl
28 ./init/darwin-addusers.pl
30 chmod +x ./init/osx105-addusers.sh
31 ./init/osx105-addusers.sh
36 if [ "$UNAME" = "FreeBSD" -o "$UNAME" = "DragonFly" ]; then
37 GROUPADD="/usr/sbin/pw groupadd"
38 USERADD="/usr/sbin/pw useradd"
39 OSMYSHELL="/sbin/nologin"
40 elif [ "$UNAME" = "SunOS" ]; then
41 GROUPADD="/usr/sbin/groupadd"
42 USERADD="/usr/sbin/useradd"
43 OSMYSHELL="/bin/false"
44 elif [ "$UNAME" = "AIX" ]; then
45 GROUPADD="/usr/sbin/mkgroup"
46 USERADD="/usr/sbin/useradd"
47 OSMYSHELL="/bin/false"
48 elif [ "$UNAME" = "OpenBSD" ]; then
49 GROUPADD="/usr/sbin/groupadd"
50 USERADD="/usr/sbin/useradd"
51 OSMYSHELL="/sbin/nologin"
53 # Alpine linux has adduser/addgroup
54 if [ -e "/etc/alpine-release" ]; then
55 GROUPADD="/usr/sbin/addgroup"
56 USERADD="/usr/sbin/adduser"
57 OSMYSHELL="/sbin/nologin"
59 # All current linux distributions should support system accounts for
60 # users/groups. If not, leave the GROUPADD/USERADD as it was before
63 $1 --help 2>&1 | grep -e " *-r.*system account" >/dev/null 2>&1 && echo "$1 -r" || echo "$1"
65 GROUPADD=$(sys_acct_chk "/usr/sbin/groupadd -f")
66 USERADD=$(sys_acct_chk "/usr/sbin/useradd")
67 OSMYSHELL="/sbin/nologin"
71 if [ -x /usr/bin/getent ]; then
72 if [ `getent group "${GROUP}" | wc -l` -lt 1 ]; then
73 ${GROUPADD} "${GROUP}"
75 elif ! grep "^${GROUP}" /etc/group > /dev/null 2>&1; then
76 ${GROUPADD} "${GROUP}"
79 if [ "${OSMYSHELL}" = "/sbin/nologin" ]; then
80 # We first check if /sbin/nologin is present. If it is not,
81 # we look for /bin/false. If none of them is present, we
82 # just stick with nologin (no need to fail the install for that).
83 if [ ! -f ${OSMYSHELL} ]; then
84 if [ -f /bin/false ]; then
85 OSMYSHELL="/bin/false"
90 for U in ${USER} ${USER_MAIL} ${USER_REM}; do
91 if [ -x /usr/bin/getent ]; then
92 if [ `getent passwd ${U} | wc -l` -lt 1 ]; then
93 if [ "$UNAME" = "OpenBSD" ] || [ "$UNAME" = "SunOS" ]; then
94 ${USERADD} -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}" "${U}"
95 elif [ -e "/etc/alpine-release" ]; then
96 ${USERADD} -G ${GROUP} -s ${OSMYSHELL} -h ${DIR} -S ${U}
98 ${USERADD} "${U}" -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}"
101 elif [ ! `grep "^${U}" /etc/passwd > /dev/null 2>&1` ]; then
102 if [ "$UNAME" = "OpenBSD" ] || [ "$UNAME" = "SunOS" ]; then
103 ${USERADD} -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}" "${U}"
104 elif [ -e "/etc/alpine-release" ]; then
105 ${USERADD} -G ${GROUP} -s ${OSMYSHELL} -h ${DIR} -S ${U}
107 ${USERADD} "${U}" -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}"