systemd-extra-utils.preinst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/sh
  2. bbnote () {
  3. echo "NOTE: $*"
  4. }
  5. bbwarn () {
  6. echo "WARNING: $*"
  7. }
  8. bbfatal () {
  9. echo "ERROR: $*"
  10. exit 1
  11. }
  12. perform_groupadd () {
  13. local rootdir="$1"
  14. local opts="$2"
  15. bbnote "systemd: Performing groupadd with [$opts]"
  16. local groupname=`echo "$opts" | awk '{ print $NF }'`
  17. local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
  18. if test "x$group_exists" = "x"; then
  19. eval flock -x $rootdir/etc -c \"$PSEUDO groupadd \$opts\" || true
  20. group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
  21. if test "x$group_exists" = "x"; then
  22. bbfatal "systemd: groupadd command did not succeed."
  23. fi
  24. else
  25. bbnote "systemd: group $groupname already exists, not re-creating it"
  26. fi
  27. }
  28. perform_useradd () {
  29. local rootdir="$1"
  30. local opts="$2"
  31. bbnote "systemd: Performing useradd with [$opts]"
  32. local username=`echo "$opts" | awk '{ print $NF }'`
  33. local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
  34. if test "x$user_exists" = "x"; then
  35. eval flock -x $rootdir/etc -c \"$PSEUDO useradd \$opts\" || true
  36. user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
  37. if test "x$user_exists" = "x"; then
  38. bbfatal "systemd: useradd command did not succeed."
  39. fi
  40. else
  41. bbnote "systemd: user $username already exists, not re-creating it"
  42. fi
  43. }
  44. perform_groupmems () {
  45. local rootdir="$1"
  46. local opts="$2"
  47. bbnote "systemd: Performing groupmems with [$opts]"
  48. local groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
  49. local username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
  50. bbnote "systemd: Running groupmems command with group $groupname and user $username"
  51. local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
  52. if test "x$mem_exists" = "x"; then
  53. eval flock -x $rootdir/etc -c \"$PSEUDO groupmems \$opts\" || true
  54. mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
  55. if test "x$mem_exists" = "x"; then
  56. bbfatal "systemd: groupmems command did not succeed."
  57. fi
  58. else
  59. bbnote "systemd: group $groupname already contains $username, not re-adding it"
  60. fi
  61. }
  62. OPT=""
  63. SYSROOT=""
  64. if test "x$D" != "x"; then
  65. # Installing into a sysroot
  66. SYSROOT="$D"
  67. OPT="--root $D"
  68. # Make sure login.defs is there, this is to make debian package backend work
  69. # correctly while doing rootfs.
  70. # The problem here is that if /etc/login.defs is treated as a config file for
  71. # shadow package, then while performing preinsts for packages that depend on
  72. # shadow, there might only be /etc/login.def.dpkg-new there in root filesystem.
  73. if [ ! -e $D/etc/login.defs -a -e $D/etc/login.defs.dpkg-new ]; then
  74. cp $D/etc/login.defs.dpkg-new $D/etc/login.defs
  75. fi
  76. # user/group lookups should match useradd/groupadd --root
  77. export PSEUDO_PASSWD="$SYSROOT:/oe/bld/build-CORTEX_1/arago-tmp-external-linaro-toolchain/sysroots/x86_64-linux"
  78. fi
  79. # If we're not doing a special SSTATE/SYSROOT install
  80. # then set the values, otherwise use the environment
  81. if test "x$UA_SYSROOT" = "x"; then
  82. # Installing onto a target
  83. # Add groups and users defined only for this package
  84. GROUPADD_PARAM="${GROUPADD_PARAM}"
  85. USERADD_PARAM=" --system -d / -M --shell /bin/nologin systemd-bus-proxy;"
  86. GROUPMEMS_PARAM="${GROUPMEMS_PARAM}"
  87. fi
  88. # Perform group additions first, since user additions may depend
  89. # on these groups existing
  90. if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x"; then
  91. echo "Running groupadd commands..."
  92. # Invoke multiple instances of groupadd for parameter lists
  93. # separated by ';'
  94. opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  95. remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  96. while test "x$opts" != "x"; do
  97. perform_groupadd "$SYSROOT" "$OPT $opts"
  98. if test "x$opts" = "x$remaining"; then
  99. break
  100. fi
  101. opts=`echo "$remaining" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  102. remaining=`echo "$remaining" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  103. done
  104. fi
  105. if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x"; then
  106. echo "Running useradd commands..."
  107. # Invoke multiple instances of useradd for parameter lists
  108. # separated by ';'
  109. opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  110. remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  111. while test "x$opts" != "x"; do
  112. perform_useradd "$SYSROOT" "$OPT $opts"
  113. if test "x$opts" = "x$remaining"; then
  114. break
  115. fi
  116. opts=`echo "$remaining" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  117. remaining=`echo "$remaining" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  118. done
  119. fi
  120. if test "x`echo $GROUPMEMS_PARAM | tr -d '[:space:]'`" != "x"; then
  121. echo "Running groupmems commands..."
  122. # Invoke multiple instances of groupmems for parameter lists
  123. # separated by ';'
  124. opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  125. remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  126. while test "x$opts" != "x"; do
  127. perform_groupmems "$SYSROOT" "$OPT $opts"
  128. if test "x$opts" = "x$remaining"; then
  129. break
  130. fi
  131. opts=`echo "$remaining" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
  132. remaining=`echo "$remaining" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
  133. done
  134. fi