-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeb-eeprom
executable file
·222 lines (198 loc) · 6 KB
/
deb-eeprom
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
#!/usr/bin/env bash
# Description: get latest eeprom
# Destination: /usr/local/bin/deb-eeprom
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DOWNLOAD="aria2c -c --download-result=hide --console-log-level=error --disable-ipv6=true --summary-interval=0 --show-files=false"
PATCHES="https://raw.githubusercontent.com/pyavitz/rpi-img-builder/master/files/patches/"
CHANGELOG="https://raw.githubusercontent.com/raspberrypi/rpi-eeprom/debian/bookworm/debian/changelog"
URL="https://archive.raspberrypi.org/debian/pool/main/r/rpi-eeprom/"
RED="\e[0;31m"
GRN="\e[0;32m"
PNK="\e[0;35m"
TXT="\033[0m"
YLW="\e[0;33m"
FIN="\e[0m"
DEPENDS="help2man rsync pciutils flashrom"
if [ "$USER" != "root" ]; then
echo "Please run this as root or with privileges."
exit 1
fi
if [[ `command -v wget` ]]; then
[[ `wget -S --spider http://github.com 2>&1 | grep 'HTTP/1.1 200 OK'` ]];
else
if [[ `curl -I https://github.com 2>&1 | grep 'HTTP/2 200'` ]]; then
echo -e "${TXT}Installing missing depends${FIN}."
apt update; apt upgrade -y; apt install -y wget
else
echo -e "This script requires an internet connection."
exit 1
fi
fi
if [[ `command -v aria2c` ]]; then :; else apt update; apt upgrade -y; apt install -y aria2; fi
if [[ -e "/boot/firmware" ]]; then
:;
else
if [[ -d "/boot/broadcom" ]]; then ln -s /boot/broadcom /boot/firmware; fi
fi
echo_bdone (){
echo -e "${PNK}[${FIN}${GRN}done${FIN}${PNK}]${FIN}"
}
echo_fail (){
echo -n -e "${PNK}[${FIN}${RED}failed${FIN}${PNK}]${FIN}"
}
current (){
version=$(apt-cache show rpi-eeprom | grep -Po '(?<=Version:)[^;]+' | head -1)
echo " CURRENT: $version"
}
latest (){
version=$(curl --silent -L ${CHANGELOG} | awk '{if (NR==1) {print substr($2, 1, length($2)-3)}}' | sed 's/[()]//g')
echo " AVAILABLE: $version"
}
error (){
echo ""
echo -e ${TXT}Something went wrong${FIN}? ${YLW}Please report error${FIN}.
}
edit (){
if [[ -f "/etc/default/rpi-eeprom-update" ]]; then
nano /etc/default/rpi-eeprom-update
else
echo -e ""
echo -e "${TXT}/etc/default/rpi-eeprom-update is missing${FIN}?"
fi
}
update (){
if [[ `command -v deb-eeprom` ]]; then
mv -f /usr/local/bin/deb-eeprom /usr/local/bin/deb-eeprom.orig
wget -cq https://github.com/pyavitz/scripts/raw/master/deb-eeprom -P /usr/local/bin
chmod +x /usr/local/bin/deb-eeprom
if [[ -f "/usr/local/bin/deb-eeprom" ]]; then
rm -f /usr/local/bin/deb-eeprom.orig
else
mv -f /usr/local/bin/deb-eeprom.orig /usr/local/bin/deb-eeprom
fi
fi
deb-eeprom
}
cleaning (){
cd /home/$USER
rm -fdr /home/$USER/.build/eeprom
}
checking (){
echo ""
echo -e "Checking for updates ..."
apt update
apt upgrade -y
apt install ${DEPENDS} -y
if [[ -e /home/$USER/.eeprom ]]; then rm -f /home/$USER/.eeprom; fi
if [[ `ls /home/$USER/.build/eeprom` ]] > /dev/null 2>&1; then rm -fdr /home/$USER/.build/eeprom; fi
if [[ `ls /usr/local/src/*.patch` ]] > /dev/null 2>&1; then rm -f /usr/local/src/*.patch; fi
if [[ -f /usr/local/bin/deb-eeprom-update ]]; then rm -f /usr/local/bin/deb-eeprom-update; fi
}
check (){
echo ""
rpi-eeprom-update
echo ""
echo "Update bootloader; rpi-eeprom-update -a"
echo ""
}
builddir (){
echo ""
echo -en "Running setup "
sleep 1s
mkdir -p /home/$USER/.build/eeprom
cd /home/$USER/.build/eeprom
wget -cq ${PATCHES}rpi-eeprom-control
wget -cq ${PATCHES}rpi-eeprom-update.patch
if ls /home/$USER/.build/eeprom/{rpi-eeprom-control,rpi-eeprom-update.patch} > /dev/null 2>&1; then
echo_bdone; else echo_fail; exit 1; fi
}
find_eeprom (){
EEPROM_VERSION=$(curl --silent -L ${CHANGELOG} | awk '{if (NR==1) {print substr($2, 1, length($2)-3)}}' | sed 's/[()]//g')
if [[ `wget -S --spider ${URL}rpi-eeprom_${EEPROM_VERSION}.orig.tar.gz 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
download_eeprom; else finding_eeprom; fi
}
finding_eeprom (){
EEPROM_VERSION=$(curl --silent -L ${CHANGELOG} | awk '{if (NR==10) {print substr($2, 1, length($2)-3)}}' | sed 's/[()]//g')
if [[ `wget -S --spider ${URL}rpi-eeprom_${EEPROM_VERSION}.orig.tar.gz 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
download_eeprom; else error; cleaning; exit 1; fi
}
download_eeprom (){
echo ""
echo -en "Searching ..."
sleep .75
${DOWNLOAD} ${URL}rpi-eeprom_${EEPROM_VERSION}-1.debian.tar.xz
${DOWNLOAD} ${URL}rpi-eeprom_${EEPROM_VERSION}.orig.tar.gz && echo_bdone
}
build_eeprom (){
echo ""
echo -e "Updating rpi-eeprom ..."
tar xf rpi-eeprom_${EEPROM_VERSION}.orig.tar.gz
tar xf rpi-eeprom_${EEPROM_VERSION}-1.debian.tar.xz
rm -f rpi-eeprom_${EEPROM_VERSION}-1.debian.tar.xz
mkdir -p debian/patches
mv rpi-eeprom-update.patch debian/patches/rpi-eeprom-update.patch
echo rpi-eeprom-update.patch >> debian/patches/series
rm -f debian/control; mv -f rpi-eeprom-control debian/control
mv -f debian rpi-eeprom-${EEPROM_VERSION}/
cd rpi-eeprom-${EEPROM_VERSION}
dpkg-buildpackage -us -nc -uc
cd ..
dpkg -i *.deb
cd ..
echo -e "Done."
cd /home/$USER
rm -fdr /home/$USER/.build/eeprom
check
}
upgrade (){
checking; builddir; find_eeprom; build_eeprom
}
devel (){
builddir
DEBIAN="https://github.com/raspberrypi/rpi-eeprom.git -b debian/bookworm"
FIRMWARE="https://github.com/raspberrypi/rpi-eeprom.git"
echo ""
git clone ${FIRMWARE}
git clone -q -n --filter=tree:0 --sparse ${DEBIAN} tmp &> /dev/null
cd tmp
git sparse-checkout set --no-cone --quiet debian &> /dev/null
git checkout --quiet &> /dev/null
mv debian ../rpi-eeprom
cd ../rpi-eeprom
rm -fdr ../tmp
mkdir -p debian/patches
mv ../rpi-eeprom-update.patch debian/patches/rpi-eeprom-update.patch
echo rpi-eeprom-update.patch >> debian/patches/series
rm -f debian/control; mv -f ../rpi-eeprom-control debian/control
dpkg-buildpackage -us -nc -uc
cd ..
dpkg -i *.deb
cd ..
echo -e "Done."
cd /home/$USER
rm -fdr /home/$USER/.build/eeprom
check
}
if [ $# -eq 0 ]; then
echo ""
current
latest
echo ""
>&2 echo -e "Arguments: upgrade install stable release
devel install devel release
check release status
edit firmware release status
update deb-eeprom script"
echo -e ""
exit 1
fi
case $1 in
check|devel|edit|update|upgrade)
;;
*)
echo -e "Arguments: check devel edit update upgrade" >&2
exit 1
esac
EEPROM=`echo $1`
$EEPROM
exit 0