-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathimage-create.sh
More file actions
72 lines (69 loc) · 2.15 KB
/
image-create.sh
File metadata and controls
72 lines (69 loc) · 2.15 KB
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
#!/bin/bash
trap 'BR.unmount; clear -x' EXIT
shrink() {
bar "Shrink Pass #$1 ..."
read b_used b_size b_count < <( tune2fs -l $PART_R | awk '
/^Block count/ { count=$NF }
/^Free blocks/ { free=$NF }
/^Block size/ { size=$NF }
END { print ( count - free ), size, count }' )
b_target=$(( ( b_used * 105 ) / 100 ))
if (( $b_count - b_target < 1024 )); then
bar Almost at minimum size already.
else
b_new=$(( ( b_target * b_size ) / 1024 ))
resize2fs -fp $PART_R ${b_new}K
s_size=$( blockdev --getss $DEV )
s_start=$( cat /sys/class/block/${PART_R/*\/}/start )
s_needed=$(( ( b_target * b_size ) / s_size ))
sfdisk "$DEV" -N ${PART_R: -1} --force <<< "$s_start, $s_needed"
fi
}
# required packages
[[ ! -e /usr/bin/dialog ]] && packages+='dialog '
[[ ! -e /usr/bin/bsdtar ]] && packages+='bsdtar '
if [[ $packages ]]; then
if [[ -e /usr/bin/pacman ]]; then
pacman -Sy --noconfirm $packages
else
[[ ! -e /usr/bin/bsdtar ]] && packages+='libarchive-tools '
apt install -y $packages
fi
fi
#............................
dialog.splash Image File
read DEV PART_B PART_R < <( dialog.sd )
banner Check Partitions ...
bar BOOT: $PART_B ...
fsck.fat -taw $PART_B
bar ROOT: $PART_R ...
e2fsck -p $PART_R
BR.mount
file_r1=ROOT/srv/http/data/addons/r1
[[ ! -e $file_r1 ]] && dialog.error_exit 'SD card is not rAudio: \Z1$DEVZn'
#------------------------------------------------------------------------------
release=$( < $file_r1 )
if [[ -e BOOT/kernel8.img ]]; then
model=64bit
elif [[ -e BOOT/kernel7.img ]]; then
model=32bit
else # BOOT/kernel.img
model=Legacy
fi
#............................
file_img=$( dialog.input 'Image filename:' rAudio-$model-$release.img.xz )
touch BOOT/expand # auto expand root partition
BR.unmount
#............................
banner Shrink ROOT
shrink 1
shrink 2
#............................
banner Compressed to image file ...
bar $file_img
threads=$(( $( nproc ) - 2 ))
dd if=$DEV bs=512 iflag=fullblock count=$s_end | nice -n 10 xz -v -T $threads > "$file_img"
size=$( xz -l --robot $file_img | awk '/^file/ {printf "%.2f MB <<< %.2f GB", $4/10^6, $5/10^9}' )
bar "Image file created:
$file_img
$size"