useradd-example.bb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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"
  6. LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
  7. SRC_URI = "file://file1 \
  8. file://file2 \
  9. file://file3 \
  10. file://file4"
  11. S = "${WORKDIR}"
  12. PACKAGES =+ "${PN}-user3"
  13. EXCLUDE_FROM_WORLD = "1"
  14. inherit useradd
  15. # You must set USERADD_PACKAGES when you inherit useradd. This
  16. # lists which output packages will include the user/group
  17. # creation code.
  18. USERADD_PACKAGES = "${PN} ${PN}-user3"
  19. # You must also set USERADD_PARAM and/or GROUPADD_PARAM when
  20. # you inherit useradd.
  21. # USERADD_PARAM specifies command line options to pass to the
  22. # useradd command. Multiple users can be created by separating
  23. # the commands with a semicolon. Here we'll create two users,
  24. # user1 and user2:
  25. USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -r -s /bin/bash user1; -u 1201 -d /home/user2 -r -s /bin/bash user2"
  26. # user3 will be managed in the useradd-example-user3 pacakge:
  27. # As an example, we use the -P option to set clear text password for user3
  28. USERADD_PARAM_${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -P 'user3' user3"
  29. # GROUPADD_PARAM works the same way, which you set to the options
  30. # you'd normally pass to the groupadd command. This will create
  31. # groups group1 and group2:
  32. GROUPADD_PARAM_${PN} = "-g 880 group1; -g 890 group2"
  33. # Likewise, we'll manage group3 in the useradd-example-user3 package:
  34. GROUPADD_PARAM_${PN}-user3 = "-g 900 group3"
  35. do_install () {
  36. install -d -m 755 ${D}${datadir}/user1
  37. install -d -m 755 ${D}${datadir}/user2
  38. install -d -m 755 ${D}${datadir}/user3
  39. install -p -m 644 file1 ${D}${datadir}/user1/
  40. install -p -m 644 file2 ${D}${datadir}/user1/
  41. install -p -m 644 file2 ${D}${datadir}/user2/
  42. install -p -m 644 file3 ${D}${datadir}/user2/
  43. install -p -m 644 file3 ${D}${datadir}/user3/
  44. install -p -m 644 file4 ${D}${datadir}/user3/
  45. # The new users and groups are created before the do_install
  46. # step, so you are now free to make use of them:
  47. chown -R user1 ${D}${datadir}/user1
  48. chown -R user2 ${D}${datadir}/user2
  49. chown -R user3 ${D}${datadir}/user3
  50. chgrp -R group1 ${D}${datadir}/user1
  51. chgrp -R group2 ${D}${datadir}/user2
  52. chgrp -R group3 ${D}${datadir}/user3
  53. }
  54. FILES_${PN} = "${datadir}/user1/* ${datadir}/user2/*"
  55. FILES_${PN}-user3 = "${datadir}/user3/*"
  56. # Prevents do_package failures with:
  57. # debugsources.list: No such file or directory:
  58. INHIBIT_PACKAGE_DEBUG_SPLIT = "1"