summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
blob: 11141ec71ff966a1917feaf48e70eb8fad2c1e19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
#
# Copyright 2007 Openedhand Ltd.
#
# Author: Richard Purdie <rpurdie@openedhand.com>
#

# The following script will run all the scriptlets found in #SYSCONFDIR#/deb-postinsts,
# #SYSCONFDIR#/ipk-postinsts or #SYSCONFDIR#/rpm-posinsts.

pi_dir=""
for pm in rpm deb ipk; do
	if [ -d "#SYSCONFDIR#/${pm}-postinsts" ]; then
		pi_dir=#SYSCONFDIR#/${pm}-postinsts
		break
	fi
done

remove_rcsd_link () {
	if [ -n "`which update-rc.d`" ]; then
		update-rc.d -f run-postinsts remove
	fi
}

if [ -z "$pi_dir" ]; then
	remove_rcsd_link
	exit 0
fi

[ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst

remove_pi_dir=1
for i in `ls $pi_dir`; do
	i=$pi_dir/$i
	echo "Running postinst $i..."
	[ "$POSTINST_LOGGING" = "1" ] && echo "Running postinst $i..." >> $LOGFILE
	if [ -x $i ]; then
		if [ "$POSTINST_LOGGING" = "1" ]; then
			sh -c $i >>$LOGFILE 2>&1
		else
			sh -c $i
		fi
		rm $i
	else
		echo "ERROR: postinst $i failed."
		[ "$POSTINST_LOGGING" = "1" ] && echo "ERROR: postinst $i failed." >> $LOGFILE
		remove_pi_dir=0
	fi
done

# since all postinstalls executed successfully, remove the postinstalls directory
# and the rcS.d link
if [ $remove_pi_dir = 1 ]; then
	rm -rf $pi_dir
	remove_rcsd_link
fi
OpenPOWER on IntegriCloud