| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # Description: To set the client to be graphic mode and autologin now |
| 5 | |
| 6 | # Load DRBL setting and functions |
| 7 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 8 | |
| 9 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 10 | |
| 11 | # |
| 12 | usage() { |
| 13 | echo "Force DRBL client machines to re-autologin." |
| 14 | echo "Usage: $0 [OPTION]" |
| 15 | echo "Options:" |
| 16 | echo "-v, --verbose: verbose mode." |
| 17 | echo "-h, --hosts IP_LIST: Instead of all DRBL clients, assign the clients by IP address, like: -h \"192.168.0.1 192.168.0.2\" NOTE!!! You must put \" \" before and after the IP_LIST!" |
| 18 | } |
| 19 | |
| 20 | # |
| 21 | check_if_root |
| 22 | |
| 23 | # main |
| 24 | while [ $# -gt 0 ]; do |
| 25 | case "$1" in |
| 26 | -h|--hosts) |
| 27 | shift; |
| 28 | LIST_HOST="on" |
| 29 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 30 | # skip the -xx option, in case |
| 31 | IP_LIST="$1" |
| 32 | fi |
| 33 | shift ;; |
| 34 | -v|--verbose) |
| 35 | shift; verbose="on" |
| 36 | ;; |
| 37 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 38 | usage >& 2 |
| 39 | exit 2 ;; |
| 40 | *) break ;; |
| 41 | esac |
| 42 | done |
| 43 | |
| 44 | # check if specified host exists |
| 45 | if [ -n "$specified_host" ]; then |
| 46 | [ ! -d "$drblroot/$specified_host" ] && echo "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Program terminated!" && exit 1 |
| 47 | [ -n "$verbose" ] && echo "specified_host: $specified_host" |
| 48 | fi |
| 49 | |
| 50 | # set the host to be processed |
| 51 | # host_list is the IP address of client, like 192.168.1.1... |
| 52 | host_list="" |
| 53 | if [ -n "$specified_host" ]; then |
| 54 | # set the host path |
| 55 | host_list=$drblroot/$specified_host |
| 56 | else |
| 57 | # withoud specified_host, it must be all clients, append each one to $host_list |
| 58 | for ihost in `get-client-ip-list`; do |
| 59 | host_list="$host_list $drblroot/$ihost" |
| 60 | done |
| 61 | fi |
| 62 | |
| 63 | |
| 64 | # set the host to be autologin, make sure it is, then run init 3 and init 5. |
| 65 | for ihost in $host_list; do |
| 66 | # skip those IP not listed in the $IP_LIST |
| 67 | if [ "$LIST_HOST" = "on" ]; then |
| 68 | [ -z "$(echo $IP_LIST | grep -E "\<${ihost##/*/}\>")" ] && continue |
| 69 | fi |
| 70 | host_ip="$(basename $ihost)" |
| 71 | if [ -e /etc/debian_version ]; then |
| 72 | # Debian |
| 73 | # Assume the client uses the same dm with server. |
| 74 | #default_dm="$(drbl-check-dm -h $host_ip)" |
| 75 | default_dm="$(drbl-check-dm)" |
| 76 | restart_dm_cmd="/etc/init.d/$default_dm restart" |
| 77 | else |
| 78 | # RH-like or SuSE |
| 79 | restart_dm_cmd="init 3; sleep 3; init 5" |
| 80 | fi |
| 81 | drbl-login-switch --no-gen-ssi -l 0 --auto --host $host_ip & |
| 82 | drbl-doit -l en --no-ping --hosts $host_ip "$restart_dm_cmd" & |
| 83 | done |