Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | # This bbclass is used for image level user/group configuration. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # Inherit this class if you want to make EXTRA_USERS_PARAMS effective. |
| 3 | |
| 4 | # Below is an example showing how to use this functionality. |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 5 | # IMAGE_CLASSES += "extrausers" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # EXTRA_USERS_PARAMS = "\ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 7 | # useradd -p '' tester; \ |
| 8 | # groupadd developers; \ |
| 9 | # userdel nobody; \ |
| 10 | # groupdel -g video; \ |
| 11 | # groupmod -g 1020 developers; \ |
| 12 | # usermod -s /bin/sh tester; \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | # " |
| 14 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | inherit useradd_base |
| 16 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 17 | PACKAGE_INSTALL:append = " ${@['', 'base-passwd shadow'][bool(d.getVar('EXTRA_USERS_PARAMS'))]}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
| 19 | # Image level user / group settings |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 20 | ROOTFS_POSTPROCESS_COMMAND:append = " set_user_group;" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | |
| 22 | # Image level user / group settings |
| 23 | set_user_group () { |
| 24 | user_group_settings="${EXTRA_USERS_PARAMS}" |
| 25 | export PSEUDO="${FAKEROOTENV} ${STAGING_DIR_NATIVE}${bindir}/pseudo" |
| 26 | setting=`echo $user_group_settings | cut -d ';' -f1` |
| 27 | remaining=`echo $user_group_settings | cut -d ';' -f2-` |
| 28 | while test "x$setting" != "x"; do |
| 29 | cmd=`echo $setting | cut -d ' ' -f1` |
| 30 | opts=`echo $setting | cut -d ' ' -f2-` |
| 31 | # Different from useradd.bbclass, there's no file locking issue here, as |
| 32 | # this setting is actually a serial process. So we only retry once. |
| 33 | case $cmd in |
| 34 | useradd) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 35 | perform_useradd "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | ;; |
| 37 | groupadd) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 38 | perform_groupadd "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | ;; |
| 40 | userdel) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 41 | perform_userdel "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | ;; |
| 43 | groupdel) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | perform_groupdel "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | ;; |
| 46 | usermod) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 47 | perform_usermod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | ;; |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 49 | passwd-expire) |
| 50 | perform_passwd_expire "${IMAGE_ROOTFS}" "$opts" |
| 51 | ;; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | groupmod) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | perform_groupmod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | ;; |
| 55 | *) |
| 56 | bbfatal "Invalid command in EXTRA_USERS_PARAMS: $cmd" |
| 57 | ;; |
| 58 | esac |
| 59 | # Avoid infinite loop if the last parameter doesn't end with ';' |
| 60 | if [ "$setting" = "$remaining" ]; then |
| 61 | break |
| 62 | fi |
| 63 | # iterate to the next setting |
| 64 | setting=`echo $remaining | cut -d ';' -f1` |
| 65 | remaining=`echo $remaining | cut -d ';' -f2-` |
| 66 | done |
| 67 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 68 | |
| 69 | USERADDEXTENSION ?= "" |
| 70 | |
| 71 | inherit ${USERADDEXTENSION} |