/
raspi-install.sh
executable file
·133 lines (111 loc) · 4.23 KB
/
raspi-install.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
#!/bin/bash
# gemacht von Stefan Höhn
#https://github.com/dewomser/Raspi-auto-downloader
#ACHTUNG : Zeile 106-112 Beachten !
attribut=$1
datum="[0-9]{4}-[0-9]{2}-[0-9]{2}"
if [[ "$attribut" = "-h" ]]
then
echo "
Aufruf raspi-install.sh [OPTION]
Option Bedeutung
-f raspios_full_armhf Raspberry Pi OS with desktop and recommended software
-l raspios_lite_armhf Raspberry Pi OS Lite
-d raspios_armhf Raspberry Pi OS with desktop
-h Diese Hilfe
-f64 raspios_full_arm64
-l64 raspios_lite_arm64
-d64 raspios_arm64
" && exit
elif [[ "$attribut" = "-f" ]]
then
rimage="raspios_full_armhf"
elif [[ "$attribut" = "-l" ]]
then
rimage="raspios_lite_armhf"
elif [[ "$attribut" = "-d" ]]
then
rimage="raspios_armhf"
elif [[ "$attribut" = "-f64" ]]
then
rimage="raspios_full_arm64"
elif [[ "$attribut" = "-l64" ]]
then
rimage="raspios_lite_arm64"
elif [[ "$attribut" = "-d64" ]]
then
rimage="raspios_arm64"
else
echo "Kein Pi-Image ausgewählt. \"raspi-install.sh -h \" für Hilfe!" && exit
fi
#rimage ="raspios_lite_armhf"
#rimage="raspios_full_armhf"
cd "$HOME/Downloads" || echo"Downloads Ordner nicht vorhanden"
dirr=$(curl --silent "https://downloads.raspberrypi.org/$rimage/images/" | grep -o -E "$rimage-$datum" | tail -1 )
pathr="https://downloads.raspberrypi.org/$rimage/images/$dirr/"
#rname=$(curl --silent "$pathr" | grep -o -E -w "$datum-[[:lower:]-]*\.zip" | head -1)
#rname=$(curl --silent "$pathr" | grep -o -E "$datum-[[:alnum:]-]*\.xz" | head -1)
rname=$(curl --silent "$pathr" | grep -o -E "$datum-[[:alnum:]-]*\.img\.xz"|tail -1)
wget -c "$pathr""$rname" -O "raspi$attribut".xz
#echo Test kompletter Pfad :: "$pathr""$rname"
shaname=$(curl --silent "$pathr" | grep -o -E -w "$datum-[[:alnum:]-]*\.img.\xz\.sha256" | tail -1)
#echo Test kompletter sha256-Pfad :: $pathr$shaname
wget "$pathr""$shaname" -O raspi"$attribut".sha256
echo "Bitte ein paar Sekunden warten. Der Hash wird erzeugt."
sha1=$(shasum -a 256 raspi"$attribut".xz | grep -o -P "[0-9a-z]{40,}")
sha2=$( grep -o -P "[0-9a-z]{40,}" < raspi"$attribut".sha256 )
sleep 1
echo Prüfsumme aus Download "$sha1"
echo Prüfsumme von Webseite "$sha2"
if [ "$sha1" == "$sha2" ]; then
echo "Prüfsumme stimmt."
echo "-----------------"
echo "SD-Karte auf die geschrieben werden soll ENTFERNEN !" \"y\"
read -r input
if [ "$input" == "y" ]; then
mapfile -t laufwerke < <(lsblk -l -o Name | grep -E "^sd[a-z]*$")
laufwerke[0]="lolo"
laufwerke1[0]="lolo"
else
exit
fi
echo Es gibt diese seriellen Blockdevices "${laufwerke[*]}"
echo "SD-Karte auf die geschrieben werden soll EINSCHIEBEN !" \"y\"
read -r input
if [ "$input" == "y" ]; then
mapfile -t laufwerke1 < <(lsblk -l -o Name |grep -E "^sd[a-z]*$")
echo "${laufwerke1[0]}"
mapfile -t laufwerke2 < <({ printf "%s\n" "${laufwerke[@]}" | sort -u; printf "%s\n" "${laufwerke1[@]}" "${laufwerke[@]}"; } | sort | uniq -u)
zahl_laufwerke="${#laufwerke2[@]}"
echo neu erkannte Es gibt jetzt dieses neue serielle Blockdevice: "${laufwerke2[@]}"
echo Laufwerke ${#laufwerke2[@]}
echo lwo:"${laufwerke2[0]}"
echo lw1:"${laufwerke2[1]}"
if [ "$zahl_laufwerke" -eq 1 ]; then
echo Es gibt jetzt dieses neue serielle Blockdevice: "${laufwerke2[0]}"
else
echo "Es kann nicht geschrieben werden. Es wurden mehr oder weniger als 1 SD-Karte erkannt" ; exit
fi
else
exit
fi
echo Ich bin mir SICHER und will auf SD-Karte schreiben : /dev/"${laufwerke2[0]}" \"y\" oder \"n\"
read -r endgueltigja
if [ "$endgueltigja" == "y" ]; then
# Wenn die Karte nur als root gemountet werden kann, muss dd durch sudo dd ersetzt werden. umount -> sudo umount
## sudo ddd – is now on
# Alternative für Ubuntu:
# echo 'KERNEL=="sd*", SUBSYSTEMS=="usb", MODE="0666"' | sudo tee /etc/udev/rules.d/99-usb-storage.rules
# Quelle : https://askubuntu.com/questions/828545/using-dd-without-sudo
# Wenn die nächsten 3 Zeilen aktiviert sind: "don't blame me!"
#umount /dev/"${laufwerke2[0]}"[0-9] > /dev/null 2>&1
xz --keep --decompress raspi"$attribut".xz
sudo dd if=raspi"$attribut" of=/dev/"${laufwerke2[0]}" bs=4M conv=fsync status=progress || echo "Es gibt Probleme mit Schreibrechten.Ab Zeile 105 gibts Hilfe"
echo "Tatatatah ! fertig"
#umount /dev/"${laufwerke2[0]}"[0-9] > /dev/null 2>&1
else
exit
fi
else
echo "Achtung,Prüfsumme stimmt nicht überein !"
fi