#!/sbin/openrc-run
# vim:set ts=8 noet ft=sh:

description="Tiny Cloud Bootstrap - main phase"
extra_commands="complete incomplete"

: "${LIBDIR:=$PREFIX/lib}"
. "$LIBDIR"/tiny-cloud/init-main

depend() {
	need net
	before sshd
}

start() {

	is_bootstrapped && return 0

	ebegin "Saving Instance UserData"
	save_userdata
	eend $?

	ebegin "Setting Instance Hostname"
	set_hostname
	eend $?

	ebegin "Installing SSH Keys for $CLOUD_USER User"
	set_ssh_keys "$CLOUD_USER"
	eend $?
}

# allow setting / unsetting of bootstrap state
complete() { bootstrap_complete ; }
incomplete() { bootstrap_incomplete ; }
