forked from hastho/pigeos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpigeos-deploy
executable file
·150 lines (138 loc) · 4.25 KB
/
pigeos-deploy
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
#!/bin/bash
#!/bin/bash
# (c) 2020-21 T.Hass
#
# USAGE pigeos-deploy <stage> [<stage>]
#
# STAGE:
# img_erase erase the deployment dev be overwriting it with zeros
# img_prepare write raspbian-lite image and resize it
# img_build build the image
# img_debug mount the SD card to inspect the image
# img_extract extract the image file from the build SD card
# ext_write write the extracted image to an external card
# help show advanced help (manual)
#
###
#
# NAME: Pi/GEOS DEPLOY v0.2
#
# PURPOSE: Pi/GEOS deployment utillity
#
# DESCRIPTION: This utility is used to prepare a Pi/GEOS image.
#
# img_erase
# ensure all non-used blocks are zero for best compression results
# for final image
# img_build
# build the image inside of a change_root environment
# img_extract
# extract the image file from the build SD card and create an compressed
# archive ready to use with rpi-imager or similar tools
# ext_write
# write the extracted image to an external card to test it on an other
# system
#
# SEE ALSO: pigeos-setup, pigeos-config
#
#####
set -e
# setup for usage and manual
PROGNAME=$(type $0 | cut -d ' ' -f 3)
PROGDIR=$(dirname $PROGNAME)
PROGNAME=$(basename $PROGNAME)
img_file_in=~/Downloads/2023-05-03-raspios-buster-armhf-lite.img.xz
img_file_out=~/Downloads/$(date -Idate)-pigeos-buster-armhf-beta.img.xz
# internal SD card to build to image on
img_dev=/dev/mmcblk0
img_boot=p1
img_root=p2
# external SD card to export image on
ext_dev=/dev/sdb
ext_boot=1
ext_root=2
ext_conf=defaults/config.txt
ext_1str=$HOME/Downloads/firstrun.sh
# bundled GEOS image to include for off-line installation
bdl_geos_img=~/Downloads/ensprev60d.tgz
usage() {
echo "" >&2
echo "$PROGNAME:" "$@" >&2
sed -n '/^###/q; /^#/!q; s/^#//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME" >&2
exit 254
}
help() {
echo "" >&2
echo "$PROGNAME:" "$@" >&2
sed -n '/^#####/q; /^#/!q; s/^#*//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME" >&2
exit 254
}
img_erase() {
dd if=/dev/zero of=$img_dev bs=1M status=progress
return 0
}
img_prepare() {
# write base image
sudo rpi-imager --cli $img_file_in $img_dev
# extend root file system
echo ", +1G" | sudo sfdisk -N 2 $img_dev
sudo fsck.ext4 -f $img_dev$img_root
sudo resize2fs $img_dev$img_root
}
img_build() {
# ingest Pi/GEOS files
sudo mount -t ext4 $img_dev$img_root /mnt/pigeos/root/
sudo mount -t vfat $img_dev$img_boot /mnt/pigeos/root/boot
sudo mount -t proc proc /mnt/pigeos/root/proc
sudo mount -t sysfs sys /mnt/pigeos/root/sys
sudo mount -B /dev /mnt/pigeos/root/dev
sudo mount -B /dev/pts /mnt/pigeos/root/dev/pts
sudo cp -L /etc/resolv.conf /mnt/pigeos/root/etc
sudo mkdir -p /mnt/pigeos/root/usr/local/share/pigeos
sudo cp $bdl_geos_img /mnt/pigeos/root/usr/local/share/pigeos/ensbudle.tgz
sudo cp pigeos-setup /mnt/pigeos/root/usr/local/bin
sudo chroot /mnt/pigeos/root/ \
/bin/bash -ic 'cd /tmp; pigeos-setup setup gr'
sync
sudo umount /mnt/pigeos/root/{dev/pts,dev,sys,proc,boot}
sudo umount $img_dev$img_root
sudo fsck.ext4 -f $img_dev$img_root
}
img_extract() {
# clean free sectors for better comression result
sudo zerofree -v $img_dev$img_root
# calculate imgage size
img_last_sector=$(fdisk -l $img_dev | awk 'END{print $3/8}')
dd if=$img_dev bs=4096 count=$img_last_sector status=progress \
| xz --threads=0 > $img_file_out
sync
}
ext_write() {
sudo rpi-imager --cli $img_file_out $ext_dev
# sudo mount -t vfat $ext_dev$ext_boot /mnt/pigeos
# sudo cp $ext_conf /mnt/pigeos
# sudo cp $ext_1str /mnt/pigeos
# sync
# sudo umount $ext_dev$ext_boot
}
img_debug() {
# ingest Pi/GEOS files
sudo mount -t ext4 $img_dev$img_root /mnt/pigeos/root/
sudo mount -t vfat $img_dev$img_boot /mnt/pigeos/root/boot
sudo mount -t proc proc /mnt/pigeos/root/proc
sudo mount -t sysfs sys /mnt/pigeos/root/sys
sudo mount -B /dev /mnt/pigeos/root/dev
sudo mount -B /dev/pts /mnt/pigeos/root/dev/pts
sudo cp -L /etc/resolv.conf /mnt/pigeos/root/etc
sudo cp pigeos-setup /mnt/pigeos/root/usr/local/bin
sudo chroot /mnt/pigeos/root/ \
/bin/bash -l
sync
sudo umount /mnt/pigeos/root/{dev/pts,dev,sys,proc,boot}
sudo umount $img_dev$img_root
sudo fsck.ext4 -f $img_dev$img_root
}
### MAIN ###
for action in $*; do
$action || break
done