#!/bin/sh
#
# autologin-home-reset: Reset autologin account's home directory as initial status.
#
# Version:      @(#) /etc/init.d/autologin-home-reset 1.0
#
# chkconfig: 35 99 99
# description: reset autologin account's home directory as initial status when system boot.
#
# Author: Steven Shiau <steven@nchc.org.tw>
# License: GPL
# Modified by Steven Shiau <steven@nchc.org.tw> to be used in DRBL for RedHat
# NOTE!!!
# UGLY!!! UGLY!!!  UGLY!!! UGLY!!! UGLY!!! UGLY!!!
# This is a UGLY code...
# Here we just assume autologin user's home directory is in /home

# Load DRBL setting and functions
if [ ! -f "/opt/drbl/sbin/drbl-conf-functions" ]; then
  echo "Unable to find /opt/drbl/sbin/drbl-conf-functions! Program terminated!" 
  exit 1
fi
. /opt/drbl/sbin/drbl-conf-functions

#
check_if_root

# get the hostname and auto_login_id
. /etc/sysconfig/network
auto_login_id="$HOSTNAME"
[ -z "$auto_login_id" ] && echo "No hostname, no autologin account...Program terminated!!!" && exit 1
# UGLY!!! UGLY!!!  UGLY!!! UGLY!!! UGLY!!! UGLY!!!
# Ugly here... maybe to use "ypcat passwd" to get the user home, but it's not
# safe to export server's /var/yp...
# Here we just assume autologin user's home directory is in /home
USER_HOME_DIR="/home/$auto_login_id"
if [ -d "$USER_HOME_DIR" ]; then
  rsync -a --delete --progress /etc/skel/ $USER_HOME_DIR/
  chown -R $auto_login_id.$auto_login_id /etc/skel/ $USER_HOME_DIR/
fi
