-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathworli.sh
More file actions
executable file
·515 lines (442 loc) · 17.4 KB
/
Copy pathworli.sh
File metadata and controls
executable file
·515 lines (442 loc) · 17.4 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#!/bin/bash
PREFIX="\e[1;36m[WoRli]\e[0m"
if [ "$EUID" -ne 0 ]
then echo -e "${PREFIX} This script needs to be run as root. If you're a noob, that's 'sudo ./worli.sh' or 'sudo bash worli.sh'"
exit 1
fi
if [[ $OSTYPE == 'darwin'* ]]; then
echo -e "${PREFIX} macOS detected, running in experimental macOS mode."
echo " "
echo -e "${PREFIX} Prerequisites"
echo -e "${PREFIX} Due to how brew works you need to run these commands in a non root shell:"
echo -e "${PREFIX} - 'brew install wimlib gdisk dosfstools gnu-sed'"
echo -e "${PREFIX} - 'brew install --cask macfuse'"
echo -e "${PREFIX} - 'brew tap gmerlino/exfat'"
echo -e "${PREFIX} - 'brew install --HEAD exfat'"
echo -e "${PREFIX} - You may need to disable SIP as stated here: https://www.rodsbooks.com/gdisk/"
echo " "
read -p "Press enter to continue..."
export MACOS=1
export PATH=$PATH:/usr/local/sbin
else
export MACOS=0
fi
echo -e "${PREFIX} WoRli, made by JoJo Autoboy#1931"
echo -e "${PREFIX} Heavily based off of Mario's WoR Linux guide: https://worproject.com/guides/how-to-install/from-other-os"
mkdir -p /tmp/isomount
chmod 777 /tmp/isomount
echo " "
echo -e "${PREFIX} Are you installing onto a Raspberry Pi 4, 3, CM3, or 2?"
read -r -p "[4/3/CM3/2]: " input
case $input in
[4])
export PI="4"
;;
[3]|[cC][mM][3]|[2])
export PI="3"
;;
*)
echo -e "${PREFIX} Invalid input"
exit 1
;;
esac
echo " "
echo -e "${PREFIX} Do you want the tool to download the UEFI, drivers, and PE-installer automatically? Say 'N' to use your own files"
export default="Y"
read -r -p "[n/Y] default: Y: " input
: ${input:=$default}
echo " "
case $input in
[yY][eE][sS]|[yY])
if ! command -v wget &> /dev/null
then
echo -e "${PREFIX} - 'wget' package not installed. Install it (For Debian and Ubuntu, run 'sudo apt install wget'; for Arch, run 'sudo pacman -S wget'; for macOS, run 'brew install wget')"
exit 1
fi
if [[ $MACOS == *"1"* ]]; then
efiURL="$(wget -qO- https://api.github.com/repos/pftf/RPi${PI}/releases/latest | grep '"browser_download_url":'".*RPi${PI}_UEFI_Firmware_.*\.zip" | gsed 's/^.*browser_download_url": "//g' | gsed 's/"$//g')"
wget -O "/tmp/UEFI_Firmware.zip" "$efiURL" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download UEFI_Firmware.zip"; exit 1; }
drivURL="$(wget -qO- https://api.github.com/repos/worproject/RPi-Windows-Drivers/releases/latest | grep '"browser_download_url":'".*RPi${PI}_Windows_ARM64_Drivers_.*\.zip" | gsed 's/^.*browser_download_url": "//g' | gsed 's/"$//g')"
wget -O "/tmp/Windows_ARM64_Drivers.zip" "$drivURL" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download Windows_ARM64_Drivers.zip"; exit 1; }
wget -O "/tmp/WoR-PE_Package.zip" "https://worproject.com/dldserv/worpe/downloadlatest.php" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download WoR-PE_Package.zip"; exit 1; }
else
efiURL="$(wget -qO- https://api.github.com/repos/pftf/RPi${PI}/releases/latest | grep '"browser_download_url":'".*RPi${PI}_UEFI_Firmware_.*\.zip" | sed 's/^.*browser_download_url": "//g' | sed 's/"$//g')"
wget -O "/tmp/UEFI_Firmware.zip" "$efiURL" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download UEFI_Firmware.zip"; exit 1; }
drivURL="$(wget -qO- https://api.github.com/repos/worproject/RPi-Windows-Drivers/releases/latest | grep '"browser_download_url":'".*RPi${PI}_Windows_ARM64_Drivers_.*\.zip" | sed 's/^.*browser_download_url": "//g' | sed 's/"$//g')"
wget -O "/tmp/Windows_ARM64_Drivers.zip" "$drivURL" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download Windows_ARM64_Drivers.zip"; exit 1; }
wget -O "/tmp/WoR-PE_Package.zip" "https://worproject.com/dldserv/worpe/downloadlatest.php" || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to download WoR-PE_Package.zip"; exit 1; }
fi
export efi="/tmp/UEFI_Firmware.zip"
export driv="/tmp/Windows_ARM64_Drivers.zip"
export inst="/tmp/WoR-PE_Package.zip"
export auto="1"
;;
[nN][oO]|[nN])
echo " "
echo -e "${PREFIX} - Download the UEFI package (not the source code):"
echo -e "${PREFIX} - for Pi 4 and newer: https://github.com/pftf/RPi4/releases"
echo -e "${PREFIX} - for Pi 2, 3, CM3: https://github.com/pftf/RPi3/releases"
echo -e "${PREFIX} - Then, rename the ZIP file to 'UEFI_Firmware.zip'"
echo " "
echo -e "${PREFIX} What's the path to 'UEFI_Firmware.zip'?"
read -r -p "[/*] E.g. '~/UEFI_Firmware.zip': " efi
echo " "
echo -e "${PREFIX} - Go to https://worproject.com/downloads#windows-on-raspberry-pe-based-installer and download the 'Windows on Raspberry PE-based installer', then rename the ZIP file to 'WoR-PE_Package.zip'"
echo " "
echo -e "${PREFIX} What's the path to 'WoR-PE_Package.zip'?"
read -r -p "[/*] E.g. '~/WoR-PE_Package.zip': " inst
echo " "
echo -e "${PREFIX} - Download the driver package from: https://github.com/worproject/RPi-Windows-Drivers/releases (get the ZIP archive with the RPi prefix followed by your board version) and rename the ZIP file to Windows_ARM64_Drivers.zip"
echo " "
echo -e "${PREFIX} What's the path to 'Windows_ARM64_Drivers.zip'?"
read -r -p "[/*] E.g. '~/Windows_ARM64_Drivers.zip': " driv
;;
*)
echo -e "${PREFIX} Invalid input"
exit 1
;;
esac
echo " "
if [ -f $efi ]; then
echo -e "${PREFIX} 'UEFI_Firmware.zip' found"
else
echo -e "${PREFIX} 'UEFI_Firmware.zip' does not exist. Abort."
exit 1
fi
if [ -f $driv ]; then
echo -e "${PREFIX} 'Windows_ARM64_Drivers.zip' found"
else
echo -e "${PREFIX} 'Windows_ARM64_Drivers.zip' does not exist. Abort."
exit 1
fi
if [ -f $inst ]; then
echo -e "${PREFIX} 'WoR-PE_Package.zip' found"
else
echo -e "${PREFIX} 'WoR-PE_Package.zip' does not exist. Abort."
exit 1
fi
echo " "
echo -e "${PREFIX} Prerequisites"
echo " "
echo -e "${PREFIX} - Get the windows ISO: https://worproject.com/guides/getting-windows-images"
echo -e "${PREFIX} - Rename the ISO file to 'win.iso'"
echo " "
echo -e "${PREFIX} - If you want use use a modified install.wim, rename it to 'install.wim'. NOTE: You will still need the ISO where the WIM came from"
echo " "
echo -e "${PREFIX} - If you're using a Raspberry Pi 4, you must update the Bootloader to the latest version: https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#updating-the-bootloader"
echo " "
if ! command -v wimupdate &> /dev/null
then
echo -e "${PREFIX} - 'wimtools' package not installed. Install it (For Debian and Ubuntu, run 'sudo apt install wimtools'; for Arch, run 'sudo pacman -S wimlib')"
exit 1
fi
if [[ $MACOS == *"1"* ]]; then
if ! command -v gdisk &> /dev/null
then
echo -e "${PREFIX} - 'gdisk' package not installed. Install it ('brew install gdisk')"
exit 1
fi
else
if ! command -v parted &> /dev/null
then
echo -e "${PREFIX} - 'parted' package not installed. Install it (For Debian and Ubuntu, run 'sudo apt install parted'; for Arch, run 'sudo pacman -S parted')"
exit 1
fi
fi
if ! command -v mkfs.exfat &> /dev/null
then
echo -e "${PREFIX} - 'mkfs.exfat' command not found. Install it (For Debaian and Ubuntu, run 'sudo apt install exfatprogs'; For Arch, run 'sudo pacman -S exfatprogs')"
exit 1
fi
echo -e "${PREFIX} \e[0;31mDO THE PREREQUISITES STUFF BEFORE CONTINUING\e[0m"
read -p "Press enter to continue..."
echo " "
echo -e "${PREFIX} What's the path to the 'win.iso'?"
read -r -p "[/*] E.g. '~/win.iso': " iso
echo " "
echo -e "${PREFIX} Do you want to use a custom WIM?"
export default="N"
read -r -p "[N/y] default: N: " input
: ${input:=$default}
echo " "
case $input in
[yY][eE][sS]|[yY])
echo -e "${PREFIX} what's the path to the 'install.wim'?"
read -r -p "[/*] E.g. '~/install.wim': " wim
export custwim="1"
echo " "
if [ -f $wim ]; then
echo -e "${PREFIX} 'install.wim' found"
else
echo -e "${PREFIX} 'install.wim' does not exist. Abort."
exit 1
fi
;;
[nN][oO]|[nN])
echo " "
echo -e "${PREFIX} No custom WIM then"
export custwim="0"
;;
*)
echo -e "${PREFIX} Invalid input"
exit 1
;;
esac
echo " "
if [ -f $iso ]; then
echo -e "${PREFIX} 'win.iso' found"
else
echo -e "${PREFIX} 'win.iso' does not exist. Abort."
exit 1
fi
echo " "
echo -e "${PREFIX} What /dev/* is your drive? NOTE: ALL your data on the selected disk will be ERASED, proceed with caution!"
echo -e "${PREFIX} ---------------------------------------------------------------------------------------------------------"
echo " "
if [[ $MACOS == *"1"* ]]; then
diskutil list
else
parted -l
fi
echo " "
read -r -p "[/dev/*] E.g. 'sdb', 'mmcblk0', 'disk7': " disk
echo -e "${PREFIX} You have selected '$disk', is this correct?"
export default="Y"
read -r -p "[n/Y] default: Y: " input
: ${input:=$default}
case $input in
[yY][eE][sS]|[yY])
echo -e "${PREFIX} ok '$disk' it is then"
;;
[nN][oO]|[nN])
echo -e "${PREFIX} Abort."
exit 1
;;
*)
echo -e "${PREFIX} Invalid input"
exit 1
;;
esac
if [[ $disk == *"mmcblk"* ]]; then
export nisk="${disk}p"
else
export nisk="$disk"
fi
if [[ $disk == *"disk"* ]]; then
export nisk="${disk}s"
else
export nisk="$disk"
fi
if [[ $disk == *"/dev"* ]]; then
echo -e "${PREFIX} DO NOT PUT '/dev', only put the name like 'sdb'"
exit 1
else
echo -e "${PREFIX} Disk name format correct"
fi
if [ -b "/dev/$disk" ]; then
echo -e "${PREFIX} '$disk' found"
else
echo -e "${PREFIX} '$disk' does not exist. Abort."
exit 1
fi
echo -e "${PREFIX} \e[0;31mWARNING: THE DISK '$disk' WILL BE WIPED!\e[0m Do you want to continue?"
read -r -p "[Y/N]: " input
case $input in
[yY][eE][sS]|[yY])
echo -e "${PREFIX} No going back now"
;;
[nN][oO]|[nN])
echo -e "${PREFIX} Abort."
exit 1
;;
*)
echo -e "${PREFIX} Invalid input"
exit 1
;;
esac
echo " "
echo -e "${PREFIX} Creating partitions..."
echo " "
echo -e "${PREFIX} *Ignore the 'not mounted' errors, they are normal*"
echo " "
if [[ $MACOS == *"1"* ]]; then
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
else
umount /dev/$disk*
fi
if [[ $MACOS == *"1"* ]]; then
printf "o\nY\nn\n1\n\n+1000M\n0700\nw\nY\n" | sudo gdisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to partition disk"; exit 1; }
sync
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
#echo -e "${PREFIX} \e[0;31mNOTE:\e[0m Due to macOS weirdness you need to disconnect and reconnect the drive now"
#read -p "Press enter to continue..."
binbowstype() {
echo " "
echo -e "${PREFIX} [1]: Do you want the installer to be able to install Windows on the same drive (at least 32GB)?"
echo -e "${PREFIX} [2]: OR create an installation media on this drive (at least 8GB) that's able to install Windows on other drives (at least 16GB)?"
read -r -p "[1/2]: " input
echo " "
case $input in
[1])
printf "n\n2\n\n+19000M\n0700\nw\nY\n" | sudo gdisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to partition disk"; exit 1; }
sync
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
#echo -e "${PREFIX} \e[0;31mNOTE:\e[0m Again, due to macOS weirdness you need to disconnect and reconnect the drive now"
#read -p "Press enter to continue..."
return 0
;;
[2])
printf "n\n2\n\n\n0700\nw\nY\n" | sudo gdisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to partition disk"; exit 1; }
sync
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
#echo -e "${PREFIX} \e[0;31mNOTE:\e[0m Again, due to macOS weirdness you need to disconnect and reconnect the drive now"
#read -p "Press enter to continue..."
return 0
;;
*)
echo -e "${PREFIX} Invalid input"
return 1
;;
esac
}
until binbowstype; do : ; done
else
parted -s /dev/$disk mklabel gpt
parted -s /dev/$disk mkpart primary 1MB 1000MB
parted -s /dev/$disk set 1 msftdata on
binbowstype() {
echo " "
echo -e "${PREFIX} [1]: Do you want the installer to be able to install Windows on the same drive (at least 32GB)?"
echo -e "${PREFIX} [2]: OR create an installation media on this drive (at least 8GB) that's able to install Windows on other drives (at least 16GB)?"
read -r -p "[1/2]: " input
echo " "
case $input in
[1])
parted -s /dev/$disk mkpart primary 1000MB 19000MB
parted -s /dev/$disk set 2 msftdata on
return 0
;;
[2])
parted -s -- /dev/$disk mkpart primary 1000MB -0
parted -s /dev/$disk set 2 msftdata on
return 0
;;
*)
echo -e "${PREFIX} Invalid input"
return 1
;;
esac
}
until binbowstype; do : ; done
fi
sync
if [[ $MACOS == *"1"* ]]; then
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
fi
mkfs.fat -F 32 /dev/$nisk'1' || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to format disk"; exit 1; }
sync
if [[ $MACOS == *"1"* ]]; then
diskutil unmountDisk /dev/$disk || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to unmount disk"; exit 1; }
fi
mkfs.exfat /dev/$nisk'2' || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to format disk"; exit 1; }
sync
mkdir -p /tmp/bootpart /tmp/winpart
if [[ $MACOS == *"1"* ]]; then
diskutil mount -mountPoint /tmp/bootpart /dev/$nisk'1' || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to mount disk"; exit 1; }
diskutil mount -mountPoint /tmp/winpart /dev/$nisk'2' || { echo -e "${PREFIX} \e[0;31mERROR:\e[0m Failed to mount disk"; exit 1; }
else
mount /dev/$nisk'1' /tmp/bootpart
mount /dev/$nisk'2' /tmp/winpart
fi
echo " "
echo -e "${PREFIX} Copying Windows files to the drive, this may take a while..."
echo " "
echo -e "${PREFIX} *NOTE: 'WARNING: Device write-protected, mounted read-only' is also normal*"
echo " "
if [[ $MACOS == *"1"* ]]; then
hdiutil attach $iso -mountpoint /tmp/isomount -nobrowse
else
mount $iso /tmp/isomount
fi
cp -r /tmp/isomount/boot /tmp/bootpart
cp -r /tmp/isomount/efi /tmp/bootpart
mkdir /tmp/bootpart/sources
cp /tmp/isomount/sources/boot.wim /tmp/bootpart/sources
if [[ $custwim == *"1"* ]]; then
cp $wim /tmp/winpart
else
cp /tmp/isomount/sources/install.wim /tmp/winpart
fi
if [[ $MACOS == *"1"* ]]; then
hdiutil detach /tmp/isomount
else
umount /tmp/isomount
fi
echo " "
echo -e "${PREFIX} Copying the PE-installer to the drive..."
echo " "
unzip $inst -d /tmp/peinstaller
cp -r /tmp/peinstaller/efi /tmp/bootpart
wimupdate /tmp/bootpart/sources/boot.wim 2 --command="add /tmp/peinstaller/winpe/2 /"
echo " "
echo -e "${PREFIX} Copying the drivers to the drive..."
echo " "
unzip $driv -d /tmp/driverpackage
wimupdate /tmp/bootpart/sources/boot.wim 2 --command="add /tmp/driverpackage /drivers"
echo " "
echo -e "${PREFIX} Copying the UEFI boot files to the drive..."
echo " "
unzip $efi -d /tmp/uefipackage
sudo cp /tmp/uefipackage/* /tmp/bootpart
echo " "
echo -e "${PREFIX} *Ignore 'cp: -r not specified; omitting directory...'*"
echo " "
if [[ $PI == *"3"* ]]; then
echo -e "${PREFIX} Installing to Pi 3 and below, applying gptpatch..."
echo " "
dd if=/tmp/peinstaller/pi3/gptpatch.img of=/dev/$disk conv=fsync
else
echo -e "${PREFIX} Installing to Pi 4, no need to apply gptpatch"
fi
echo " "
echo -e "${PREFIX} Unmounting drive, this may also take a while..."
sync
echo " "
echo -e "${PREFIX} *Again, ignore the 'not mounted' errors, they are normal*"
echo " "
if [[ $MACOS == *"1"* ]]; then
diskutil unmountDisk /dev/$disk
else
umount /dev/$disk*
fi
echo " "
echo -e "${PREFIX} Cleaning up..."
rm -rf /tmp/driverpackage
rm -rf /tmp/uefipackage
rm -rf /tmp/peinstaller
rm -rf /tmp/isomount
rm -rf /tmp/bootpart
rm -rf /tmp/winpart
if [[ $auto == *"1"* ]]; then
rm -rf /tmp/UEFI_Firmware.zip
rm -rf /tmp/Windows_ARM64_Drivers.zip
rm -rf /tmp/WoR-PE_Package.zip
else
echo " "
echo -e "${PREFIX} No need to clear downloaded files"
fi
echo " "
echo -e "${PREFIX} 1. Connect the drive and other peripherals to your Raspberry Pi then boot it up."
echo " "
echo -e "${PREFIX} 2. Assuming everything went right in the previous steps, you'll be further guided by the PE-based installer on your Pi."
echo " "
echo -e "${PREFIX} - If you've used the 1st method (self-installation), there's no need to touch the Raspberry Pi once it has booted. The installer will automatically start the installation process after a delay of 15 seconds. Moving the mouse cursor over the Windows Setup window will stop the timer, so you'll have to manually click on the Install button."
echo " "
echo -e "${PREFIX} - If you've used the 2nd method (installing on a secondary drive), you must also connect the 2nd drive before the installer window opens up, then select it in the drop-down list. Otherwise, it will assume you're trying to install Windows on the same drive (self-installation)."
echo " "
echo -e "${PREFIX} \e[0;31mNOTE:\e[0m Disabling the 3gb ram limit before the first boot can cause the disk to not be recognized in the PE-installer. The limit can be removed AFTER the installation."
echo " "
echo -e "${PREFIX} All done :)"
echo -e "${PREFIX} Thanks for using WoRli!"
echo " "
exit 0