-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·247 lines (217 loc) · 8.09 KB
/
build.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
#!/bin/sh
# Made by fullpwn.
# Some files were copied from odysseyn1x.
# Exit if user isn't root
[ "$(id -u)" -ne 0 ] && {
echo 'Please run as root'
exit 1
}
# Change these variables to modify the version of checkra1n
# checkra1n 0.10.1
CHECKRA1N_OLD_AMD64='https://assets.checkra.in/downloads/linux/cli/x86_64/b0edbb87a5e084caf35795dcb3b088146ad5457235940f83e007f59ca57b319c/checkra1n-x86_64'
CHECKRA1N_OLD_I686='https://assets.checkra.in/downloads/linux/cli/i486/9b7a5c7821c8e06a334b854c5ffad7b28c56a5ac261afe3c6b647c9ba7185aee/checkra1n-i486'
# If the latest version of checkra1n (at build time) is desired, leave the variables empty
CHECKRA1N_AMD64='https://assets.checkra.in/downloads/linux/cli/x86_64/dac9968939ea6e6bfbdedeb41d7e2579c4711dc2c5083f91dced66ca397dc51d/checkra1n'
CHECKRA1N_I686='https://assets.checkra.in/downloads/linux/cli/i486/77779d897bf06021824de50f08497a76878c6d9e35db7a9c82545506ceae217e/checkra1n'
if [ -z "$CHECKRA1N_AMD64" ]; then
CHECKRA1N_AMD64=$(curl "https://checkra.in/releases/" | grep -Po "https://assets.checkra.in/downloads/linux/cli/x86_64/[0-9a-f]*/checkra1n")
fi
if [ -z "$CHECKRA1N_I686" ]; then
CHECKRA1N_I686=$(curl "https://checkra.in/releases/" | grep -Po "https://assets.checkra.in/downloads/linux/cli/i486/[0-9a-f]*/checkra1n")
fi
GREEN="$(tput setaf 2)"
BLUE="$(tput setaf 6)"
NORMAL="$(tput sgr0)"
cat << EOF
${GREEN}############################################${NORMAL}
${GREEN}# #${NORMAL}
${GREEN}# ${BLUE}Welcome to the infinity build script ${GREEN}#${NORMAL}
${GREEN}# #${NORMAL}
${GREEN}############################################${NORMAL}
EOF
echo "VERSION: $VERSION"
echo "ARCH: $ARCH"
# Ask for the version and architecture if variables are empty
while [ -z "$VERSION" ]; do
printf 'Version: '
read -r VERSION
done
until [ "$ARCH" = 'amd64' ] || [ "$ARCH" = 'i686' ]; do
echo '1 amd64'
echo '2 i686'
printf 'Which architecture? amd64 (default) or i686 '
read -r input_arch
[ "$input_arch" = 1 ] && ARCH='amd64'
[ "$input_arch" = 2 ] && ARCH='i686'
[ -z "$input_arch" ] && ARCH='amd64'
done
# Delete old build
{
umount work/chroot/proc
umount work/chroot/sys
umount work/chroot/dev
} > /dev/null 2>&1
rm -rf work/
set -e -u -v -x
start_time="$(date -u +%s)"
# Install dependencies to build odysseyn1x
apt-get update
apt-get install -y --no-install-recommends wget debootstrap grub-pc-bin \
mtools squashfs-tools xorriso ca-certificates curl \
libusb-1.0-0-dev gcc make gzip xz-utils unzip libc6-dev
if [ "$ARCH" = 'amd64' ]; then
REPO_ARCH='amd64' # Debian's 64-bit repos are "amd64"
KERNEL_ARCH='amd64' # Debian's 32-bit kernels are suffixed "amd64"
apt install -y --no-install-recommends grub-efi-amd64-bin
else
# remove grub-efi-amd64-bin. grub-mkrescue doesn't have any architecture configuration other than the set of installed packages.
apt-get remove -y --allow-remove-essential grub-efi-amd64-bin grub-efi-amd64-signed
# Install depencies to build odysseyn1x for i686
dpkg --add-architecture i386
apt-get update
apt install -y --no-install-recommends libusb-1.0-0-dev:i386 gcc-multilib
REPO_ARCH='i386' # Debian's 32-bit repos are "i386"
KERNEL_ARCH='686' # Debian's 32-bit kernels are suffixed "-686"
fi
# Configure the base system
mkdir -p work/chroot work/iso/live work/iso/boot/grub
debootstrap --variant=minbase --arch="$REPO_ARCH" stable work/chroot 'http://deb.debian.org/debian/'
mount --bind /proc work/chroot/proc
mount --bind /sys work/chroot/sys
mount --bind /dev work/chroot/dev
cp /etc/resolv.conf work/chroot/etc
cat << EOF | chroot work/chroot /bin/bash
# Set debian frontend to noninteractive
export DEBIAN_FRONTEND=noninteractive
# Install requiered packages
apt-get install -y --no-install-recommends linux-image-$KERNEL_ARCH live-boot \
systemd systemd-sysv usbmuxd libusbmuxd-tools openssh-client sshpass xz-utils whiptail
# Remove apt as it won't be usable anymore
apt purge apt -y --allow-remove-essential
EOF
# Change initramfs compression to xz
sed -i 's/COMPRESS=gzip/COMPRESS=xz/' work/chroot/etc/initramfs-tools/initramfs.conf
chroot work/chroot update-initramfs -u
(
cd work/chroot
# Empty some directories to make the system smaller
rm -f etc/mtab \
etc/fstab \
etc/ssh/ssh_host* \
root/.wget-hsts \
root/.bash_history
rm -rf var/log/* \
var/cache/* \
var/backups/* \
var/lib/apt/* \
var/lib/dpkg/* \
usr/share/doc/* \
usr/share/man/* \
usr/share/info/* \
usr/share/icons/* \
usr/share/locale/* \
usr/share/zoneinfo/* \
usr/lib/modules/*
)
# Copy scripts
cp scripts/* work/chroot/usr/bin/
(
# download checkra1n 0.10.1
cd work/chroot/usr/bin/
if [ "$ARCH" = 'amd64' ]; then
curl -L -O "$CHECKRA1N_OLD_AMD64"
mv checkra1n-x86_64 checkra1n_old
else
curl -L -O "$CHECKRA1N_OLD_I686"
mv checkra1n-i486 checkra1n_old
fi
chmod +x checkra1n_old
)
(
cd work/chroot/root/
# Download resources for Android Sandcastle
curl -L -O 'https://assets.checkra.in/downloads/sandcastle/dff60656db1bdc6a250d3766813aa55c5e18510694bc64feaabff88876162f3f/android-sandcastle.zip'
unzip android-sandcastle.zip
rm -f android-sandcastle.zip
(
cd android-sandcastle/
rm -f iproxy ./*.dylib load-linux.mac ./*.sh README.txt isetup
)
# Download resources for Linux Sandcastle
curl -L -O 'https://assets.checkra.in/downloads/sandcastle/0175ae56bcba314268d786d1239535bca245a7b126d62a767e12de48fd20f470/linux-sandcastle.zip'
unzip linux-sandcastle.zip
rm -f linux-sandcastle.zip
(
cd linux-sandcastle/
rm -f load-linux.mac README.txt
)
)
(
# Copy and set up iPhone scripts
cp assets/isetup work/chroot/root/android-sandcastle/
cp assets/iremove work/chroot/root/android-sandcastle/
chmod a+x work/chroot/root/android-sandcastle/isetup
chmod a+x work/chroot/root/android-sandcastle/iremove
)
(
cd work/chroot/usr/bin/
curl -L -O 'https://raw.githubusercontent.com/corellium/projectsandcastle/master/loader/load-linux.c'
# Build load-linux.c and download checkra1n for the corresponding architecture
if [ "$ARCH" = 'amd64' ]; then
gcc load-linux.c -o load-linux -lusb-1.0
curl -L -o checkra1n "$CHECKRA1N_AMD64"
else
gcc -m32 load-linux.c -o load-linux -lusb-1.0
curl -L -o checkra1n "$CHECKRA1N_I686"
fi
rm -f load-linux.c
chmod +x load-linux checkra1n
)
# Configure autologin
mkdir -p work/chroot/etc/systemd/system/getty@tty1.service.d
cat << EOF > work/chroot/etc/systemd/system/getty@tty1.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin root %I
Type=idle
EOF
# Configure grub
cat << "EOF" > work/iso/boot/grub/grub.cfg
insmod all_video
echo ''
echo ' _ ___ _ _ _ '
echo ' |_|___| _|_|___|_| |_ _ _'
echo ' | | | _| | | | _| | |'
echo ' |_|_|_|_| |_|_|_|_|_| |_ |'
echo ' |___|'
echo ''
echo ' By fullpwn.'
echo ' V 1.1'
linux /boot/vmlinuz boot=live quiet
initrd /boot/initrd.img
boot
EOF
# Change hostname and configure .bashrc
echo 'infinity' > work/chroot/etc/hostname
echo "export INFINITY_VERSION='$VERSION'" > work/chroot/root/.bashrc
echo '/usr/bin/infinity_menu' >> work/chroot/root/.bashrc
rm -f work/chroot/etc/resolv.conf
# Build the ISO
umount work/chroot/proc
umount work/chroot/sys
umount work/chroot/dev
cp work/chroot/vmlinuz work/iso/boot
cp work/chroot/initrd.img work/iso/boot
mksquashfs work/chroot work/iso/live/filesystem.squashfs -noappend -e boot -comp xz -Xbcj x86 -Xdict-size 100%
## Creates output ISO dir (easier for GitHub Actions)
mkdir -p out
grub-mkrescue -o "out/infinity-$VERSION-$ARCH.iso" work/iso \
--compress=xz \
--fonts='' \
--locales='' \
--themes=''
end_time="$(date -u +%s)"
elapsed_time="$((end_time - start_time))"
# Stop echoing commands
set +x
echo "Built infinity-$VERSION-$ARCH in $((elapsed_time / 60)) minutes and $((elapsed_time % 60)) seconds."