-
Notifications
You must be signed in to change notification settings - Fork 16
/
installer.sh
executable file
·319 lines (295 loc) · 10.3 KB
/
installer.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/bin/bash
# Checkra1n Installer for All Architectures
# GitHub Repository: https://github.com/Randomblock1/checkra1n-linux
# shellcheck disable=SC2034,SC1091,SC2089
SCRIPT_VERSION=3.1
# Set terminal colors
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
# Set whiptail dialog size
LINES=$(tput lines)
COLUMNS=$(tput cols)
LISTHEIGHT=6
# Prints a line with color using terminal codes
Print_Style() {
printf "%s\n" "${2}$1${NORMAL}"
}
# This is a bash script. Can also run in zsh.
if [[ "$BASH_VERSION" == '' && "$ZSH_VERSION" == '' ]]; then
whiptail --msgbox "ERROR: this script must be run in bash/zsh!" 20 30 --ok-button "Exit"
echo "ERROR: this script must be run in bash/zsh!"
exit
fi
# We need root.
if [ "$EUID" -ne 0 ]; then
whiptail --msgbox "YOU AREN'T RUNNING AS ROOT! This script needs root, use sudo!" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10)) --ok-button "Exit"
Print_Style "ERROR: You need to run this as root, use sudo!" "$RED"
exit
fi
# Check system architecture
CPUArch=$(uname -m)
Print_Style "System Architecture: $CPUArch" "$YELLOW"
# Get Linux distribution
# https://unix.stackexchange.com/a/6348
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
# This script and Checkra1n requires some things to work properly.
CheckDep() {
if dpkg -s "$1" &>/dev/null || which "$1" || sudo -u "$SUDO_USER" brew list "$1"; then
Print_Style "Dependency check: $1 installed." "$GREEN"
else
Print_Style "Dependency check: $1 NOT installed. Installing..." "$RED"
if [ "$OS" != "Darwin" ]; then
apt install -y "$1" -qq >/dev/null 2>/dev/null || (
Print_Style "WARNING: $1 failed to install." "$RED"
exit
)
else
sudo -u "$SUDO_USER" brew install "$1" -q >/dev/null 2>/dev/null || (
Print_Style "WARNING: $1 failed to install." "$RED"
exit
)
fi
Print_Style "$1 installed." "$GREEN"
fi
}
CheckDep curl
CheckDep grep
CheckDep usbmuxd
if [ "$OS" = "Darwin" ]; then
CheckDep newt
CheckDep libimobiledevice
else
CheckDep whiptail
CheckDep libimobiledevice6
CheckDep libimobiledevice-utils
fi
# We need Internet
if ! curl -sI http://google.com >/dev/null; then
Print_Style "No internet connection!" "$RED"
exit
fi
# Find latest checkra1n version (for autoupdate).
CHECKRA1NVERSION=$(curl https://checkra.in/ -s | grep "checkra1n .\..*\.." -oE | grep ".\..*\.." -oE)
# Automatically find latest checkra1n for correct architecture.
GetDL() {
FindDL() {
DL_LINK=$(curl -s https://checkra.in/releases/ | grep "https:\/\/assets.checkra.in\/downloads\/linux\/cli\/$1\/.*\/checkra1n" -o)
}
Print_Style "Getting latest download..." "$YELLOW"
if [[ "$CPUArch" == "aarch64*" || "$CPUArch" == "arm64" ]]; then
Print_Style "ARM64 detected!" "$YELLOW"
FindDL arm64
elif [[ "$CPUArch" == "armhf" || "$CPUArch" == "armv*" ]]; then
Print_Style "ARM detected!" "$YELLOW"
FindDL arm
elif [[ "$CPUArch" == "x86_64" ]]; then
Print_Style "x86_64 detected!" "$YELLOW"
FindDL x86_64
elif [[ "$CPUArch" == "x86" || "$CPUArch" == "i*86" ]]; then
Print_Style "x86 detected!" "$YELLOW"
FindDL i486
else
Print_Style "ERROR: Unknown/Unsupported architecture! Make sure your architecture is supported by checkra1n." "$RED"
Print_Style "Manually select architecture. Options are arm64, armv7, x86_64 and x86." "$RED"
read -rp "Architecture: "
CPUArch="$REPLY"
GetDL
fi
}
# Automatic script self-update logic
ScriptUpdate() {
ONLINE_VERSION="$(curl -s https://raw.githubusercontent.com/Randomblock1/checkra1n-linux/master/installer.sh | head -n 5 | tail -c 4)"
if (($(echo "$ONLINE_VERSION > $SCRIPT_VERSION" | bc -l))); then
Print_Style "Script needs to be updated! Updating..." "$GREEN"
sudo -u "$SUDO_USER" wget -q https://raw.githubusercontent.com/Randomblock1/checkra1n-linux/master/installer.sh -O installer.sh
chmod 755 installer.sh
Print_Style "Completed!" "$GREEN"
whiptail --title "Script Updated" --msgbox "This script has been automatically updated to version $ONLINE_VERSION!" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10))
./installer.sh
exit
else
Print_Style "Script is already up to date!" "$GREEN"
fi
}
# Is our checkra1n up to date?
Checkra1nChecker() {
if ! test "$HOME/.cache"; then
mkdir ~/.cache
fi
if test -f ~/.cache/checkra1n-version; then
INSTALLEDVERSION=$(cat ~/.cache/checkra1n-version)
if [ "$CHECKRA1NVERSION" != "$INSTALLEDVERSION" ]; then
if (whiptail --title "Checkra1n Update" --yesno "An update for checkra1n is available ($(cat ~/.cache/checkra1n-version) to $CHECKRA1NVERSION). Update?" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10))); then
DirectDL
fi
else
Print_Style "Checkra1n is up to date!" "$GREEN"
fi
else
# If checkra1n exists, assume we are up-to-date. Otherwise, let it autoupdate.
if test -f /usr/bin/checkra1n; then
echo "$CHECKRA1NVERSION" >~/.cache/checkra1n-version
else
echo 0.00.0 >~/.cache/checkra1n-version
fi
fi
}
# Installs Procursus bootstrap interactively.
Procursify() {
if (whiptail --title "Procursify" --yesno "Would you like to install the Procursus/odysseyra1n bootstrap?\n\
This will allow you to use libhooker, a replacement for Substrate, and the Procursus repo tools.\n\
Procursus tools are more up-to-date than other repos.\n\
Libhooker is slightly more stable and efficient than Substrate and Substitute." $((LINES * 3 / 4)) $((COLUMNS * 7 / 10))); then
if ! command -v iproxy &>/dev/null; then
Print_Style "iproxy could not be found, attempting to install" "$RED"
apt install -y libusbmuxd-tools
fi
sudo -u "$SUDO_USER" /bin/bash -c "./procursify.sh"
whiptail --title "Procursify" --msgbox "Success! Enjoy your libhooker." $((LINES * 3 / 4)) $((COLUMNS * 7 / 10))
fi
}
# Called when we want to directly download checkra1n.
DirectDL() {
GetOS
GetDL
Print_Style "Getting checkra1n..." "$GREEN"
curl "$DL_LINK" -o /usr/bin/checkra1n
chmod 755 /usr/bin/checkra1n
Print_Style "Done! Marked as executable!" "$GREEN"
echo "$CHECKRA1NVERSION" >~/.cache/checkra1n-version
Print_Style "All done!" "$BLINK"
}
# Check if we can use the repo; otherwise, exit.
InstallRepo() {
if [[ "$CPUArch" == *"x86_64"* ]]; then
Print_Style "x86_64 detected!" "$GREEN"
else
Print_Style "ERROR:You aren't on x86_64! You can't use this! Exiting..." "$RED"
exit
fi
echo "Adding repo..."
echo "deb https://assets.checkra.in/debian /" | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --fetch-keys https://assets.checkra.in/debian/archive.key
sudo apt update
echo "Installing..."
sudo apt install checkra1n
echo "All done!"
}
# Save blobs using 1Conan TSSSaver API
TssSaver() {
Print_Style "TSS Saver Activated!" "$PURPLE"
Print_Style "Getting info about your device..." "$PURPLE"
if ! ideviceinfo -s -k ProductVersion; then
Print_Style "No device detected!" "$RED"
Print_Style "Check that your device is plugged in!" "$RED"
exit
fi
device="$(ideviceinfo -s -k ProductType)"
board="$(ideviceinfo -s -k HardwareModel)"
ecid="$(ideviceinfo -s -k UniqueChipID)"
Print_Style "Device: $device" "$PURPLE"
Print_Style "Board: $board" "$PURPLE"
Print_Style "ECID (decimal): $ecid" "$PURPLE"
Print_Style "Requesting https://tsssaver.1conan.com to save our blobs..." "$WHITE"
request="{\"boardConfig\":\"$board\",\"ecid\":\"$ecid\",\"deviceIdentifier\":\"$device\"}"
sleep 1
curl -X POST -d "$request" https://tsssaver.1conan.com/v2/api/save.php || exit
Print_Style "Success! View your saved blobs at https://tsssaver.1conan.com/shsh/$ecid" "$GREEN"
Print_Style "If you want to save blobs for your device without this tool, just run this command:" "$GREEN"
Print_Style "curl -X POST -d $request https://tsssaver.1conan.com/v2/api/save.php" "$WHITE"
}
# Print credits.
GetCredits() {
if dpkg -s "net-tools" &>/dev/null; then
NET_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1)
else
NET_IP=N/A
fi
whiptail --title "Checkra1n GUI Installer" --msgbox "Checkra1n GUI Installer made by Randomblock1.\n\
This project is open source! Check out https://github.com/Randomblock1/Checkra1n-Linux! \n\
Follow me on Twitter @randomblock1_! \n\
Please report all bugs in the GitHub issue tracker and feel free to make pull requests! \n\
INFO: $OS $(uname -mo) \n\
VERSION: $SCRIPT_VERSION \n\
Local IP: $NET_IP" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10)) $((LISTHEIGHT))
MainMenu
}
# Main menu. Uses whiptail.
function MainMenu() {
CHOICE=$(whiptail \
--title "Checkra1n GUI Installer on $(uname -m)" \
--menu "Choose an option" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10)) $((LISTHEIGHT)) \
"Install Repo" "Install the repo. x86_64 ONLY!" \
"Direct Download" "Use on any architecture." \
"Procursify" "Install Procursus bootstrap." \
"Save Blobs" "Save SHSH blobs for up/downgrading." \
"Credits" "This tool is open-source!" \
"Update/Reinstall" "Update this tool." 3>&1 1>&2 2>&3)
case $CHOICE in
"Install Repo")
InstallRepo
;;
"Direct Download")
DirectDL
;;
"Procursify")
Procursify
;;
"Save Blobs")
TssSaver
;;
"Credits")
GetCredits
;;
"Update/Reinstall")
whiptail --title "Checkra1n GUI Installer" --yesno "Force update to latest version?" $((LINES * 3 / 4)) $((COLUMNS * 7 / 10))
case $? in
1)
MainMenu
;;
0)
SCRIPT_VERSION=0.0
ScriptUpdate
;;
esac
;;
esac
}
# Main function. Check script, then checkra1n, then enter the main menu.
ScriptUpdate
Checkra1nChecker
MainMenu