summaryrefslogtreecommitdiff
path: root/recipes-core/useradd/useradd.bb
blob: 29d65088d933c4e42486ce404a6f49068d260761 (plain)
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
SUMMARY = "Add mtadm user"
DESCRIPTION = "Add mtadm user for security purposes"
SECTION = "mtadm"
PR = "r4"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

S = "${WORKDIR}"
user = "mtadm"
home = "/home/${user}"
FILES_${PN} = "${home}/.ssh"
inherit useradd

# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
#USERADD_PACKAGES = "${PN} ${PN}-user3"
USERADD_PACKAGES = "${PN}"

# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.

# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
GROUPADD_PARAM_${PN} = "-r  -g 27 sudo"

# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM_${PN} = "-u 50 -G sudo,disk,dialout -m -r -s /bin/bash ${user}"

do_install () {
        # If the recipe doesn't have a file, the ipk
        # is deleted, and it does nothing.
        # Create a .ssh directory for mtadm.
        install -d 0700 ${D}/${FILES_${PN}}
	chown mtadm:mtadm ${D}/${home}
	chown mtadm:mtadm ${D}/${FILES_${PN}}
}

# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

pkg_postinst_${PN} () {
   profile=${home}/.profile
   if ! grep 'sbin' ${profile} ; then
     Sub='${PA'
     Sub=${Sub}'TH}:/sbin:/usr/sbin'
     echo 'PATH='${Sub} >>$D/${home}/.profile
     echo 'export PATH'  >>$D/${home}/.profile
   fi
   # If doing an update, we need to add mtadm to dialout.
   # If the admin has been changed, then the user must
   # do something himself.
   if [[ -z $D ]] ; then
     sudo groupmems -a mtadm  -g dialout || true
   fi
}