#!/bin/sh

# author : Nicolas Chipaux <aegiap@gandi.net> for GANDI
# all rights reserved.

# We load the default functions and configuration for gandi-config
[ -f /etc/gandi/plugins-lib ] && . /etc/gandi/plugins-lib || exit 1
load_config

if [ "$CONFIG_MOTD" -eq 0 ]; then
	exit 0
fi

umask 022

MOTD_MESSAGE="$(cat <<EOF
[-----------------------------------------]
  Gandi - Welcome to your new OS image.

  Documentation :
   [EN] https://docs.gandi.net/en/cloud/
   [FR] https://docs.gandi.net/fr/cloud/

  Configuration file for Gandi :
   /etc/default/gandi or
   /etc/sysconfig/gandi

[-----------------------------------------]
EOF
)"

# update-motd. We place a small script to add Gandi information.
if [ -d /etc/update-motd.d ]; then
	if [ -e /etc/update-motd.d/10-help-text ] && [ ! -e /etc/update-motd.d/11-help-text ]; then
		mv /etc/update-motd.d/10-help-text /root/10-help-text.disabled
	fi
	cat > /etc/update-motd.d/11-help-text <<-GEOF
		#!/bin/sh

		cat <<EOF

		${MOTD_MESSAGE}
		EOF

	GEOF
	chmod 0755 /etc/update-motd.d/11-help-text
else
	cat > "$(realpath /etc/motd)" << EOF
$(uname -a)

${MOTD_MESSAGE}
EOF
fi

exit 0
