Skip to content

Commit fc81082

Browse files
committed
implemented ADDPART command
ADDPART appends a partition in the SIZE with a partition type and file system
1 parent b608d15 commit fc81082

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
submodules: recursive
1818

1919
- name: Install dependencies
20-
run: sudo apt-get update && sudo apt-get install -y binfmt-support fdisk file git kpartx lsof p7zip-full qemu qemu-user-static unzip wget xz-utils units
20+
run: sudo apt-get update && sudo apt-get install -y binfmt-support exfatprogs fdisk file git kpartx lsof p7zip-full qemu-user-static unzip wget xz-utils units
2121
shell: bash
2222

2323
- name: Run pimod OpenWRT example

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ FROM debian:bookworm-slim
22

33
LABEL description="Reconfigure Raspberry Pi images with an easy, Docker-like configuration file"
44
LABEL maintainer="[email protected]"
5-
LABEL version="0.6.1"
5+
LABEL version="0.7.0"
66

77
RUN bash
88

99
RUN apt-get update && \
1010
apt-get install -y \
1111
binfmt-support \
12+
exfatprogs \
1213
fdisk \
1314
file \
1415
git \

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ sudo apt-get install \
9494
kpartx \
9595
lsof \
9696
p7zip-full \
97-
qemu \
9897
qemu-user-static \
9998
unzip \
10099
wget \
@@ -198,6 +197,9 @@ This is an alternative to `FROM` and `TO`.
198197
##### `PUMP SIZE`
199198
`PUMP` increases the image's size about the given amount (suffixes K, M, G are allowed).
200199

200+
##### `ADDPART SIZE PTYPE FS`
201+
`PUMP` appends a partition of the size (suffixes K, M, G are allowed) using a partion type and file system (ext4, exfat, ...).
202+
201203
#### 3. Chroot Stage
202204
##### `INSTALL <MODE> SOURCE DEST`
203205
`INSTALL` installs a given file or directory into the destination in the image.

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ runs:
1414
steps:
1515
- run: sudo apt-get update
1616
shell: bash
17-
- run: sudo apt-get install -y binfmt-support fdisk file git kpartx qemu qemu-user-static unzip p7zip-full wget xz-utils units
17+
- run: sudo apt-get install -y binfmt-support exfatprogs fdisk file git kpartx qemu-user-static unzip p7zip-full wget xz-utils units
1818
shell: bash
1919
- run: sudo ${{ github.action_path }}/pimod.sh ${{ inputs.pifile }}
2020
shell: bash

stages/00-commands.sh

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ PUMP() {
4444
:
4545
}
4646

47+
ADDPART() {
48+
:
49+
}
50+
4751
# Stage 3x
4852
INSTALL() {
4953
:

stages/20-prepare.sh

+60
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,63 @@ PUMP() {
4242

4343
umount_image "${loop}"
4444
}
45+
46+
# ADDPART adds a partition of a given size, partition type and file system
47+
#
48+
# Usage: ADDPART SIZE PTYPE FS
49+
ADDPART() {
50+
if [ $# -ne 3 ]; then
51+
echo -e "\033[0;31m### Error: usage ADDPART SIZE PTYPE FS\033[0m"
52+
return 1
53+
fi
54+
55+
echo -e "\033[0;32m### ADDPART ${1} ${2} ${3}\033[0m"
56+
57+
if [[ -b "${DEST_IMG}" ]]; then
58+
echo -e "\033[0;31m### Error: Block device ${DEST_IMG} cannot be altered.\033[0m"
59+
return 1
60+
fi
61+
62+
BS="1M"
63+
64+
# units does not print to stderr, thus test call before using output
65+
echo -n "addpart conversion to ${BS} * "
66+
units -t "${1}B" "${BS}B"
67+
68+
COUNT=$(units -t ${1}B ${BS}B)
69+
70+
# Ceil the number if a decimal is given.
71+
if [[ "${COUNT}" == *.* ]]; then
72+
COUNT=$(( $(echo "${COUNT}" | cut -d. -f1) + 1 ))
73+
fi
74+
75+
echo "addpart ceil: ${BS} * ${COUNT}"
76+
77+
# Error on unset PTYPE
78+
if [[ -z ${2+x} ]]; then
79+
echo -e "\033[0;31m### Error: Partition type unspecified, possible options:\033[0m"
80+
sfdisk -T
81+
return 1
82+
fi
83+
84+
echo "checking mkfs.${3}"
85+
86+
if ! command -v mkfs.${3}; then
87+
echo -e "\033[0;31m### Error: file system ${3} is not available.\033[0m"
88+
return 1
89+
fi
90+
91+
dd if=/dev/zero bs="${BS}" count="${COUNT}" >> "${DEST_IMG}"
92+
93+
local data_part_start
94+
data_part_start=$(( $(sfdisk -l "${DEST_IMG}" -o END -n | tail -n1) + 1 ))
95+
96+
echo "$data_part_start,+,${2}" | sfdisk -a "${DEST_IMG}"
97+
98+
local loop
99+
loop=$(mount_image "${DEST_IMG}")
100+
101+
mkfs.${3} "/dev/mapper/${loop}p$((IMG_ROOT + 1))"
102+
103+
umount_image "${loop}"
104+
}

0 commit comments

Comments
 (0)