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