From 4cfedbe892f38a43be63a2ffcb0301f9170a7ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Ho=CC=88chst?= Date: Thu, 4 Nov 2021 14:44:12 +0100 Subject: [PATCH] fixed limitedness of PUMP command (closes #40) PUMP was implemented using dd's bs, which is limited to 2GB. In this fix the bs is set to fixed 1MB and the block count is calculated and ceiled. Caveat: Fractions of the block size can not be realized using this method, but should be not a real problem. --- .github/workflows/tests.yml | 2 +- Dockerfile | 3 ++- action.yml | 2 +- stages/20-prepare.sh | 20 ++++++++++++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4aeb1da..2599b21 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: submodules: recursive - name: Install dependencies - run: sudo apt-get update && sudo apt-get install -y binfmt-support file kpartx lsof p7zip-full parted qemu qemu-user-static unzip wget xz-utils + run: sudo apt-get update && sudo apt-get install -y binfmt-support file kpartx lsof p7zip-full parted qemu qemu-user-static unzip wget xz-utils units shell: bash - name: Run pimod OpenWRT example diff --git a/Dockerfile b/Dockerfile index 79b4209..e0ca829 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,8 @@ RUN apt-get update && \ qemu-user-static \ unzip \ wget \ - xz-utils + xz-utils \ + units RUN mkdir /pimod COPY . /pimod/ diff --git a/action.yml b/action.yml index 119b2d0..98752e2 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ runs: steps: - run: sudo apt-get update shell: bash - - run: sudo apt-get install -y binfmt-support file kpartx parted qemu qemu-user-static unzip p7zip-full wget xz-utils + - run: sudo apt-get install -y binfmt-support file kpartx parted qemu qemu-user-static unzip p7zip-full wget xz-utils units shell: bash - run: sudo ${{ github.action_path }}/pimod.sh ${{ inputs.pifile }} shell: bash diff --git a/stages/20-prepare.sh b/stages/20-prepare.sh index f4cef4a..35a36cd 100644 --- a/stages/20-prepare.sh +++ b/stages/20-prepare.sh @@ -1,6 +1,6 @@ # PUMP increases the image's size about the given amount of megabytes. # -# Usage: PUMP SIZE_IN_MB +# Usage: PUMP SIZE PUMP() { if [[ -b "${DEST_IMG}" ]]; then echo -e "\033[0;31m### Error: Block device ${DEST_IMG} cannot be pumped.\033[0m" @@ -8,7 +8,23 @@ PUMP() { fi echo -e "\033[0;32m### PUMP ${1}\033[0m" - dd if=/dev/zero bs="${1}" count=1 >> "${DEST_IMG}" + + BS="1M" + + # units does not print to stderr, thus test call before using output + echo -n "pump conversion to ${BS} * " + units -t "${1}B" "${BS}B" + + COUNT=$(units -t ${1}B ${BS}B) + + # Ceil the number if a decimal is given. + if [[ "${COUNT}" == *.* ]]; then + COUNT=$(( $(echo "${COUNT}" | cut -d. -f1) + 1 )) + fi + + echo "pump ceil: ${BS} * ${COUNT}" + + dd if=/dev/zero bs="${BS}" count="${COUNT}" >> "${DEST_IMG}" # Fix the GPT if necessary and resize the partition afterwards. # The fix is currently kind of hackish..