blob: 307feb71879e21aab0a8b521fe3326558064f8f5 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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 Williamsc0f7c042017-02-23 20:41:17 -06009# #SYSCONFDIR#/ipk-postinsts or #SYSCONFDIR#/rpm-postinsts.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
11# the order of this list is important, do not change!
12backend_list="rpm deb ipk"
13
14pm_installed=false
15
16for pm in $backend_list; do
17 pi_dir="#SYSCONFDIR#/$pm-postinsts"
18
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019 if [ ! -d $pi_dir ]; then
20 continue
21 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 # found the package manager, it has postinsts
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 case $pm in
25 "deb")
26 if [ -s "#LOCALSTATEDIR#/lib/dpkg/status" ]; then
27 pm_installed=true
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 fi
29 ;;
30
31 "ipk")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 if [ -s "#LOCALSTATEDIR#/lib/opkg/status" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 pm_installed=true
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 fi
35 ;;
36 esac
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038done
39
40remove_rcsd_link () {
41 if [ -n "`which update-rc.d`" ]; then
42 update-rc.d -f run-postinsts remove
43 fi
44}
45
Brad Bishop316dfdd2018-06-25 12:45:53 -040046if ! [ -d $pi_dir ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 remove_rcsd_link
48 exit 0
49fi
50
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051echo "Configuring packages on first boot...."
52echo " (This may take several minutes. Please do not power off the machine.)"
53
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054[ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst
55
56if [ "$POSTINST_LOGGING" = "1" ]; then
57 rm -f $LOGFILE
58 append_log=">>$LOGFILE 2>&1"
59fi
60
61exec_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
77remove_pi_dir=1
78if $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
88else
89 exec_postinst_scriptlets
90fi
91
92# since all postinstalls executed successfully, remove the postinstalls directory
93# and the rcS.d link
94if [ $remove_pi_dir = 1 ]; then
95 rm -rf $pi_dir
96 remove_rcsd_link
97fi