blob: 95dccb9cae11f6db415a285240563c3c47c46e25 [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,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08009# #SYSCONFDIR#/ipk-postinsts or #SYSCONFDIR#/rpm-postinsts or the package manager in
10# case available.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
12# the order of this list is important, do not change!
13backend_list="rpm deb ipk"
14
15pm_installed=false
16
17for pm in $backend_list; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018 # found the package manager, it has postinsts
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019 case $pm in
20 "deb")
21 if [ -s "#LOCALSTATEDIR#/lib/dpkg/status" ]; then
22 pm_installed=true
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 fi
25 ;;
26
27 "ipk")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 if [ -s "#LOCALSTATEDIR#/lib/opkg/status" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 pm_installed=true
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 fi
32 ;;
33 esac
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034
35 pi_dir="#SYSCONFDIR#/$pm-postinsts"
36
37 # found postinsts directory
38 if [ -d $pi_dir ]; then
39 break
40 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041done
42
43remove_rcsd_link () {
44 if [ -n "`which update-rc.d`" ]; then
45 update-rc.d -f run-postinsts remove
46 fi
47}
48
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049if ! [ -d $pi_dir ] && ! $pm_installed; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 remove_rcsd_link
51 exit 0
52fi
53
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054echo "Configuring packages on first boot...."
55echo " (This may take several minutes. Please do not power off the machine.)"
56
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057[ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst
58
59if [ "$POSTINST_LOGGING" = "1" ]; then
60 rm -f $LOGFILE
61 append_log=">>$LOGFILE 2>&1"
62fi
63
64exec_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 Bishopc342db32019-05-15 21:57:59 -040070 (sh -c $i $append_log)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071 rm $i
72 else
73 echo "ERROR: postinst $i failed."
74 [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
Andrew Geissler95ac1b82021-03-31 14:34:31 -050075 remove_rcsd_link=0
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 fi
77 done
78}
79
Andrew Geissler95ac1b82021-03-31 14:34:31 -050080remove_rcsd_link=1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081if $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
91else
92 exec_postinst_scriptlets
93fi
94
Andrew Geissler95ac1b82021-03-31 14:34:31 -050095# since all postinstalls executed successfully, remove the rcS.d link
96if [ $remove_rcsd_link = 1 ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 remove_rcsd_link
98fi