| 1 | #!/bin/bash |
| 2 | # |
| 3 | # drbl-autologin-home-reset: Reset autologin account's home directory as initial status. This script in usually run when client boots, i.e. make it as a service. |
| 4 | # |
| 5 | # Version: @(#) /etc/init.d/drbl-autologin-home-reset 1.0 |
| 6 | # |
| 7 | # chkconfig: 35 99 99 |
| 8 | # description: reset autologin account's home directory as initial status when system boot. |
| 9 | # |
| 10 | # For SuSE insserv |
| 11 | ### BEGIN INIT INFO |
| 12 | # Provides: drbl-autologin-home-reset |
| 13 | # Required-Start: nfs portmap |
| 14 | # Required-Stop: nfs portmap |
| 15 | # X-UnitedLinux-Should-Start: |
| 16 | # X-UnitedLinux-Should-Stop: |
| 17 | # Default-Start: 2 3 4 5 |
| 18 | # Default-Stop: 0 1 2 6 |
| 19 | # Description: Reset autologin account's home directory |
| 20 | ### END INIT INFO |
| 21 | # |
| 22 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 23 | # License: GPL |
| 24 | # Modified by Steven Shiau <steven _at_ clonezilla org> to be used in DRBL for RedHat |
| 25 | |
| 26 | # Load DRBL setting and functions |
| 27 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 28 | |
| 29 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 30 | |
| 31 | # |
| 32 | check_if_root |
| 33 | |
| 34 | # get the hostname and auto_login_id |
| 35 | # use client's hostname as the auto-login ID. |
| 36 | if [ -e /etc/debian_version ]; then |
| 37 | # Debian |
| 38 | auto_login_id="$(cat /etc/hostname)" |
| 39 | elif [ -e /etc/SuSE-release ]; then |
| 40 | # SuSE |
| 41 | # SuSE use hostname+domainname, like cat.suse.com.tw |
| 42 | auto_login_id="$(cat /etc/HOSTNAME | sed -e "s/\..*//g")" |
| 43 | else |
| 44 | # RH-like |
| 45 | . /$SYSCONF_PATH/network |
| 46 | auto_login_id="$HOSTNAME" |
| 47 | fi |
| 48 | [ -z "$auto_login_id" ] && echo "No hostname, no autologin account... Program terminated!!!" && exit 1 |
| 49 | # Thanks for Blake to prompt this. Since in client, we can not use /etc/passwd to get the account's home directory. It's NIS/YP. |
| 50 | USER_HOME_DIR=$(bash -c "echo ~$auto_login_id") |
| 51 | auto_login_group="$(id -n -g $auto_login_id)" |
| 52 | if [ -n "$USER_HOME_DIR" -a -d "$USER_HOME_DIR" ]; then |
| 53 | rsync -a --delete --progress /etc/skel/ $USER_HOME_DIR/ |
| 54 | chown -R ${auto_login_id}:${auto_login_group} $USER_HOME_DIR/ |
| 55 | fi |