#!/bin/bash # Title: postinstall.sh # Description: Wrapper script to start the postinstall_worker.sh script with logging. # Last Updated: 2016-10-24 # Most Recent Changes:-Initial release ####################################################################################### function print_usage { echo echo " Usage: postinstall.sh [-y]" echo echo " This script(${0}), provides logging for its worker script, worker_postinstall.sh" echo echo " Recommended action" echo " 1) Mount: mount -t nfs nfs-server:/admin /mnt" echo " 2) Execute parent script: /mnt/deploy/postinstall.sh [-y]" echo " -y => Yes, execute script without prompting." echo exit 1 } #===================================== # Get Script Arguments #===================================== # Reset POSIX variable in case it has been used previously in this shell OPTIND=1 # By default, do not force run script. Prompt for running or not. force_run_script="no" while getopts "hy" opt; do case "${opt}" in h) # -h (help) argument print_usage exit 0 ;; y) # -y (yes to running script) argument force_run_script="yes" ;; *) # invalid argument print_usage exit 0 ;; esac done ##==================== ## Pre-req checks ##==================== ## Ensure we are root ## if [[ $(id --user) -ne 0 ]]; then echo ">>Error; this script must be run as root. Exiting..." exit 1 fi ##====================== ## Set Script Variables ##====================== # Set base path from executed command (relative or full path works) base_path="$(echo ${0} | sed 's/postinstall.sh//')" # Set log file and script locations postinstall_log="/root/postinstall.log" postinstall_worker="worker_postinstall.sh" ##================ ## Setup Logging ##================ echo -e ">>Logging output and errors to: ${postinstall_log}\n" # Clear log and timestamp the beginning cat /dev/null > ${postinstall_log} echo -e "---- Log Started: $(date) ----\n" >> ${postinstall_log} ##========================= ## Execute External Scripts ##========================= # Start script, pass base path argument if [[ ${force_run_script} == "no" ]]; then ${base_path}${postinstall_worker} -d ${base_path} 2>&1 | tee -a ${postinstall_log} elif [[ ${force_run_script} == "yes" ]]; then ${base_path}${postinstall_worker} -d ${base_path} -y 2>&1 | tee -a ${postinstall_log} else echo -e ">>Error: Unknown value for force_run_script (${force_run_script}). Exiting..." exit 1 fi ##========================== ## Close Logs, Show Location ##========================== # Ending timestamp echo -e "\n---- Log Completed: $(date) ----" >> ${postinstall_log} # Reminder of where the log file is at echo -e "\n>>Logged output and errors were sent to: ${postinstall_log}\n" echo -e "----> Remember to umount NFS before rebooting <----"