#!/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

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

echo
echo "[-----------------------------------------]"
echo "  Gandi - Welcome to your new OS image."
echo 
echo "  Documentation :"
echo "   [EN] http://wiki.gandi.net/en/iaas"
echo "   [FR] http://wiki.gandi.net/fr/iaas"
echo
echo    
echo "  Configuration file for Gandi :"
echo "   /etc/default/gandi or"
echo "   /etc/sysconfig/gandi"
echo "[-----------------------------------------]"
echo
EOF
    fi
    chmod 0755 /etc/update-motd.d/11-help-text

else

    if [ ! -e /etc/motd.gandi ]; then
        cat > /etc/motd.gandi << EOF
[-----------------------------------------]
  Gandi - Welcome to your new OS image.

  Documentation : 
   [EN] http://wiki.gandi.net/en/iaas
   [FR] http://wiki.gandi.net/fr/iaas

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

[-----------------------------------------]
EOF
    fi
    
    motdfile=/etc/motd
    if [ -L "$motdfile" ]; then
        motdfile=`readlink /etc/motd`
    fi
    
    ( uname -a && cat /etc/motd.gandi ) > "$motdfile"
    [ -f /etc/motd.gandi ] && rm /etc/motd.gandi

fi

exit 0
