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