#!/bin/bash # lab-template # Description: This script, based on singular argument, either does setup or # grading for the particular lab # Subcommands: # setup - perform any configuration adjustments to the system # grade - perform any evaluation steps to the system # The setup function needs to be run on desktop # The grade function needs to be run on server # Use of the template: # Rename the file to lab- # Adjust the comments above # Modify the two functions, lab_setup and lab_grade to perform the steps # you desire. Remember the functions receive MYHOST as an argument so you # can branch and perform different steps on the particular host or generate # message if run from the wrong host # Remove these Use of template comments # Initialize and set some variables MYHOST="" CMD="" DEBUG=true # Source library of functions source /usr/local/bin/labtool.shlib trap on_exit EXIT # Additional functions for this shell script function print_usage { echo "This script controls the setup and grading of this lab." echo "Usage: $(basename $0) COMMAND" echo " $(basename $0) -h|--help" echo "COMMAND is one of:" echo " setup - perform any setup steps for this lab on this machine" echo " grade - perform any grading steps and report on this machine" } function lab_setup { VMNAME=server case $VMNAME in desktop) echo "Steps to set up lab on desktop" # Put in the steps to set up the lab # Change to the example of server) if should only run # there - and adjust the catchall message with *) print_FAIL && echo "The setup script needs to be run on server" ;; server) # Obviously adjust this to actual commands if script needs # to run on server - and adjust the catchall message with *) echo "# This line is completely borked, you should remove it." >> /etc/fstab echo "/dev/bad_device /fluffy xfs defaults 0 2" >> /etc/fstab reboot ;; *) # Should never get here, but what the hey.... print_FAIL && echo "The setup script needs to be run on server" ;; esac } function lab_grade { VMNAME=server case $VMNAME in desktop) echo "Steps to grade lab on desktop" # Put in the steps to grade the lab (use print_PASS or print_FAIL) # Change to the example of server) if should only run # there - and adjust the catchall message with *) print_FAIL && echo "The grade script needs to be run on server" ;; server) # Obviously adjust this to actual commands if script needs # to run on server - and adjust the catchall message with *) echo "There is grading for this script." ;; *) # Should never get here, but what the hey.... print_FAIL && echo "The grade script needs to be run on desktop" ;; esac } # Main area # Fail out if not running as root check_root # Process command line # Parse input case $1 in setup|grade) CMD=$1 ;; -h|--help) print_usage exit 0 ;; *) echo Bad option $1 print_usage exit 1 ;; esac # Validation [ -z "$CMD" ] && debug "Missing command" && print_usage && exit 1 # Get local system information get_X # Branch based on short (without number) hostname case $MYHOST in desktop|server) lab_$CMD $MYHOST ;; *) debug "Bad or missing hostname - $MYHOST" debug "This command needs to be run on desktop or server" exit 3 ;; esac