dbus-1.preinst 5.5 KB

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