-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions_test.sh
executable file
·295 lines (273 loc) · 10.1 KB
/
functions_test.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# Variscite Functions_Test - by ThatStella7922
# Shoutout to crystall1nedev, my beloved
ver="2023.315.1"
##################################################################################################
##################################################################################################
#### ####
#### This is a testing file. Commands will be added and removed at random from this file. ####
#### ####
##################################################################################################
##################################################################################################
# colors
usecolors="true"
reset="\033[0m";faint="\033[37m";red="\033[38;5;196m";black="\033[38;5;244m";green="\033[38;5;46m";yellow="\033[38;5;226m";magenta="\033[35m";blue="\033[36m";default="\033[39m"
# formatting
bold="\033[1m";resetbold="\033[21m"
# message styling
init="${black}${faint}[${reset}${magenta}*${reset}${black}${faint}]${reset}"
info="${black}${faint}[${reset}${green}Info${reset}${black}${faint}]${reset}"
question="${black}${faint}[${reset}${yellow}?${reset}${black}${faint}]${reset}"
help="${black}${faint}[${reset}${green}?${reset}${black}${faint}]${reset}"
error="${black}${faint}[${reset}${red}${bold}Error${reset}${resetbold}${black}${faint}]${reset}"
warn="${black}${faint}[${reset}${yellow}!${reset}${black}${faint}]${reset}"
azule="${black}${faint}[${reset}${blue}Azule${reset}${black}${faint}]${reset}"
success="${black}${faint}[${reset}${green}√${reset}${black}${faint}]${reset}"
if [[ usecolors == "false" ]]; then
reset="";faint="";red="";black="";green="";yellow="";magenta="";blue="";default=""
fi
# init message
echo -e "$init Variscite Functions_Test $ver"
echo -e "$init https://github.com/ThatStella7922/Variscite"
echo
### Functions
## Checks for Azule and doesn't prompt for installation. Returns 1 if Azule not found, else returns 0.
# Call with true to make it print an error.
nonInteractiveAzuleCheck () {
if [[ ! -f "$(which azule)" ]]; then
if [[ $1 == "true" ]]; then
echo -e "$error Variscite couldn't locate Azule. If it's already installed, make sure that it's in the PATH."
echo -e "$error Cannot continue without Azule."
echo -e "$info Variscite can install Azule for you - Run Variscite with -h to learn more."
echo -e "$info Alternatively, you can manually install it at https://github.com/Al4ise/Azule/wiki."
return 1
else
return 1
fi
else
return 0
fi
}
## Checks for the Xcode command line tools and doesn't prompt for installation. Returns 1 if Xcode not found, else returns 0.
# Call with true to make it print an error.
nonInteractiveXcodeCltCheck () {
if ! xcode-select -p 1>/dev/null; then
if [[ $1 == "true" ]]; then
echo -e "$error Variscite couldn't locate the Xcode Command Line Tools."
echo -e "$info You can install them manually by running xcode-select --install"
return 1
else
return 1
fi
else
# good to go
return 0
fi
}
# Checks if we are running on Darwin (macOS/iOS). Returns 0 if we are, else returns 1.
checkAreWeOnDarwin () {
if [[ "$OSTYPE" == "darwin"* ]]; then
return 0
else
return 1
fi
}
# Checks if we are running on some type of Linux. Returns 0 if we are, else returns 1.
checkAreWeOnLinux () {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
return 0
else
return 1
fi
}
## Checks if we are running on jailbroken iOS. Returns 0 if we are, else returns 1.
# Checks using the presence of apt, so this might trigger on Procursus-strapped macOS. not my problem tho :trolley:
checkAreWeOnJbIos () {
checkAreWeOnDarwin
if test "$?" == "0"; then
# we are on darwin, actually check if we are on ios now
if [[ "$(sw_vers -productName)" == "iOS" ]]; then
return 0
else
# we are not on ios so stop here
return 1
fi
else
# we are not even on darwin so stop here
return 1
fi
}
# downloadAzule"
downloadAzule () {
nonInteractiveCurlCheck true
if [[ $? == "0" ]]; then
curl -LJ#o azule.zip https://github.com/Al4ise/Azule/archive/refs/heads/main.zip
res=$?
if test "$res" != "0"; then
echo -e "$error curl failed with: $res"
exit $res
fi
else
exit 1
fi
}
installAzule () {
echo -e "$info Downloading Azule..."
rm -rf temp 2> /dev/null;mkdir temp;cd temp
downloadAzule
echo -e "$info Unpacking Azule..."
unzip -q azule.zip;rm azule.zip
echo -e "$info Installing Azule (this may require your password)..."
if [[ ! -d ~/Applications ]]; then
mkdir ~/Applications
fi #check if applications folder exists at ~ so we can put Azule there
if [[ -d ~/Applications/Azule-main ]]; then
rm -rf ~/Applications/Azule-main
fi #check if azule is there and if so delete it
mv Azule-main/ ~/Applications/
rm -rf temp
if [[ ! -d /usr/local/bin ]]; then
sudo mkdir /usr/local/bin
fi #check if /usr/local/bin exists and if not, make the folder
sudo ln -sf ~/Applications/Azule-main/azule /usr/local/bin/azule
if [[ $? == "0" ]]; then
echo -e "$info Azule installed succesfully. (symlinked to /usr/local/bin/azule)"
else
echo -e "$error Installation failed with code $?"
exit $?
fi
}
uninstallAzule () {
echo -e "$info Uninstalling Azule (this may require your password)..."
if [[ -d ~/Applications/Azule-main ]]; then
rm -rf ~/Applications/Azule-main
fi #check if azule is there and if so delete it
if [[ $? == "0" ]]; then
echo -e "$info Deleted ~/Applications/Azule-main"
else
echo -e "$error Failed to remove ~/Applications/Azule-main, error code $?"
exit $?
fi
sudo rm -rf /usr/local/bin/azule
if [[ $? == "0" ]]; then
echo -e "$info Azule uninstalled succesfully."
else
echo -e "$error Uninstallation failed with code $?"
exit $?
fi
}
# Checks that the IPA is valid, returns 0 if OK and 1 if invalid.
# Call: validateIpa PathToIpa DoIPromptForNewIpa[true/false]
validateIpa () {
if [[ "$1" != *".ipa" ]]; then
if [[ $2 == "true" ]]; then
echo -e "$error The specified file doesn't appear to be a valid IPA file"
read -p "$(echo -e "$question Specify the path of a valid IPA file: ")" ipafile
validateIpa $ipafile true
if [[ $? == "0" ]]; then
return 0
else
return 1
fi
fi
return 1
else
return 0
fi
}
# Checks that the dylib is valid, returns 0 if OK and 1 if invalid.
# Call: validateDylib PathToDylib DoIPromptForNewDylib[true/false]
validateDylib () {
if [[ "$1" != *".dylib" ]]; then
if [[ $2 == "true" ]]; then
echo -e "$error The specified file doesn't appear to be a valid dylib"
read -p "$(echo -e "$question Specify the path of a valid dylib: ")" dylib
validateDylib $dylib true
if [[ $? == "0" ]]; then
return 0
else
return 1
fi
fi
return 1
else
return 0
fi
}
# Checks that the folder exists, returns 0 if OK and 1 if it doesn't exist.
# Call: validatePath PathToCheck MakeFolderIfNotExist[true/false]
validatePath () {
if [[ ! -d $1 ]]; then
if [[ $2 == "true" ]]; then
mkdir $1
if [[ $? == "0" ]]; then
return 0
else
echo -e "$error Folder creation at $1 failed."
return 1
fi
else
return 1
fi
else
return 0
fi
}
# Specify arguments when calling. patchIpa PathToIpa PathToDylib OutputPath
patchIpa () {
azule -U -i $1 -o $3 -f $2 -r -v | sed -u -r "s/(\[\*\])/$(echo -e $azule)/g"
}
showHelp () {
echo -e "##################################################################################################"
echo -e "##################################################################################################"
echo -e "#### ####"
echo -e "#### This is a testing file. Commands will be added and removed at random from this file. ####"
echo -e "#### Use argument syntax from Variscite. ####"
echo -e "#### ####"
echo -e "##################################################################################################"
echo -e "##################################################################################################"
}
### End of functions
### Start code
# Check for help argument
if [[ $1 == "-h"* ]] || [[ $1 == "--h"* ]]; then
showHelp
exit 0
fi
# Check for install Azule argument.
if [[ $1 == "-iA"* ]] || [[ $1 == "--iA"* ]]; then
nonInteractiveAzuleCheck
if [[ ! $? == "0" ]]; then
installAzule
exit $?
else
echo -e "$info Azule is already installed!"
exit $?
fi
fi
# Check for uninstall Azule argument.
if [[ $1 == "-uA"* ]] || [[ $1 == "--uA"* ]]; then
nonInteractiveAzuleCheck
if [[ $? == "0" ]]; then
uninstallAzule
exit $?
else
echo -e "$error Couldn't find Azule, it has likely already been uninstalled!"
exit $?
fi
fi
while getopts ':s:i:d:o:' OPTION
do
case "${OPTION}" in
s) silent=${OPTARG};;
i) ipafile=${OPTARG};;
d) dylib=${OPTARG};;
o) outpath=${OPTARG};;
\?) echo -e "$error Invalid option: -${OPTARG}" >&2; exit 1;;
:) echo -e "$error option -${OPTARG} requires an argument" >&2; exit 1;;
esac
done
# Start Test
echo -e "$init Beginning validation functions test"
checkAreWeOnJbIos
echo -e "exited with code $?"