blob: 8437a5a7745a7212e908ea6bad4a412ae92922c8 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "Example recipe for using inherit useradd"
2DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
3SECTION = "examples"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006
7SRC_URI = "file://file1 \
8 file://file2 \
9 file://file3 \
10 file://file4"
11
12S = "${WORKDIR}"
13
14PACKAGES =+ "${PN}-user3"
15
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016EXCLUDE_FROM_WORLD = "1"
17
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018inherit useradd
19
20# You must set USERADD_PACKAGES when you inherit useradd. This
21# lists which output packages will include the user/group
22# creation code.
23USERADD_PACKAGES = "${PN} ${PN}-user3"
24
25# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
26# you inherit useradd.
27
28# USERADD_PARAM specifies command line options to pass to the
29# useradd command. Multiple users can be created by separating
30# the commands with a semicolon. Here we'll create two users,
31# user1 and user2:
Patrick Williams213cb262021-08-07 19:21:33 -050032USERADD_PARAM:${PN} = "-u 1200 -d /home/user1 -r -s /bin/bash user1; -u 1201 -d /home/user2 -r -s /bin/bash user2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
Patrick Williams520786c2023-06-25 16:20:36 -050034# user3 will be managed in the useradd-example-user3 package:
Andrew Geissler87f5cff2022-09-30 13:13:31 -050035# As an example, we use the -p option to set password ('user3') for user3
36USERADD_PARAM:${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -p '\$6\$XAWr.8nc\$bUE4pYYaVb8n6BbnBitU0zeJMtfhTpFpiOBLL9zRl4e4YQo88UU4r/1kjRzmTimCy.BvDh4xoFwVqcO.pihLa1' user3"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38# GROUPADD_PARAM works the same way, which you set to the options
39# you'd normally pass to the groupadd command. This will create
40# groups group1 and group2:
Patrick Williams213cb262021-08-07 19:21:33 -050041GROUPADD_PARAM:${PN} = "-g 880 group1; -g 890 group2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
43# Likewise, we'll manage group3 in the useradd-example-user3 package:
Patrick Williams213cb262021-08-07 19:21:33 -050044GROUPADD_PARAM:${PN}-user3 = "-g 900 group3"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
46do_install () {
47 install -d -m 755 ${D}${datadir}/user1
48 install -d -m 755 ${D}${datadir}/user2
49 install -d -m 755 ${D}${datadir}/user3
50
51 install -p -m 644 file1 ${D}${datadir}/user1/
52 install -p -m 644 file2 ${D}${datadir}/user1/
53
54 install -p -m 644 file2 ${D}${datadir}/user2/
55 install -p -m 644 file3 ${D}${datadir}/user2/
56
57 install -p -m 644 file3 ${D}${datadir}/user3/
58 install -p -m 644 file4 ${D}${datadir}/user3/
59
60 # The new users and groups are created before the do_install
61 # step, so you are now free to make use of them:
62 chown -R user1 ${D}${datadir}/user1
63 chown -R user2 ${D}${datadir}/user2
64 chown -R user3 ${D}${datadir}/user3
65
66 chgrp -R group1 ${D}${datadir}/user1
67 chgrp -R group2 ${D}${datadir}/user2
68 chgrp -R group3 ${D}${datadir}/user3
69}
70
Patrick Williams213cb262021-08-07 19:21:33 -050071FILES:${PN} = "${datadir}/user1/* ${datadir}/user2/*"
72FILES:${PN}-user3 = "${datadir}/user3/*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
74# Prevents do_package failures with:
75# debugsources.list: No such file or directory:
76INHIBIT_PACKAGE_DEBUG_SPLIT = "1"