forked from ryanrudolfoba/SteamDeck-Clover-dualboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-Clover.sh
281 lines (224 loc) · 10 KB
/
install-Clover.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
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
CLOVER_VERSION='5151'
clear
echo Clover Install Script by ryanrudolf
echo https://github.com/ryanrudolfoba/SteamDeck-Clover-dualboot
sleep 2
# Password sanity check - make sure sudo password is already set by end user!
if [ "$(passwd --status deck | tr -s " " | cut -d " " -f 2)" == "P" ]
then
read -s -p "Please enter current sudo password: " current_password ; echo
echo Checking if the sudo password is correct.
echo -e "$current_password\n" | sudo -S -k ls &> /dev/null
if [ $? -eq 0 ]
then
echo -e "$GREEN"Sudo password is good!
else
echo -e "$RED"Sudo password is wrong! Re-run the script and make sure to enter the correct sudo password!
exit
fi
else
echo -e "$RED"Sudo password is blank! Setup a sudo password first and then re-run script!
passwd
exit
fi
# sudo password is already set by the end user, all good let's go!
echo -e "$current_password\n" | sudo -S ls &> /dev/null
if [ $? -eq 0 ]
then
echo -e "$GREEN"1st sanity check. So far so good!
else
echo -e "$RED"Something went wrong on the 1st sanity check! Re-run script!
exit
fi
###### Main menu. Ask user for the default OS to be selected in the Clover GUI boot menu.
Choice=$(zenity --width 900 --height 250 --list --radiolist --multiple --title "Clover Install Script for Steam Deck - https://github.com/ryanrudolfoba/SteamDeck-clover-dualboot"\
--column "Select One" \
--column "Default OS" \
--column="Comments - Read this carefully!"\
FALSE Windows "Choose this and Windows will be the default OS selected in the Clover GUI boot menu."\
FALSE SteamOS "Choose this and SteamOS will be the default OS selected in the Clover GUI boot menu."\
TRUE EXIT "Select this if you changed your mind and don't want to proceed anymore.")
if [ $? -eq 1 ] || [ "$Choice" == "EXIT" ]
then
echo User pressed CANCEL / EXIT. Make no changes. Exiting immediately.
exit
else
OS=$Choice
fi
# obtain Clover ISO
clover_archive=$(curl -s -O -L -w "%{filename_effective}" "https://github.com/CloverHackyColor/CloverBootloader/releases/download/${CLOVER_VERSION}/Clover-${CLOVER_VERSION}-X64.iso.7z")
clover_base=$(basename -s .7z $clover_archive)
7z x $clover_archive -aoa $clover_base
# mount Clover ISO
sudo mkdir ~/temp-clover && sudo mount $clover_base ~/temp-clover &> /dev/null
if [ $? -eq 0 ]
then
echo -e "$GREEN"2nd sanity check. ISO has been mounted!
else
echo -e "$RED"Error mounting ISO!
sudo umount ~/temp-clover
rmdir ~/temp-clover
exit
fi
# copy Clover files to EFI system partition
sudo mkdir -p /esp/efi/clover && sudo cp -Rf ~/temp-clover/efi/clover /esp/efi/ && sudo cp custom/$OS-config.plist /esp/efi/clover/config.plist && sudo cp -Rf custom/themes/* /esp/efi/clover/themes
if [ $? -eq 0 ]
then
echo -e "$GREEN"3rd sanity check. Clover has been copied to the EFI system partition!
else
echo -e "$RED"Error copying files. Something went wrong.
sudo umount ~/temp-clover
rmdir ~/temp-clover
exit
fi
# cleanup temp directories created
sudo umount ~/temp-clover
sudo rmdir ~/temp-clover
# remove previous Clover entries before re-creating them
for entry in $(efibootmgr | grep -i "Clover" | colrm 9 | colrm 1 4)
do
sudo efibootmgr -b $entry -B &> /dev/null
done
# install Clover to the EFI system partition
sudo efibootmgr -c -d /dev/nvme0n1 -p 1 -L "Clover - GUI Boot Manager" -l "\EFI\clover\cloverx64.efi" &> /dev/null
# backup and disable the Windows EFI entry!
sudo cp /esp/efi/Microsoft/Boot/bootmgfw.efi /esp/efi/Microsoft/Boot/bootmgfw.efi.orig && sudo mv /esp/efi/Microsoft/Boot/bootmgfw.efi /esp/efi/Microsoft
# re-arrange the boot order and make Clover the priority!
Clover=$(efibootmgr | grep -i Clover | colrm 9 | colrm 1 4)
SteamOS=$(efibootmgr | grep -i SteamOS | colrm 9 | colrm 1 4)
sudo efibootmgr -n $Clover &> /dev/null
sudo efibootmgr -o $Clover,$SteamOS &> /dev/null
# Final sanity check
efibootmgr | grep "Clover - GUI" &> /dev/null
if [ $? -eq 0 ]
then
echo -e "$GREEN"Final sanity check. Clover has been successfully installed to the EFI system partition!
else
echo -e "$RED"Whoopsie something went wrong. Clover is not installed.
exit
fi
# copy dolphin root extension to easily add themes
mkdir -p ~/.local/share/kservices5/ServiceMenus
cp custom/open_as_root.desktop ~/.local/share/kservices5/ServiceMenus
sleep 2
echo \****************************************************************************************************
echo Post install scripts saved in 1Clover-tools. Use them as needed -
echo \****************************************************************************************************
echo enable-windows-efi.sh - Use this script to re-enable Windows EFI entry and temp disable Clover.
echo uninstall-Clover.sh - Use this to completely uninstall Clover from the EFI system partition.
echo \****************************************************************************************************
echo \****************************************************************************************************
#################################################################################
################################ post install ###################################
#################################################################################
# create ~/1Clover-tools and place the scripts in there
mkdir ~/1Clover-tools &> /dev/null
rm -f ~/1Clover-tools/* &> /dev/null
# enable-windows-efi.sh - use this to temporarily re-enable the Windows EFI entry
cat > ~/1Clover-tools/enable-windows-efi.sh << EOF
#!/bin/bash
# restore Windows EFI entry from backup
sudo cp /esp/efi/Microsoft/Boot/bootmgfw.efi.orig /esp/efi/Microsoft/Boot/bootmgfw.efi
# make Windows the next boot option!
Windows=\$(efibootmgr | grep -i Windows | colrm 9 | colrm 1 4)
sudo efibootmgr -n \$Windows &> /dev/null
echo Clover has been temporarily deactivated and Windows EFI entry has been re-enabled!
EOF
# uninstall-Clover.sh - use this to revert any changes made and uninstall Clover
cat > ~/1Clover-tools/uninstall-Clover.sh << EOF
#!/bin/bash
# restore Windows EFI entry from backup
sudo mv /esp/efi/Microsoft/Boot/bootmgfw.efi.orig /esp/efi/Microsoft/Boot/bootmgfw.efi
sudo rm /esp/efi/Microsoft/bootmgfw.efi
# remove Clover from the EFI system partition
sudo rm -rf /esp/efi/clover
for entry in \$(efibootmgr | grep "Clover - GUI" | colrm 9 | colrm 1 4)
do
sudo efibootmgr -b \$entry -B &> /dev/null
done
rm -rf ~/1Clover-tools/*
# delete systemd service
sudo steamos-readonly disable
sudo systemctl stop clover-bootmanager.service
sudo rm /etc/systemd/system/clover-bootmanager.service
sudo systemctl daemon-reload
sudo steamos-readonly enable
# delete dolphin root extension
rm ~/.local/share/kservices5/ServiceMenus/open_as_root.desktop
# delete the injected systemd from the other rootfs
echo "mount -o rw,remount / ; sudo steamos-readonly disable ; sudo rm /etc/systemd/system/clover-bootmanager.service" | sudo steamos-chroot --partset other -- &> /dev/null
echo Clover has been uninstalled and the Windows EFI entry has been restored!
EOF
# post-install-Clover.sh
cat > ~/1Clover-tools/post-install-Clover.sh << EOF
#!/bin/bash
CloverStatus=/home/deck/1Clover-tools/status.txt
echo Clover Boot Manager > \$CloverStatus
date >> \$CloverStatus
echo BIOS Version : \$(sudo dmidecode -s bios-version) >> \$CloverStatus
# check for dump files
dumpfiles=\$(ls -l /sys/firmware/efi/efivars/dump-type* 2> /dev/null | wc -l)
if [ \$dumpfiles -gt 0 ]
then
echo dump files exists. performing cleanup. >> \$CloverStatus
sudo rm -f /sys/firmware/efi/efivars/dump-type*
else
echo no dump files. no action needed. >> \$CloverStatus
fi
# Sanity Check - are the needed EFI entries available?
efibootmgr | grep -i Clover &> /dev/null
if [ \$? -eq 0 ]
then
echo Clover EFI entry exists! No need to re-add Clover. >> \$CloverStatus
else
echo Clover EFI entry is not found. Need to re-ad Clover. >> \$CloverStatus
efibootmgr -c -d /dev/nvme0n1 -p 1 -L "Clover - GUI Boot Manager" -l "\EFI\clover\cloverx64.efi" &> /dev/null
fi
efibootmgr | grep -i Steam &> /dev/null
if [ \$? -eq 0 ]
then
echo SteamOS EFI entry exists! No need to re-add SteamOS. >> \$CloverStatus
else
echo SteamOS EFI entry is not found. Need to re-add SteamOS. >> \$CloverStatus
efibootmgr -c -d /dev/nvme0n1 -p 1 -L "SteamOS" -l "\EFI\steamos\steamcl.efi" &> /dev/null
fi
# disable the Windows EFI entry!
test -f /esp/efi/Microsoft/Boot/bootmgfw.efi && echo Windows EFI exists! Moving it to /esp/efi/Microsoft >> \$CloverStatus && sudo cp /esp/efi/Microsoft/Boot/bootmgfw.efi /esp/efi/Microsoft/Boot/bootmgfw.efi.orig && sudo mv /esp/efi/Microsoft/Boot/bootmgfw.efi /esp/efi/Microsoft &>> \$CloverStatus
# re-arrange the boot order and make Clover the priority!
Clover=\$(efibootmgr | grep -i Clover | colrm 9 | colrm 1 4)
SteamOS=\$(efibootmgr | grep -i SteamOS | colrm 9 | colrm 1 4)
efibootmgr -o \$Clover,\$SteamOS &> /dev/null
echo "*** Current state of EFI entries ****" >> \$CloverStatus
efibootmgr >> \$CloverStatus
chown deck:deck \$CloverStatus
EOF
#clover-bootmanager.service - systemd service that calls post-install-Clover.sh on startup
cat > ~/1Clover-tools/clover-bootmanager.service << EOF
[Unit]
Description=Custom systemd service for Clover - GUI Boot Manager.
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c '/home/deck/1Clover-tools/post-install-Clover.sh'
[Install]
WantedBy=multi-user.target
EOF
# inject systemd service to the other rootfs
echo "mount -o rw,remount / ; sudo steamos-readonly disable ; echo -e \"
[Unit]
Description=Custom systemd service for Clover - GUI Boot Manager.
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c '/home/deck/1Clover-tools/post-install-Clover.sh'
[Install]
WantedBy=multiuser.target
\" > /etc/systemd/system/clover-bootmanager.service" | sudo steamos-chroot --partset other -- &> /dev/null
echo "mount -o rw,remount / ; sudo steamos-readonly disable ; systemctl enable --now clover-bootmanager.service" | sudo steamos-chroot --partset other -- &> /dev/null
chmod +x ~/1Clover-tools/*
sudo cp ~/1Clover-tools/clover-bootmanager.service /etc/systemd/system/clover-bootmanager.service
sudo systemctl daemon-reload
sudo systemctl enable --now clover-bootmanager.service