blob: 32569e97db874ece039a74a401be06bef5fab7fb [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001# This bbclass is used for image level user/group configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002# 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 Bishop19323692019-04-05 15:28:33 -04005# IMAGE_CLASSES += "extrausers"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006# EXTRA_USERS_PARAMS = "\
Brad Bishop19323692019-04-05 15:28:33 -04007# 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 Williamsc124f4f2015-09-15 14:41:29 -050013# "
14
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015inherit useradd_base
16
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017PACKAGE_INSTALL_append = " ${@['', 'base-passwd shadow'][bool(d.getVar('EXTRA_USERS_PARAMS'))]}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018
19# Image level user / group settings
20ROOTFS_POSTPROCESS_COMMAND_append = " set_user_group;"
21
22# Image level user / group settings
23set_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 Williamsd8c66bc2016-06-20 12:57:21 -050035 perform_useradd "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036 ;;
37 groupadd)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038 perform_groupadd "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 ;;
40 userdel)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 perform_userdel "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 ;;
43 groupdel)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044 perform_groupdel "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 ;;
46 usermod)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 perform_usermod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 ;;
49 groupmod)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 perform_groupmod "${IMAGE_ROOTFS}" "-R ${IMAGE_ROOTFS} $opts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 ;;
52 *)
53 bbfatal "Invalid command in EXTRA_USERS_PARAMS: $cmd"
54 ;;
55 esac
56 # Avoid infinite loop if the last parameter doesn't end with ';'
57 if [ "$setting" = "$remaining" ]; then
58 break
59 fi
60 # iterate to the next setting
61 setting=`echo $remaining | cut -d ';' -f1`
62 remaining=`echo $remaining | cut -d ';' -f2-`
63 done
64}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065
66USERADDEXTENSION ?= ""
67
68inherit ${USERADDEXTENSION}