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, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | # #SYSCONFDIR#/ipk-postinsts or #SYSCONFDIR#/rpm-postinsts. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | if [ ! -d $pi_dir ]; then |
| 20 | continue |
| 21 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | # found the package manager, it has postinsts |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | case $pm in |
| 25 | "deb") |
| 26 | if [ -s "#LOCALSTATEDIR#/lib/dpkg/status" ]; then |
| 27 | pm_installed=true |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | fi |
| 29 | ;; |
| 30 | |
| 31 | "ipk") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | if [ -s "#LOCALSTATEDIR#/lib/opkg/status" ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | pm_installed=true |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | fi |
| 35 | ;; |
| 36 | esac |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 37 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | done |
| 39 | |
| 40 | remove_rcsd_link () { |
| 41 | if [ -n "`which update-rc.d`" ]; then |
| 42 | update-rc.d -f run-postinsts remove |
| 43 | fi |
| 44 | } |
| 45 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 46 | if ! [ -d $pi_dir ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | remove_rcsd_link |
| 48 | exit 0 |
| 49 | fi |
| 50 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | echo "Configuring packages on first boot...." |
| 52 | echo " (This may take several minutes. Please do not power off the machine.)" |
| 53 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | [ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst |
| 55 | |
| 56 | if [ "$POSTINST_LOGGING" = "1" ]; then |
| 57 | rm -f $LOGFILE |
| 58 | append_log=">>$LOGFILE 2>&1" |
| 59 | fi |
| 60 | |
| 61 | exec_postinst_scriptlets() { |
| 62 | for i in `ls $pi_dir`; do |
| 63 | i=$pi_dir/$i |
| 64 | echo "Running postinst $i..." |
| 65 | [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log |
| 66 | if [ -x $i ]; then |
| 67 | eval sh -c $i $append_log |
| 68 | rm $i |
| 69 | else |
| 70 | echo "ERROR: postinst $i failed." |
| 71 | [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log |
| 72 | remove_pi_dir=0 |
| 73 | fi |
| 74 | done |
| 75 | } |
| 76 | |
| 77 | remove_pi_dir=1 |
| 78 | if $pm_installed; then |
| 79 | case $pm in |
| 80 | "ipk") |
| 81 | eval opkg configure $append_log |
| 82 | ;; |
| 83 | |
| 84 | "deb") |
| 85 | eval dpkg --configure -a $append_log |
| 86 | ;; |
| 87 | esac |
| 88 | else |
| 89 | exec_postinst_scriptlets |
| 90 | fi |
| 91 | |
| 92 | # since all postinstalls executed successfully, remove the postinstalls directory |
| 93 | # and the rcS.d link |
| 94 | if [ $remove_pi_dir = 1 ]; then |
| 95 | rm -rf $pi_dir |
| 96 | remove_rcsd_link |
| 97 | fi |