#!/bin/bash PROGNAME=`basename $0` # ============================= 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 " " echo "Args so far:" echo "ARG1: $ARG1 " echo "ARG2: $ARG2 " echo "ARG3: $ARG3 " echo "ARG4: $ARG4 " echo " " ask "Continue? [Y/n]" y if [ $? -ne 0 ]; then { exit 100 } fi } #### #### # # Error Handler. # #### #### function ERROR { clear 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 "==========================" SYNTAX exit $1 } #### #### # # - SYNTAX -------- Bet you cannot guess what this does. # #### #### function SYNTAX { MORE "Do you wish to view the Syntax for `VERSION`" y echo "SYNTAX: Program $PROGNAME" echo " " MORE "Do you wish to continue?" y echo "NOTES: " echo " " MORE "Do you wish to continue?" y echo "NOTES:" echo " " echo "**** End of help. Don't you wish there was more? ****" echo "Strike a key to exit help." read DUMMY return } #### #### # # MORE # #### #### function MORE() { ask "$1 [y/n]" $2 if [ $? -eq 0 ]; then return else exit 0 fi } #### #### # # - CHECKCMD --------- Locates the system cammands used by this script.------- # This makes sure the commands we need exist. If a command is missing, # this function will cause the script to abort. # #### #### function CHECKCMD { # Check for required *NIX executable commands. echo "---->In CHECKCMD...." for i in id seq echo hostname touch cp mv rm rsync mount smbmount ask; do which $i; if [ $? -ne 0 ]; then ERROR 1 "the command $i is missing from the system" fi; done } #### #### # # CHECK_HOST ----Aborts the program if the hostname keyfile is missing. # #### #### function CHECK_HOST() { AUTHORIZED_HOST=`cat /root/bin/authorized_hostkey` if [ $AUTHORIZED_HOST = `hostname` ]; then { echo "Host $AUTHORIZED_HOST validated." } else { ERROR 20 "When you try to run `basename $0` on an unauthorized backup host" } fi } #### #### # # - R_U_ROOT ----- Aborts the program if the person running it is not root. # #### #### function R_U_ROOT { ID=`id -u` if [ $ID -ne 0 ]; then { echo "$PROGNAME is a potentially dangerous program." echo "Therefore it is only to be run by the root user." echo "You appear to be running it as `id -nu`." echo "Please try again as root or have the system administrator run" echo "$PROGNAME for you." ERROR 10 "you forget to log in as root first" } fi } #### #### # # - GETARGS ----------- Converts command-line args to appropriate parameters. Otherwise, # it prompts for the necessary arguments. # #### #### function GETARGS { echo "IN GETARGS...." if [ -z $1 ]; then { echo "" read ARG1 if [ -z $ARG1 ]; then echo "Setting backup path to /usr2/backup." ARG1="/usr2/backup" fi } else ARG1=$1 fi } #### #### # # Reports the version for this program. # #### #### function VERSION { echo "$PROGNAME Version 04292k4-a, NEWSCRIPT Version 11172k3-a" } #======================================= No more functions. ========== ############################################################################# ################################# #################################### ################################# MAIN #################################### ################################# #################################### ############################################################################# case "$1" in v|V|-v|-V|--version|--VERSION|--Version|-version|-Version|-VERSION--ver|--Ver|--VER|-ver|-Ver|-VER) VERSION exit 0 ;; h|H|-h|-H|--help|--HELP|--Help|HELP|help|Help|-help|-HELP|-Help) SYNTAX exit 0 ;; esac #CHECK_HOST R_U_ROOT VERSION CHECKCMD GETARGS $1 echo "Processing Linux Boxen" for i in `cat /usr/local/bin/linux_boxen`; do { if [ -d ${ARG1}/$i ]; then echo "${ARG1}/$i already exists. Nothing done." else { echo "Making ${ARG1}/$i" mkdir -p ${ARG1}/$i } fi } done for i in `cat /usr/local/bin/windows_boxen`; do { for j in c-${i} d-${i} e-${i} f-${i}; do { if [ -d ${ARG1}/$i/$j ]; then echo "${ARG1}/$i/$j already exists. Nothing done." else { echo "Making ${ARG1}/$i/$j" mkdir -p ${ARG1}/$i/$j } fi if [ -d /mnt/$i/$j ]; then echo "/mnt/$i/$j already exists. Skipped this iteration." else { echo "Making samba mount point at /mnt/$i/$j" mkdir -p /mnt/$i/$j } fi } done } done echo "Tree structure created." echo "End run--------------<<<<<<<".