#!/bin/bash

#
# Create softlinks to all backups.
#
if [ ! -d /root/backups ]
then
        mkdir /root/backups
fi

if [ -d /root/backups ]
then
        cd /root/backups
        for i in `find /root/backups -type l`
        do
                rm -f $i
        done

        for serial in `cat /etc/passwd|sed s/:.*//g|grep "^[0-9]\{5\}"`
        do
		# Only create softlink if there is a homedirectory.
		if [ -d /home/$serial ]
		then	
           	     	# Get server name.
			NEONOVA_LIST="/usr/local/neonova/etc/neonova-server.lst"
          	      	name=`cat $NEONOVA_LIST |grep ^$serial|awk -F, '{ print $3 }'`

                	# Create softlinks.
                	command="ln -sf /home/$serial /root/backups/$name"
                	$command
		fi
        done
fi
