Skip to content

Commit

Permalink
New upstream version 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
chodak166 committed Apr 6, 2021
1 parent 126f3de commit 7f9b7fc
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ sudo apt-get update
sudo apt-get install ddarch
```

Note: on Ubuntu 16.04 (Xenial) with buggy `software-properties-common` use:

```
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:chodak166/ppa
```

## Manual installation

The very minimum you truly need is to place the `ddarch` file from this repository in any of your `$PATH` directories (e.g. `/usr/bin`). Don't forget to make sure you have all [dependencies](#dependencies) installed.
Expand Down
4 changes: 2 additions & 2 deletions ddarch
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

SCRIPT_NAME=ddarch
SCRIPT_FILENAME=$(basename "$0")
SCRIPT_VERSION=0.1.4
SCRIPT_VERSION=0.1.5
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

set -e # exit on command errors (so you MUST handle exit codes properly!)
Expand Down Expand Up @@ -627,7 +627,7 @@ shrinkLastPartition() #EXPFUN [image] [tail size]
loDevice=$(losetup -f)

execCmd losetup -o $offsetBytes $loDevice "$image"
execCmd e2fsck -y -f $loDevice
execCmd 'e2fsck -y -f $loDevice ||:'

local blockSize=$(getBlockSize $loDevice)
local minBlocks=$(estimateBlocksAfterShrink $loDevice)
Expand Down
4 changes: 2 additions & 2 deletions man/ddarch.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.6.
.TH DDARCH "1" "March 2021" "ddarch 0.1.3" "User Commands"
.TH DDARCH "1" "April 2021" "ddarch 0.1.5" "User Commands"
.SH NAME
ddarch \- archive & restore utility for dd disk images
.SH SYNOPSIS
Expand All @@ -12,7 +12,7 @@ ddarch \- archive & restore utility for dd disk images
.B ddarch
\fI\,restore \/\fR[\fI\,options\/\fR]
.SH DESCRIPTION
ddarch 0.1.3
ddarch 0.1.5
.PP
ddarch is a simple helper tool that wraps multiple disk image management utilities to easily create, preserve and restore disk images.
.PP
Expand Down
39 changes: 30 additions & 9 deletions tests/ddarch_test
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
set -e
#set -x && PS4='- Line ${LINENO}: '

DDARCH_PATH=$(readlink -e ../ddarch)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DDARCH_PATH=$(readlink -e "${DIR}/../ddarch")

cd "$DIR"

. "$DDARCH_PATH"
. ddarch_test_helpers.shlib
. test.shlib


# ---------- function tests ------------

test_lastPartitionOffset()
Expand Down Expand Up @@ -153,7 +155,7 @@ test_cliArchiveMinimalMbr()
setupTestFiles
local inputAbsolutePath=$(readlink -e $TEST_MBR_PRI_IMAGE)
pushd $TEST_TMP_DIR >/dev/null
"$DDARCH_PATH" --input $inputAbsolutePath --quiet
"$DDARCH_PATH" --yes --input $inputAbsolutePath --quiet
popd >/dev/null

local output=$TEST_TMP_DIR/$(date +%Y-%m-%d)-image.img.7z
Expand All @@ -170,7 +172,7 @@ test_cliArchiveExplicitOutputZip()
setupTestFiles
local output=$TEST_TMP_DIR/gpt_pri_out.zip

"$DDARCH_PATH" archive --input $TEST_GPT_PRI_IMAGE \
"$DDARCH_PATH" archive --yes --input $TEST_GPT_PRI_IMAGE \
--output $output \
--arch-type zip \
--quiet
Expand All @@ -189,7 +191,7 @@ test_cliArchiveEmptyWorkDir()
local output=$TEST_TMP_DIR/gpt_pri_out.img
local workDir=$TEST_TMP_DIR/empty_work_dir

"$DDARCH_PATH" archive --input $TEST_GPT_PRI_IMAGE \
"$DDARCH_PATH" archive --yes --input $TEST_GPT_PRI_IMAGE \
--output $output \
--arch-type none \
--work-dir $workDir \
Expand All @@ -209,7 +211,7 @@ test_cliArchiveNonEmptyWorkDir()
mkdir -p $workDir
touch $foreignFile

"$DDARCH_PATH" archive --input $TEST_GPT_PRI_IMAGE \
"$DDARCH_PATH" archive --yes --input $TEST_GPT_PRI_IMAGE \
--output $output \
--arch-type none \
--work-dir $workDir \
Expand All @@ -228,7 +230,7 @@ test_cliArchiveMbrDevice()
output=$TEST_TMP_DIR/mbrdevice.img
loDevice=$(losetup --show -f $TEST_MBR_PRI_IMAGE)

"$DDARCH_PATH" archive --input $loDevice -a none --output $output --quiet
"$DDARCH_PATH" archive --yes --input $loDevice -a none --output $output --quiet

losetup -d $loDevice

Expand All @@ -249,7 +251,7 @@ test_cliArchiveInPlaceNoCompressNoOutput()
local inputSizeBefore=$(stat --printf="%s" $input)


"$DDARCH_PATH" archive --input $input \
"$DDARCH_PATH" archive --yes --input $input \
--output $output \
--arch-type none \
--in-place \
Expand All @@ -270,7 +272,7 @@ test_cliArchiveInPlaceTarGzOutput()

local inputSizeBefore=$(stat --printf="%s" $input)

"$DDARCH_PATH" archive --input $input \
"$DDARCH_PATH" archive --yes --input $input \
--output $output \
--arch-type tgz \
--in-place \
Expand All @@ -283,6 +285,25 @@ test_cliArchiveInPlaceTarGzOutput()
assertEqual $mimeType "application/gzip" "The output file MIME type should be application/gzip"
}

test_cliArchiveCorruptedMbr()
{
setupTestFiles
local inputAbsolutePath=$(readlink -e $TEST_MBR_PRI_IMAGE)
corruptLastPartition $TEST_MBR_PRI_IMAGE

pushd $TEST_TMP_DIR >/dev/null
"$DDARCH_PATH" --yes --input $inputAbsolutePath --yes --quiet
popd >/dev/null

local output=$TEST_TMP_DIR/$(date +%Y-%m-%d)-image.img.7z
local mimeType=$(getMimeType $output)
local inputSize=$(stat --printf="%s" $TEST_MBR_PRI_IMAGE)
local outputSize=$(stat --printf="%s" $output)

assertEqual $mimeType "application/x-7z-compressed" "Archived output MIME type should be application/x-7z-compressed"
assertGreater $inputSize $outputSize "The input size should be greater than the output size"
}

test_cliRestoreMbrImage()
{
setupTestFiles
Expand Down
21 changes: 18 additions & 3 deletions tests/ddarch_test_helpers.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ setupTestFiles()
else
head -c 1M /dev/urandom > $TEST_BIN_FILE
createMbrPriTestImage $TEST_MBR_PRI_IMAGE
formatAndPlaceTEST_BIN_FILE $TEST_MBR_PRI_IMAGE
formatAndPlaceTestFile $TEST_MBR_PRI_IMAGE

createGptPriTestImage $TEST_GPT_PRI_IMAGE
formatAndPlaceTEST_BIN_FILE $TEST_GPT_PRI_IMAGE
formatAndPlaceTestFile $TEST_GPT_PRI_IMAGE

createMbrExtTestImage $TEST_MBR_EXT_IMAGE

Expand Down Expand Up @@ -93,7 +93,7 @@ createGptPriTestImage()
parted -a optimal --script "$imgFile" mkpart primary ext4 3MiB 8MiB
}

formatAndPlaceTEST_BIN_FILE()
formatAndPlaceTestFile()
{
local imgFile="$1"
local loDevice=$(losetup -f)
Expand All @@ -113,3 +113,18 @@ formatAndPlaceTEST_BIN_FILE()

fdisk -lu "$imgFile"
}

corruptLastPartition()
{
local imgFile="$1"
local offset=$(sfdisk -l "$imgFile" -o Start | tail -n 1)
local loDevice=$(losetup -f --show --offset $((512*$offset)) "$imgFile")

debugfs -w -R 'write /dev/null bad_file' $loDevice
debugfs -w -R 'clri bad_file' $loDevice
mount $loDevice $TEST_MNT_DIR
ls -sF $TEST_MNT_DIR 2>/dev/null ||:

umount $TEST_MNT_DIR
losetup -d $loDevice
}

0 comments on commit 7f9b7fc

Please sign in to comment.