linux_wiki:os_install_post_install

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
linux_wiki:os_install_post_install [2017/09/12 22:55]
billdozor [Post Install Script]
linux_wiki:os_install_post_install [2017/09/12 23:07]
billdozor [Post Install Script]
Line 309: Line 309:
   * This script does all the heavy lifting (system updates, configuration, etc).   * This script does all the heavy lifting (system updates, configuration, etc).
  
-Post install script: Provide logging and error checking+===== Post Install Script: Parent ===== 
 + 
 +**Post install script**: Provide logging and error checking
 <code bash postinstall.sh> <code bash postinstall.sh>
 +#!/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 <----"
 </code> </code>
  
-Post install worker: Perform the actual installations/config work+===== Post Install Script: Worker ===== 
 + 
 +**Post install worker**: Perform the actual installations/config work
 <code bash worker_postinstall.sh> <code bash worker_postinstall.sh>
 </code> </code>
  • linux_wiki/os_install_post_install.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)