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