blob: cde219518fc3bea80976516f9d5b0f481e0c9ffe [file] [log] [blame]
xf.li86118912025-03-19 20:07:27 -07001#!/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 /etc/deb-postinsts,
9# /etc/ipk-postinsts or /etc/rpm-postinsts or the package manager in
10# case available.
11
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
18 # found the package manager, it has postinsts
19 case $pm in
20 "deb")
21 if [ -s "/var/lib/dpkg/status" ]; then
22 pm_installed=true
23 break
24 fi
25 ;;
26
27 "ipk")
28 if [ -s "/var/lib/opkg/status" ]; then
29 pm_installed=true
30 break
31 fi
32 ;;
33 esac
34
35 pi_dir="/etc/$pm-postinsts"
36
37 # found postinsts directory
38 if [ -d $pi_dir ]; then
39 break
40 fi
41done
42
43remove_rcsd_link () {
44 if [ -n "`which update-rc.d`" ]; then
45 update-rc.d -f run-postinsts remove
46 fi
47}
48
49if ! [ -d $pi_dir ] && ! $pm_installed; then
50 remove_rcsd_link
51 exit 0
52fi
53
54echo "Configuring packages on first boot...."
55echo " (This may take several minutes. Please do not power off the machine.)"
56
57[ -e /etc/default/postinst ] && . /etc/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
70 (sh -c $i $append_log)
71 rm $i
72 else
73 echo "ERROR: postinst $i failed."
74 [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
75 remove_rcsd_link=0
76 fi
77 done
78}
79
80remove_rcsd_link=1
81if $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
95# since all postinstalls executed successfully, remove the rcS.d link
96if [ $remove_rcsd_link = 1 ]; then
97 remove_rcsd_link
98fi