-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaos-shell.sh
129 lines (113 loc) · 2.36 KB
/
chaos-shell.sh
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
: <<'COMMENT'
#!/bin/bash
TITLE=_TITLE_
NOTIFY_TIME=5000
EXIT_THRESHOLD=5
ARG_COUNT=_COUNT_
REQUIRED_USER=_USER_
FORCE_USER=_BOOLEAN_
source ${0%/*}/chaos-shell.sh
COMMENT
LABEL=BEGIN
####################
#NOTIFICATION & ECHO
#Ben Jarnagin
#Runs on call
####################
function notify {
echo -e "\033[38;5;3mNOTIFICATION:$TITLE::$1\033[0;00m"
notify-send -u normal -t $NOTIFY_TIME "NOTIFICATION:$TITLE" "$1"
}
####################
#ERROR & ECHO
#Ben Jarnagin
#Runs on call
####################
function error {
echo -e "\033[38;5;1mERROR:$TITLE::$1\033[0;00m"
notify-send -u critical -t $NOTIFY_TIME "ERROR:$TITLE" "$1"
if [ $2 -gt $EXIT_THRESHOLD ]
then
exit
fi
}
####################
#STATEMENT ECHO
#Ben Jarnagin
#Runs on call
####################
function statement {
echo -e "\033[38;5;10mSTATEMENT:$TITLE::$1\033[0;00m"
}
####################
#NEW SCREEN
#Ben Jarnagin
#Runs on call
####################
function newscreen {
clear
echo "################$TITLE################"
echo
}
####################
#PAUSE AND CHECK FOR ERRORS
#Ben Jarnagin
#Runs on call
####################
function pause {
echo
echo -e "\033[38;5;5m################PAUSE################\033[0;00m"
checkError 1
echo -e "\033[38;5;5m#######PRESS ENTER TO CONTINUE#######\033[0;00m"
read
}
####################
#CHECK FOR ERROR
#Ben Jarnagin
#Runs on call
####################
function checkError {
if [ $? -ne 0 ]
then
error "$LABEL" $1
fi
}
####################
#CONFIRM SCRIPT SIGNATURE
#Ben Jarnagin
#Runs on call
####################
function confirmScriptSignature {
LABEL=GPG_SCRIPT_SIG_VERIFY
FILE=${0%/*}/$(basename $0)
#gpg --verify $FILE.asc $FILE
gpg --verify ${0%/*}/$(basename $0).asc $FILE
checkError 100
statement "GPG_SCRIPT_SIG_VALID"
pause
}
####################
#TEST NUMBER OF ARGUMENTS
#Ben Jarnagin
#Runs Always
####################
if [ $# -ne $ARG_COUNT ]
then
error "Invalid Number of Arguments" 10
fi
####################
#CHECK USER
#Ben Jarnagin
#Runs Always
####################
if [ $USER != $REQUIRED_USER ]
then
error "Incorrect Running User" 5
if [ $FORCE_USER = TRUE ]
then
confirmScriptSignature
statement 'Forcing run "'${0%/*}'/'$(basename $0)' '$@'" as '$REQUIRED_USER
sudo -u $REQUIRED_USER ${0%/*}'/'$(basename $0) $@
exit
fi
fi