Skip to content

Commit 821207f

Browse files
committed
Version 1
1 parent 726645d commit 821207f

8 files changed

Lines changed: 597 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore all Logs
2+
logs/*
3+
4+
# Dont ignore log directory
5+
!logs/

args.liddle

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
3+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/scripts/working/Liddle
4+
5+
function processArgs {
6+
7+
argcounter=0
8+
9+
# Move into case for each argument if there is a least one argument
10+
if [ ! ${NEWARGS[0]} == "" ]; then
11+
12+
for arg in ${NEWARGS[@]}
13+
do
14+
15+
case $arg in
16+
17+
# help argument given, display help and exit
18+
"-h" | "help" | "--help")
19+
echo ""
20+
echo "---------------------------------------------------------------------"
21+
echo " LIDDLE SCRIPT "
22+
echo "---------------------------------------------------------------------"
23+
echo ""
24+
echo " Script Description goes here and gives an overview "
25+
echo " of what the script will do"
26+
echo ""
27+
echo " VALID ARGUMENTS "
28+
echo "---------------------------------------------------------------------"
29+
echo ""
30+
echo " -h | --help"
31+
echo " Open the scripts help"
32+
echo ""
33+
echo " -l | --load"
34+
echo " Resume script from prior point"
35+
echo ""
36+
echo " -c | --cleanup"
37+
echo " Clean log file and saved progress file"
38+
echo ""
39+
echo "---------------------------------------------------------------------"
40+
echo ""
41+
core[EXARG]="true"
42+
exit 1
43+
;;
44+
45+
# cleanup argument given, run cleanUp function and quit
46+
"--cleanup" | "--clean" | "-c") cleanUp
47+
core[EXARG]="true"
48+
exit 1 ;;
49+
# resume argument given, restart with logging and ldfile argument
50+
"--load" | "-l") core[EXARG]="true"
51+
loadFile
52+
;;
53+
# If another argument is given but is not a option
54+
*) args[$argcounter]=$arg
55+
core[ARGNUM]="${#args[@]}"
56+
((argcounter++))
57+
;;
58+
59+
esac
60+
61+
done
62+
63+
if [ -e "${core[DIR]}${core[PROGNAME]}.end" ]; then
64+
while :
65+
do
66+
echo ""
67+
echo "A saved progress file exists, would you like to continue from the saved progress?"
68+
read -p "This will ignore added arguments (y/n)" core[CONT]
69+
if [[ "${core[CONT]}" == "y" ]] || [[ "${core[CONT]}" == "Y" ]]; then
70+
loadFile
71+
elif [[ "${core[CONT]}" == "n" ]] || [[ "${core[CONT]}" == "N" ]]; then
72+
break
73+
else
74+
echo "Please input a valid answer (y/n)"
75+
continue
76+
fi
77+
break
78+
done
79+
fi
80+
81+
# Otherwise there are not arguments so check for a save file
82+
else
83+
84+
# If a save file exists
85+
if [ -e "${core[DIR]}${core[PROGNAME]}.end" ]; then
86+
while :
87+
do
88+
echo ""
89+
read -p "A saved progress file exists, would you like to continue from the saved progress? (y/n)" core[CONT]
90+
if [[ ${core[CONT]} == "y" ]] || [[ ${core[CONT]} == "Y" ]]; then
91+
loadFile
92+
elif [[ ${core[CONT]} == "n" ]] || [[ ${core[CONT]} == "N" ]]; then
93+
break
94+
else
95+
echo "Please input a valid answer (y/n)"
96+
continue
97+
fi
98+
break
99+
done
100+
fi
101+
102+
fi
103+
104+
}

core.liddle

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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

error.liddle

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/scripts/working/Liddle
4+
5+
function errorExit {
6+
7+
# --------------------------------------------------
8+
# Function for exit due to fatal error
9+
# Requires 3 Arguments, CMD Number, Line number and error
10+
# --------------------------------------------------
11+
12+
echo ""
13+
echo "---------------------------------------------------"
14+
echo " FATAL ERROR "
15+
echo "---------------------------------------------------"
16+
echo ""
17+
echo "Script File: ${core[PROGNAME]}"
18+
echo "Script Line: ${2}"
19+
echo "Error: ${3:-"Unknown Error"}" 1>&2
20+
21+
# If the save file already exists we need to replace it
22+
if [ -e "${core[DIR]}${core[PROGNAME]}.end" ]; then
23+
24+
echo ""
25+
rm -f "${core[DIR]}${core[PROGNAME]}.end" || echo "Error could not replace prior save"
26+
27+
fi
28+
29+
# Only save progress if the script has actually started
30+
if [ ${core[EXECUTION]} == "true" ]; then
31+
32+
# If the save file already exists we need to replace it
33+
if [ -e "${core[DIR]}${core[PROGNAME]}.end" ]; then
34+
35+
echo ""
36+
rm -f "${core[DIR]}${core[PROGNAME]}.end" || echo "Error could not replace prior save"
37+
38+
fi
39+
40+
save
41+
42+
# The script has not started yet so we don't need to save variables
43+
else
44+
45+
echo ""
46+
echo "Progress not saved"
47+
echo "Script progress variables not yet set"
48+
echo ""
49+
50+
fi
51+
52+
if [ ${core[LOGGING]} == "true" ]; then
53+
54+
echo "Ending Log ----------------------------------------"; endLog || echo "Failed to stop logging"
55+
echo "Exiting..."
56+
57+
else
58+
59+
echo "Logging not running..."
60+
echo "Exiting -------------------------------------------"
61+
62+
fi
63+
echo ""
64+
exit 1
65+
66+
}
67+

load.liddle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/scripts/working/Liddle
4+
5+
function loadFile {
6+
7+
# --------------------------------------------------
8+
# Function to load saved progress
9+
# Ignores any arguments given
10+
# --------------------------------------------------
11+
12+
# If the save file exists
13+
if [ -r "${core[DIR]}${core[PROGNAME]}.end" ]; then
14+
15+
# Tell core to load file
16+
loadfile="true"
17+
18+
# If the save file does not exist
19+
else
20+
# Throw an error message and exit without saving
21+
echo ""
22+
echo "---------------------------------------------------"
23+
echo " FATAL ERROR "
24+
echo "---------------------------------------------------"
25+
echo ""
26+
echo "Cannot find or cannot access saved progress file"
27+
echo "Exiting..."
28+
echo "---------------------------------------------------"
29+
echo ""
30+
exit 1
31+
fi
32+
33+
}
34+

0 commit comments

Comments
 (0)