#!/bin/ksh
#
# $OpenBSD: google_compute_engine.rc,v 1.4 2018/01/14 14:53:25 rpe Exp $

# "meta" script running the following rc.d(8) scripts with the given argument;
# note that daemon_flags, daemon_user, daemon_timeout and daemon_class are not
# passed to the child scripts.
_pkg_scripts="google_accounts_daemon google_clock_skew_daemon google_ip_forwarding_daemon"

if [[ $1 == restart ]]; then
	$0 stop && $0 start
	exit
fi

if [[ $1 == stop ]]; then
	for _i in ${_pkg_scripts}; do _l="${_i} ${_l}"; done
	_pkg_scripts=${_l% }
	/usr/local/bin/python2.7 /usr/local/bin/google_metadata_script_runner \
		--script-type=shutdown || exit
fi

if [[ $1 == start ]]; then
	/usr/local/bin/python2.7 /usr/local/bin/google_instance_setup || exit
	/usr/local/bin/python2.7 /usr/local/bin/google_network_setup || exit
	/usr/local/bin/python2.7 /usr/local/bin/google_metadata_script_runner \
		--script-type=startup || exit
fi

for _i in ${_pkg_scripts}; do
	if [[ -x /etc/rc.d/${_i} ]]; then
		/etc/rc.d/${_i} $@ || exit $?
	fi
done
