run-postinsts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. #
  3. # Copyright 2007 Openedhand Ltd.
  4. #
  5. # Author: Richard Purdie <rpurdie@openedhand.com>
  6. #
  7. # The following script will run all the scriptlets found in /etc/deb-postinsts,
  8. # /etc/ipk-postinsts or /etc/rpm-postinsts.
  9. # the order of this list is important, do not change!
  10. backend_list="rpm deb ipk"
  11. pm_installed=false
  12. for pm in $backend_list; do
  13. pi_dir="/etc/$pm-postinsts"
  14. [ -d $pi_dir ] && break
  15. case $pm in
  16. "deb")
  17. if [ -s "/var/lib/dpkg/status" ]; then
  18. pm_installed=true
  19. break
  20. fi
  21. ;;
  22. "ipk")
  23. if [ -s "/var/lib/opkg/status" ]; then
  24. pm_installed=true
  25. break
  26. fi
  27. ;;
  28. esac
  29. done
  30. remove_rcsd_link () {
  31. if [ -n "`which update-rc.d`" ]; then
  32. update-rc.d -f run-postinsts remove
  33. fi
  34. }
  35. if [ -z "$pi_dir" ]; then
  36. remove_rcsd_link
  37. exit 0
  38. fi
  39. [ -e /etc/default/postinst ] && . /etc/default/postinst
  40. if [ "$POSTINST_LOGGING" = "1" ]; then
  41. rm -f $LOGFILE
  42. append_log=">>$LOGFILE 2>&1"
  43. fi
  44. exec_postinst_scriptlets() {
  45. for i in `ls $pi_dir`; do
  46. i=$pi_dir/$i
  47. echo "Running postinst $i..."
  48. [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
  49. if [ -x $i ]; then
  50. eval sh -c $i $append_log
  51. rm $i
  52. else
  53. echo "ERROR: postinst $i failed."
  54. [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
  55. remove_pi_dir=0
  56. fi
  57. done
  58. }
  59. remove_pi_dir=1
  60. if $pm_installed; then
  61. case $pm in
  62. "ipk")
  63. eval opkg configure $append_log
  64. ;;
  65. "deb")
  66. eval dpkg --configure -a $append_log
  67. ;;
  68. esac
  69. else
  70. exec_postinst_scriptlets
  71. fi
  72. # since all postinstalls executed successfully, remove the postinstalls directory
  73. # and the rcS.d link
  74. if [ $remove_pi_dir = 1 ]; then
  75. rm -rf $pi_dir
  76. remove_rcsd_link
  77. fi