-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch
executable file
·334 lines (314 loc) · 7.39 KB
/
fetch
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
#!/bin/bash
export LC_ALL=$(locale -a|grep -ix 'c.utf-\?8' || echo C)
DOWNLOAD="aria2c -c --download-result=hide --console-log-level=error --disable-ipv6=true --summary-interval=0 --show-files=false"
URL="https://github.com/pyavitz/rpi-linux/releases/download/gcc-11/"
RED="\e[0;31m"
GRN="\e[0;32m"
PNK="\e[0;35m"
TXT="\033[0m"
YLW="\e[1;33m"
SRED="\e[0;31m"
SGRN="\e[0;32m"
SYLW="\e[0;33m"
FIN="\e[0m"
prep(){
if [ -e ~/.build ]; then
sudo rm -fdr ~/.build/*; cd ~/.build
else
mkdir -p ~/.build; cd ~/.build
fi
}
echo_bdone(){
echo -e "${PNK}[${FIN}${GRN}done${FIN}${PNK}]${FIN}"
}
list(){
version=$(curl --silent -L ${URL}version)
echo $version
}
update(){
if [[ -f "/usr/local/bin/fetch" ]]; then
sudo mv -f /usr/local/bin/fetch /usr/local/bin/fetch.orig
sudo wget -cq https://raw.githubusercontent.com/pyavitz/scripts/master/fetch -P /usr/local/bin
sleep .50
if [[ -f "/usr/local/bin/fetch" ]]; then
sudo rm -f /usr/local/bin/fetch.orig
sudo chmod +x /usr/local/bin/fetch
else
sudo mv -f /usr/local/bin/fetch.orig /usr/local/bin/fetch
fi
fi
fetch -h
}
initrd_check(){
if [[ -f "/etc/initramfs/post-update.d/99-initrd" ]]; then
:;
else
sudo mkdir -p /etc/initramfs/post-update.d/;
sudo wget -cq https://raw.githubusercontent.com/pyavitz/rpi-img-builder/master/files/scripts/99-initrd -P /etc/initramfs/post-update.d/;
sudo chmod +x /etc/initramfs/post-update.d/99-initrd;
sudo chown root:root /etc/initramfs/post-update.d/99-initrd;
fi
}
# Linux
rpi-linux(){
initrd_check; prep;
if [[ `wget -S --spider ${URL}$BOARD-$RELEASE.tar.xz 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
echo -e "${TXT}Fetching $BOARD-$RELEASE${FIN} ...";
${DOWNLOAD} ${URL}$BOARD-$RELEASE.sha256;
${DOWNLOAD} ${URL}$BOARD-$RELEASE.tar.xz;
echo_bdone;
else
echo -e "${TXT}Something went wrong? Please report which Distribution and Release you are using.${FIN}";
exit 0;
fi
echo ""
if [[ `sha256sum --check $BOARD-$RELEASE.sha256 | grep "OK"` ]]; then
echo -e "${TXT}Extracting archive${FIN} ...";
pv $BOARD-$RELEASE.tar.xz | tar -xJ $BOARD-$RELEASE;
rm -f $BOARD-$RELEASE.tar.xz;
echo "";
echo -e "${TXT}Starting install${FIN} ...";
cd $BOARD-$RELEASE;
sudo dpkg -i *.deb;
cd ~;
echo -e "${TXT}Done${FIN}.";
sudo rm -fdr ~/.build/*;
else
echo -e "${TXT}Something went wrong? Please report which Distribution and Release you are using${FIN}.";
exit 0;
fi
}
# Firmware
firmware(){
FWURL="https://github.com/pyavitz/firmware.git"
FWDEST="/lib/firmware/updates/brcm"
RBFALSE="sudo git config pull.rebase false"
echo -e "${TXT}Checking firmware${FIN} ..."
sudo mkdir -p /lib/firmware/updates
if [ -e /etc/firmware ]; then
:;
else
sudo ln -sr /lib/firmware /etc/firmware;
fi
if [[ `command -v git` ]]; then
:;
else
sudo apt update
sudo apt install -y git;
fi
if [ -e ${FWDEST}/.git ]; then
cd ${FWDEST}
${RBFALSE}
sudo git pull;
else
sudo git clone ${FWURL} ${FWDEST};
fi
echo -e "${TXT}Done${FIN}".
cd ~
}
# Userland
rpi_userland(){
echo -e "${TXT}Updating userland${FIN} ..."
if [ -d ~/.build/userland ]; then rm -fdr ~/.build/*; fi
mkdir -p ~/.build
cd ~/.build
git clone https://github.com/raspberrypi/userland.git
cd userland
wget -cq https://raw.githubusercontent.com/pyavitz/rpi-img-builder/master/files/patches/userland-remove-hi-pi.patch
patch -p1 < userland-remove-hi-pi.patch
rm -f userland-remove-hi-pi.patch
if [[ $(grep -w "Linux/arm64" "/usr/src/linux-headers-`uname -r`/.config") ]]; then
echo -e "\e[1;37m== ARM64\e[0m";
sleep 1s;
./buildme --aarch64;
fi
if [[ $(grep -w "Linux/arm" "/usr/src/linux-headers-`uname -r`/.config") ]]; then
echo -e "\e[1;37m== ARM\e[0m";
sleep 1s;
./buildme;
fi
cd ~
sudo rm -fdr ~/.build/userland
sudo ldconfig
echo -e "${TXT}Done${FIN}."
}
# check
if [[ `curl -I https://github.com 2>&1 | grep 'HTTP/2 200'` ]]; then
if [[ `command -v wget` ]] && [[ `command -v aria2c` ]] && [[ `command -v pv` ]]; then
:;
else
sudo apt install -y wget aria2 pv;
fi
else
echo ""
read -p "This script requires an internet connection."
exit 0
fi
# commands
if [ $# -eq 0 ]; then
echo -e "\e[0;31mMissing options!${FIN}"
echo "(run $0 -h for help)"
echo ""
exit 0
fi
while getopts "12brumUhf" OPTION; do
case $OPTION in
1)
ECHO="5.15"
;;
2)
ECHO="stable"
;;
f)
ECHO="firmware"
;;
U)
ECHO="userland"
;;
r)
ECHO="rev"
;;
u)
ECHO="update"
;;
m)
clear -x
echo -e "Fetching Releases ..."
VERSION="https://github.com/pyavitz/rpi-linux/releases/download/gcc-11/version2"
LTS=`curl --silent -L $VERSION | sed -n 1p`
STB=`curl --silent -L $VERSION | sed -n 2p`
while [ 1 ]
do
CHOICE=$(
export NEWT_COLORS='root=,black roottext=lightgray,black title=black,lightgray'
whiptail --backtitle "Fetch, Linux kernel installer for the Raspberry Pi Image Builder" --title "== Fetch ==" --menu "" --nocancel 0 0 0 \
"1)" "Linux $LTS LTS Release" \
"2)" "Linux $STB Stable Release" \
"3)" "Wifi/Bluetooth Update Firmware" \
"4)" "Pi Userland Update Userland" \
"E)" "Exit .." 3>&2 2>&1 1>&3
)
case $CHOICE in
"1)")
clear -x
fetch -1
echo ""
read -p "Press enter to continue."
clear -x
;;
"2)")
clear -x
fetch -2
echo ""
read -p "Press enter to continue."
clear -x
;;
"3)")
clear -x
fetch -f
echo ""
read -p "Press enter to continue."
clear -x
;;
"4)")
clear -x
fetch -U
echo ""
read -p "Press enter to continue."
clear -x
;;
"E)")
clear -x
exit 0
;;
esac
done
;;
h)
echo -e "${TXT}Fetch, Linux kernel installer for the Raspberry Pi Image Builder${FIN}"
echo "https://github.com/pyavitz/rpi-img-builder"
echo "Usage: "
echo ""
list
echo ""
echo -e "\t-1\tLinux 5.15.y LTS"
echo -e "\t-2\tLinux Stable Branch"
echo -e "\t-f\tUpdate Wifi/BT Firmware"
echo -e "\t-U\tUpdate Raspberry Pi Userland"
echo ""
echo -e "\t-u\tUpdate Fetch"
echo ""
echo "Should you come across any bugs, either open an issue on GitHub or talk"
echo "with us directly by joining our channel on Libera; #arm-img-builder"
exit 0
;;
esac
done
if [ $ECHO = "5.15" ]; then
echo ""
RELEASE="5.15.y"
if [[ `grep -w "bcm2708" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi";
rpi-linux;
fi
if [[ `grep -w "bcm2709" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi2";
rpi-linux;
fi
if [[ `grep -w "bcm2710" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi3";
rpi-linux;
fi
if [[ `grep -w "bcm2711" "/etc/opt/soc.txt"` ]]; then
if [[ `grep -w "arm64" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi4";
rpi-linux;
else
BOARD="rpi4v7";
rpi-linux;
fi
fi
fi
if [ $ECHO = "stable" ]; then
echo ""
RELEASE="stable"
if [[ `grep -w "bcm2708" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi";
rpi-linux;
fi
if [[ `grep -w "bcm2709" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi2";
rpi-linux;
fi
if [[ `grep -w "bcm2710" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi3";
rpi-linux;
fi
if [[ `grep -w "bcm2711" "/etc/opt/soc.txt"` ]]; then
if [[ `grep -w "arm64" "/etc/opt/soc.txt"` ]]; then
BOARD="rpi4";
rpi-linux;
else
BOARD="rpi4v7";
rpi-linux;
fi
fi
fi
if [ $ECHO = "rev" ]; then
list;
fi
if [ $ECHO = "update" ]; then
update;
fi
if [ $ECHO = "firmware" ]; then
firmware;
fi
if [ $ECHO = "userland" ]; then
if [ -e /usr/src/linux-headers-`uname -r`/.config ]; then
rpi_userland;
else
echo
echo -e "${TXT}Something went wrong${FIN}?"
exit > /dev/null 2>&1;
fi
fi