config-init.sh: degrade to non-bash gracefully
[invirt/packages/invirt-base.git] / files / lib / init / config-init.sh
1 # For a package which only configures another, "parent" package.
2 #
3 # Global variable PARENTPACKAGE names parent; unset for no parent,
4 # array for (zero or one or) many parents.
5 #
6 # Global variable PACKAGE names this package, for log message.
7 #
8 # If BASH_VERSION is null or unset, accepts only one parent in
9 # PARENTPACKAGE, or empty for zero.
10
11 . /lib/init/vars.sh
12 . /lib/lsb/init-functions
13 . /lib/init/gen-files.sh
14
15 if [ $BASH_VERSION ]; then
16   handle_parents () {
17     for p in "${PARENTPACKAGE[@]}"; do
18       invoke-rc.d "$p" "$1"
19     done
20   }
21 else
22   handle_parents () {
23     if [ -n "$PARENTPACKAGE" ]; then
24       invoke-rc.d "$PARENTPACKAGE" "$1"
25     fi
26   }
27 fi
28
29 config_init () {
30   case "$1" in
31     start|reload|force-reload|restart)
32       log_begin_msg "Reloading config for $PACKAGE"
33       gen_files
34       log_end_msg $?
35       handle_parents "$1"
36       ;;
37     stop)
38       handle_parents "$1"
39       ;;
40     *)
41       log_success_msg "Usage: /etc/init.d/$PACKAGE {start|reload|force-reload|restart|stop}"
42       ;;
43   esac
44 }