#!/bin/bash echo "Welcome to PO' NYS (pronounced either \"po' niss\" or \"ponies\"!" echo "Version 01292k4-a" ###### ###### ## ## FUNCTIONS ## ###### ###### ############################## Debugging Functions ###################### function BUGPAUSE { echo " " echo "-----------------------------------------------------------" echo " MANUAL BUG CHECK!" echo " Is the program doing what you expect? Please " echo " review preceeding output for correctness. Thank you." echo "-----------------------------------------------------------" echo " " ask "Continue? [Y/n]" if [ $? -ne 0 ]; then { exit 100 } fi } ########################## Program Functions ############################# function MAKE_HOMES { for i in `cat ponys-users`; do { echo "RSYNCing home directory from $1 for user $i..." rsync -e ssh -av $1:/home/$i/ /home/$i if [ $? -ne 0 ]; then { ERROR 3 "PONYS can't get the home directory info for $1" } fi } done } function GET_SECURITY_FILES { for i in passwd group shadow gshadow; do { echo "Processing the file $i from host $1..." rsync -e ssh -av $1:/etc/$i /etc/$i if [ $? -ne 0 ]; then { ERROR 4 "PONYS is unable to obtain $i from $1" } fi } done } function GET_SAMBA_PASSWD { echo "Updating Samba passwords files from $1..." scp $1:/etc/samba/smbpasswd /etc/samba if [ $? -ne 0 ]; then { ERROR 5 "PONYS is unable to get the smbpasswd file from $1" } fi } ####################### RATHER COOL ERROR-HANDLING ############################# function ERROR { echo "-----------------" echo "| ABEND: Code $1 |" echo "-------------------------------------------------------------------------" echo " Bummer! An error occurred!" echo " Don't you just hate it when..." echo "${2}?" echo "==========================" echo " Maybe this will help...." echo "==========================" echo "Syntax:" echo " ponys [-c| --clone]" echo " " echo "Example:" echo " ponys liberty -c" echo " " echo " \"liberty\" specifies that a host called liberty is to be the source of" echo " passwd, group, shadow, and gshadow" echo " " echo " The parameter \"-c\" specifies that home directories of the users listed" echo " in ponys-users are to be duplicated as well." echo " " echo "NOTE: PONYS is only to be used after the master files have been created." echo "-------------------------------------------------------------------------" exit $1 } ############################################################################## ############################################################################## ################################# MAIN ####################################### ############################################################################## ############################################################################## PATH=/usr/local/sbin:/usr/local/bin:/sbin:/root/bin:/usr/bin:/bin:/usr/sbin if ! [ -f ./ponys-users ]; then { ERROR 1 "The ponys_users file is missing or not in the current directory" } fi if [ -z $1 ]; then { ERROR 2 "You forget to specify a master server from which to get the files" } else { MASTERHOST=$1 } fi clear clear echo "Stage 1: Synchronizing Permissions Control Files from Master $1." GET_SECURITY_FILES $MASTERHOST clear echo "Stage 2: Synchronizing SAMBA permissions from Master $1." echo "Would you like to synchronize SAMBA (Choose 'no' if you do not wish to " echo "perform this task, or you are not using SAMBA.)" echo " " ask if [ $? -eq 0 ]; then GET_SAMBA_PASSWD $MASTERHOST else echo "Skipping processing of SAMBA at your request." fi clear echo "Stage 3: Processing home directories." case "$2" in clone|CLONE|--clone|--CLONE|-c|-C|c|C|Clone|--Clone) MAKE_HOMES $MASTERHOST ;; *) echo "HOME Directory Cloning from $MASTERHOST is DISABLED!" echo "NO HOME DIRECTORIES created!" ;; esac echo "Processing is complete." exit 0