-
Notifications
You must be signed in to change notification settings - Fork 3
/
shared.sh
134 lines (111 loc) · 3.35 KB
/
shared.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
130
131
132
133
134
#!/bin/sh
#------------------------#
# Logging
#------------------------#
writeLog() {
if [[ "$debugFlag" == "true" ]]; then
/bin/echo $(date)" - "$1 >> $USER_LOG_FILE
fi
}
writeEcho() {
/bin/echo $(date)" - "$1
}
#------------------------#
# Validating number
#------------------------#
isNumber() {
case $PROCESS in
'' | *[!0-9]*) false ;;
*) true ;;
esac
}
#------------------------#
# Check if file exits
#------------------------#
isFile() {
[ -f "$FILE" ]
}
#------------------------#
# Check if folder exits
#------------------------#
isFolder() {
[ -d "$FOLDER" ]
}
#------------------------#
# Greeting message
#------------------------#
greeting() {
hour=`date +%H`
if [ $hour -lt 12 ]; then
greet="Good morning"
elif [ $hour -lt 18 ]; then
greet="Good afternoon"
else
greet="Good evening"
fi
}
#------------------------#
# Print GetOps Menu uasage message
#------------------------#
printGetOptsMenuUsage() {
echo "Stop Sauron - To stop the all seeing eye of Sauron and make your MacBook operate as it should be."
echo " "
echo "Stop Sauron [options] application [arguments]"
echo " "
echo "options:"
# echo "-h, --help show brief help"
echo "-x, --debugFlag=true enable debug logging"
# echo "-o, --output-dir=DIR specify a directory to store output in"
}
#------------------------#
# Check if folder exits
#------------------------#
deleteLogfiles() {
# logfile
if [ -f $USER_LOG_FILE ]; then
rm $USER_LOG_FILE
fi
}
#------------------------#
# Create backup
#------------------------#
createBackupfiles() {
writeLog "[Backup] - Start --> Creating backup configuration files"
if [ -f $PLIST_DEAMON_CONF ]; then
writeLog "[Backup] - found --> $PLIST_DEAMON_CONF"
if [ -f $PLIST_DEAMON_BACKUP ]; then
writeLog "[Backup] - found --> $PLIST_DEAMON_BACKUP --> skipping backup"
writeEcho "[Backup] - found --> $PLIST_DEAMON_BACKUP --> skipping backup. Please remove this previous backup file manually"
else
cp $PLIST_DEAMON_CONF $PLIST_DEAMON_BACKUP
writeLog "[Backup] - created --> $PLIST_DEAMON_BACKUP"
fi
fi
if [ -f $PLIST_AGENT_CONF ]; then
writeLog "[Backup] - found --> $PLIST_AGENT_CONF"
if [ -f $PLIST_AGENT_BACKUP ]; then
writeLog "[Backup] - found --> $PLIST_AGENT_BACKUP --> skipping backup"
writeEcho "[Backup] - found --> $PLIST_AGENT_BACKUP --> skipping backup. Please remove this previous backup file manually"
else
cp $PLIST_AGENT_CONF $PLIST_AGENT_BACKUP
writeLog "[Backup] - created --> $PLIST_AGENT_BACKUP"
fi
fi
writeLog "[Backup] - Resolved --> Creating backup configuration files"
}
#------------------------#
# Remove configuration
#------------------------#
removeConfigfiles() {
# Config
if [ -f $PLIST_DEAMON_CONF ]; then
writeLog "[Reset Conf] - Found --> $PLIST_DEAMON_CONF"
rm $PLIST_DEAMON_CONF
writeLog "[Reset Conf] - Removed --> $PLIST_DEAMON_CONF"
fi
if [ -f $PLIST_AGENT_CONF ]; then
writeLog "[Reset Conf] - Found --> $PLIST_AGENT_CONF"
rm $PLIST_AGENT_CONF
writeLog "[Reset Conf] - Removed --> $PLIST_AGENT_CONF"
fi
}