|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/scripts/working/Liddle |
| 4 | + |
| 5 | +# ------------------------------------------------------------------ |
| 6 | +# * * * |
| 7 | +# Liddle Script |
| 8 | +# * * * |
| 9 | +# ------------------------------------------------------------------- |
| 10 | +# * * * |
| 11 | +# Begin Main Script Variables |
| 12 | +# * * * |
| 13 | +# ------------------------------------------------------------------- |
| 14 | + |
| 15 | +declare -A core |
| 16 | +declare -A vars |
| 17 | +declare -A args |
| 18 | + |
| 19 | +# Program name |
| 20 | +core[PROGNAME]=$(basename $0) |
| 21 | +# Directory script is being run from |
| 22 | +core[USRDIR]=$(pwd)"/" |
| 23 | +# Directory of script |
| 24 | +core[DIR]="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )""/""logs/" |
| 25 | +# Store new arguments given to script in array |
| 26 | +NEWARGS=("${@}") |
| 27 | +# Will be used to store number of arguments not options given to the script |
| 28 | +core[ARGNUM]="" |
| 29 | +# Used for counters in script |
| 30 | +core[COUNT]=0 |
| 31 | +# Argument 1 Given to Script |
| 32 | +core[ARG1]=$1 |
| 33 | +# Logfile name |
| 34 | +core[LOG]="${core[DIR]}${core[PROGNAME]}.log" |
| 35 | +# Pipe name |
| 36 | +core[PIPE]="${core[DIR]}${core[PROGNAME]}.pipe" |
| 37 | +# Set initial endphase variable |
| 38 | +core[ENDPHASE]="false" |
| 39 | +# Has the script finished the getState function yet |
| 40 | +# I.E. are the CMD and PHASE variables accurate |
| 41 | +core[EXECUTION]="false" |
| 42 | +# Has the script began logging yet |
| 43 | +# THIS ARGUMENT MUST BE RESET TO FALSE EACH RUN OF THE SCRIPT |
| 44 | +# AS THE VALUE IS NOT CHANGED TO FALSE UNTIL AFTER SAVING OF VARS |
| 45 | +core[LOGGING]="false" |
| 46 | +# Execution argument given or not |
| 47 | +core[EXARG]="false" |
| 48 | +# PHASE Variable Default |
| 49 | +core[PHASE]=1 |
| 50 | +# CMD Variable Default |
| 51 | +core[CMD]=1 |
| 52 | + |
| 53 | +# ------------------------------------------------------------------- |
| 54 | +# * * * |
| 55 | +# End Main Script Variables |
| 56 | +# * * * |
| 57 | +# ------------------------------------------------------------------- |
| 58 | + |
| 59 | +# ------------------------------------------------------------------- |
| 60 | +# * * * |
| 61 | +# Begin Script Functions |
| 62 | +# * * * |
| 63 | +# ------------------------------------------------------------------- |
| 64 | + |
| 65 | +function cleanUp { |
| 66 | + |
| 67 | +# -------------------------------------------------- |
| 68 | +# Function to remove old files |
| 69 | +# Ignores any arguments given |
| 70 | +# -------------------------------------------------- |
| 71 | + |
| 72 | + if [ -e "${core[DIR]}${core[PROGNAME]}.end" ]; then |
| 73 | + |
| 74 | + rm -f "${core[DIR]}${core[PROGNAME]}.end" |
| 75 | + |
| 76 | + fi |
| 77 | + |
| 78 | + if [ -e "${core[DIR]}${core[PROGNAME]}.log" ]; then |
| 79 | + |
| 80 | + rm -f "${core[DIR]}${core[PROGNAME]}.log" |
| 81 | + |
| 82 | + fi |
| 83 | + if [ -e "${core[PIPE]}" ]; then |
| 84 | + rm -f "${core[PIPE]}" |
| 85 | + fi |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | +function trapped { |
| 90 | + |
| 91 | +# -------------------------------------------------- |
| 92 | +# Function for Trapping Interupts |
| 93 | +# Ignores any arguments given |
| 94 | +# -------------------------------------------------- |
| 95 | + |
| 96 | + errorExit ${core[CMD]} ${core[LINENO]} "Script terminated by user" |
| 97 | + |
| 98 | +} |
| 99 | + |
| 100 | +. /root/scripts/Liddle/save.liddle |
| 101 | +. /root/scripts/Liddle/logging.liddle |
| 102 | +. /root/scripts/Liddle/error.liddle |
| 103 | +. /root/scripts/Liddle/args.liddle |
| 104 | +. /root/scripts/Liddle/load.liddle |
| 105 | + |
| 106 | +# ------------------------------------------------------------------- |
| 107 | +# * * * |
| 108 | +# Begin Traps |
| 109 | +# * * * |
| 110 | +# ------------------------------------------------------------------- |
| 111 | + |
| 112 | +# Trap to watch for interupt, runs trapped function |
| 113 | +trap trapped SIGHUP SIGINT SIGTERM |
| 114 | + |
| 115 | + |
| 116 | +# ------------------------------------------------------------------- |
| 117 | +# * * * |
| 118 | +# End Traps |
| 119 | +# * * * |
| 120 | +# ------------------------------------------------------------------- |
| 121 | + |
| 122 | +core[EXECUTION]="true" |
| 123 | + |
| 124 | +processArgs |
| 125 | + |
| 126 | +if [ "${loadfile}" == "true" ]; then |
| 127 | + echo "Fetching progress from file" |
| 128 | + . ${core[DIR]}${core[PROGNAME]}.end || errorExit ${core[CMD]} $LINENO "Failed to load" |
| 129 | + startLog continue |
| 130 | + echo "Continuing from prior exit" |
| 131 | + echo |
| 132 | + sleep 1 |
| 133 | +else |
| 134 | + # Start log and override |
| 135 | + startLog |
| 136 | +fi |
| 137 | + |
| 138 | +while [ ${core[ENDPHASE]} == false ]; do |
| 139 | + case ${core[PHASE]} in |
| 140 | + 1) phase1 |
| 141 | + core[CMD]=1 |
| 142 | + ;; |
| 143 | + 2) core[ENDPHASE]=true ;; |
| 144 | + esac |
| 145 | + ((core[PHASE]++)) |
| 146 | +done |
| 147 | + |
| 148 | +# Stop Logging |
| 149 | +endLog |
| 150 | +# Cleanup the log and any other files left |
| 151 | +cleanUp |
0 commit comments