SPEC-3723: restructure meta-agl-demo
[AGL/meta-agl-demo.git] / recipes-devtools / run-agl-postinsts / run-agl-postinsts / run-agl-postinsts
1 #!/bin/sh
2 #
3 # Copyright 2017 IoT.bzh.
4
5 # Author: Ronan Le Martret <ronan.lemartret@iot.bzh>
6 #
7
8 # The following script will run all the scriptlets found in #SYSCONFDIR#/agl-postinsts.
9
10 agl_pi_dir="#SYSCONFDIR#/agl-postinsts"
11
12 POSTINST_LOGGING=1
13 LOGFILE=/var/log/agl-postinstall.log
14
15 [ -e $LOGFILE ] && mv ${LOGFILE} ${LOGFILE}.old.$(date +%F--%H%M.%S)
16
17 append_log=">>$LOGFILE 2>&1"
18
19 exec_postinst_scriptlets() {
20     for i in `ls $agl_pi_dir`; do
21         i=$agl_pi_dir/$i
22         echo "Running postinst $i..."
23         [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
24         if [ -x $i ]; then
25             eval sh -c $i $append_log
26             if [ $? -eq 0 ]; then
27                 rm $i
28             else
29                 echo "ERROR: postinst $i failed."
30                 [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
31                 remove_agl_pi_dir=0
32             fi
33         else
34             echo "ERROR: postinst $i do not exists or do not have execute permission."
35             [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i do not exists or do not have execute permission." $append_log
36             remove_agl_pi_dir=0
37         fi
38     done
39 }
40
41 remove_agl_pi_dir=1
42 exec_postinst_scriptlets
43 systemctl daemon-reload
44
45 # since all postinstalls executed successfully, remove the postinstalls directory
46 if [ $remove_agl_pi_dir = 1 ]; then
47     rm -rf $agl_pi_dir
48 fi