-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagewrite.sh
108 lines (84 loc) · 2.29 KB
/
imagewrite.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
#!/bin/bash
# required packages
if [[ -e /usr/bin/pacman ]]; then
[[ ! -e /usr/bin/dialog ]] && packages+='dialog '
[[ ! -e /usr/bin/pv ]] && packages+='pv '
[[ ! -e /usr/bin/xz ]] && packages+='xz '
[[ $packages ]] && pacman -Sy --noconfirm $packages
else
[[ ! -e /usr/bin/dialog ]] && packages+='dialog '
[[ ! -e /usr/bin/pv ]] && packages+='pv '
[[ ! -e /usr/bin/xz ]] && packages+='xz-utils '
[[ $packages ]] && apt install -y $packages
fi
optbox=( --colors --no-shadow --no-collapse )
dialog "${optbox[@]}" --infobox "
\Z1r\Z0Audio
\Z1Write\Z0 Image File
" 9 58
sleep 2
col=$( tput cols )
banner() {
echo
def='\e[0m'
bg='\e[44m'
printf "$bg%*s$def\n" $col
printf "$bg%-${col}s$def\n" " $1"
printf "$bg%*s$def\n" $col
}
dialog "${optbox[@]}" --msgbox "
\Z1Insert micro SD card\Z0
If already inserted:
For proper detection, remove and reinsert again.
" 0 0
sd=$( dmesg -T | tail | grep ' sd .*GB' )
[[ -z $sd ]] && sleep 2 && sd=$( dmesg -T | tail | grep ' sd .* logical blocks' )
if [[ -z $sd ]]; then
dialog "${optbox[@]}" --infobox "
\Z1No SD card found.\Z0
" 0 0
exit
fi
dev=/dev/$( echo $sd | awk -F'[][]' '{print $4}' )
detail=$( echo $sd | sed 's/ sd /\nsd /; s/\(\[sd.\]\) /\1\n/; s/\(blocks\): (\(.*\))/\1\n\\Z1\2\\Z0/' )
dialog "${optbox[@]}" --yesno "
Confirm micro SD card: \Z1$dev\Z0
Detail:
$detail
" 0 0
[[ $? != 0 ]] && exit
rpi=$( dialog "${optbox[@]}" --output-fd 1 --menu "
\Z1Target:\Z0
" 8 0 0 \
0 'Raspberry Pi Zero' \
1 'Raspberry Pi 1' \
2 'Raspberry Pi 2' \
3 'Raspberry Pi 3' \
4 'Raspberry Pi 4' \
5 'Raspberry Pi 64bit' \
6 'Select image file' )
case $rpi in
0 | 1 ) file=rAudio-1-RPi0-1.img.xz ;;
2 | 3 ) file=rAudio-1-RPi2-3.img.xz ;;
4 ) file=rAudio-1-RPi4.img.xz ;;
5 ) file=rAudio-1-RPi64.img.xz ;;
6 ) file=$( basename $( dialog "${optbox[@]}" --title 'Image file' --stdout --fselect $PWD/ 30 70 ) );;
esac
[[ ! -e $file ]] && echo Image file not found. && exit
clear -x
banner 'Write ...'
echo SD card: $dev
echo File : $file
( pv -n $file \
| xz -dc - \
| dd of=$dev bs=4M conv=fsync ) 2>&1 \
| dialog "${optbox[@]}" --gauge "
Write to SD card
\Z1$file\Z0 ...
" 9 58
sync
dialog "${optbox[@]}" --infobox "
\Z1$file\Z0
Image file written successfully.
\Z1Micro SD card\Z0 unmounted.
" 9 58