summaryrefslogtreecommitdiff
path: root/system/adelie-base/adduser
blob: 5c458045dfdce1a76e4c94f5cea2424f7ec13077 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# adduser - BusyBox compatibility shim
# bbshim
# 
# Copyright © 2017 A. Wilcox.  All rights reserved.
# Licensed under the terms of the NCSA Open Source license.
#

# The GECOS for the new user.
GECOS="Linux User,,,"

# Additional groups in which to add the new user.
MYGROUPS=

# Path to the home directory for the new user.
HOMEDIR=

# Don't call passwd(1) for the new user afterwards.
NOPASSWD=0

# The new user's shell.
MYSHELL=$SHELL

# An alternative skeleton directory for the new user's home directory.
SKEL=/etc/skel

# The new user is a system user.
SYSTEM=0

# Use this UID number for the new user.
MYUID=


ARG=

while getopts h:g:s:G:SDHu:k: ARG
do
    case $ARG in
        h)  HOMEDIR=$OPTARG ;;
        g)  GECOS=$OPTARG ;;
        s)  MYSHELL=$OPTARG ;;
        G)  MYGROUPS=$OPTARG ;;
        S)  SYSTEM=1
            MYSHELL="/bin/false";;
        D)  NOPASSWD=1 ;;
        H)  unset HOMEDIR ;;
        u)  MYUID=$OPTARG ;;
        k)  SKEL=$OPTARG ;;
        :)  exit 1 ;;
        \?) exit 1 ;;
    esac
done

shift $(($OPTIND - 1))

if [ -z "$*" ]; then
    echo "$0: user name is required" >&2
    exit 1
fi

set "$@"


CMDLINE="-s $MYSHELL"

if [ -n "$MYGROUPS" ]; then
    CMDLINE="$CMDLINE -g $MYGROUPS"
fi

if [ -n "$HOMEDIR" ]; then
    CMDLINE="$CMDLINE -m -d $HOMEDIR -k $SKEL"
fi

if [ $SYSTEM -ne 0 ]; then
    CMDLINE="$CMDLINE -r"
fi

if [ -n "$MYUID" ]; then
    CMDLINE="$CMDLINE -u $MYUID"
fi

if [ -n "$2" ]; then
    CMDLINE="$CMDLINE -g $2"
fi

useradd -c "$GECOS" $CMDLINE $1

#if [ $NOPASSWD -eq 0 ]; then
#    passwd $1
#fi