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