#! /bin/sh

conffile=/etc/conf.d/ftpbanner

. /etc/init.d/functions.sh
. /usr/share/axis-release/variables
. $conffile

case "$1" in
	start)
		begin "Initializing vftpd banner"

		# Check if this is first-time boot ever or after factory default
		if [ "$FTPBANNER_SET_BANNER" = yes ]; then
			information "detected first-time boot"

			banner=`parhandclient get Brand.ProdFullName - raw` || \
				end 1 "Failed to get parameter " \
				      "\"Brand.ProdFullName\"!"
			[ "$banner" ] || \
				end 1 "Parameter \"Brand.ProdFullName\" " \
				      "has no value!"

			banner="$banner $RELEASE (`echo $BUILDTIME|cut -d ' ' -f -3`) ready."
			information "writing new banner"
			echo "$banner" > /etc/vftpd.banner

			# Mark as done in conf-file so it doesn't happen again
			# until factory default.
			information "writing new config"
			conf=`sed s/[[:space:]]*FTPBANNER_SET_BANNER=yes[[:space:]]*$/FTPBANNER_SET_BANNER=no/ "$conffile"`
			echo "$conf" > "$conffile" || \
				warning "Failed to edit configuration file!"
		else
			information "already initialized"
		fi
		end $?
		;;
	*)
		error "Usage: $0 start"
		;;
esac

exit 0
