mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-22 12:35:13 +00:00
fix to tomb resize
also included into test script
This commit is contained in:
parent
8f9e9f9d2a
commit
bc3177141d
@ -1,48 +1,46 @@
|
||||
#/usr/bin/env zsh
|
||||
#!/usr/bin/zsh
|
||||
|
||||
T="../../tomb"
|
||||
source utils.sh
|
||||
source ${T} source
|
||||
|
||||
notice() { print; yes "${@}"; print; }
|
||||
error() { _warning " ${@}"; }
|
||||
tt() {
|
||||
start_loops=(`sudo losetup -a |cut -d: -f1`)
|
||||
${T} ${=@}
|
||||
res=$?
|
||||
loops=(`sudo losetup -a |cut -d: -f1`)
|
||||
{ test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" }
|
||||
print " Tomb command returns $res"
|
||||
return $res
|
||||
}
|
||||
|
||||
|
||||
|
||||
rm /tmp/test.tomb{,.key} -f || exit 1
|
||||
|
||||
sudo -k
|
||||
notice "Testing creation"
|
||||
|
||||
${T} dig -s 10 /tmp/test.tomb
|
||||
tt dig -s 10 /tmp/test.tomb
|
||||
|
||||
sudo losetup -a
|
||||
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key
|
||||
|
||||
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom \
|
||||
forge /tmp/test.tomb.key
|
||||
|
||||
sudo losetup -a
|
||||
|
||||
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za \
|
||||
lock /tmp/test.tomb -k /tmp/test.tomb.key
|
||||
|
||||
sudo losetup -a
|
||||
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key
|
||||
|
||||
# sanity_tomb /tmp/asd.tomb
|
||||
echo
|
||||
echo trying to open with wrong password
|
||||
echo
|
||||
notice "Testing open with wrong password"
|
||||
|
||||
${T} --unsecure-dev-mode --tomb-pwd wrongpassword \
|
||||
open /tmp/test.tomb
|
||||
tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb
|
||||
|
||||
sudo losetup -a
|
||||
notice "Testing open with good password"
|
||||
|
||||
echo
|
||||
echo trying to open with good password
|
||||
echo
|
||||
tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
|
||||
|
||||
${T} --unsecure-dev-mode --tomb-pwd f00za \
|
||||
open /tmp/test.tomb
|
||||
tt --unsecure-dev-mode close test
|
||||
|
||||
sudo losetup -a
|
||||
|
||||
${T} --unsecure-dev-mode close test
|
||||
|
||||
sudo losetup -a
|
||||
|
||||
rm /tmp/test.tomb{,.key} -f || exit 1
|
||||
notice "Testing resize to 20MiB"
|
||||
tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 20
|
||||
|
||||
# rm /tmp/test.tomb{,.key} -f || exit 1
|
||||
|
17
tomb
17
tomb
@ -1648,7 +1648,7 @@ resize_tomb() {
|
||||
|
||||
local tmp_resize=`safe_filename tmbrsz`
|
||||
local newtombsize=$opts[-s]
|
||||
local oldtombsize=`stat -c %s "$1" 2>/dev/null`
|
||||
local oldtombsize=$(( `stat -c %s "$1" 2>/dev/null` / 1048576 ))
|
||||
local mounted_tomb=`mount -l |
|
||||
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'`
|
||||
|
||||
@ -1656,9 +1656,6 @@ resize_tomb() {
|
||||
_failure "the tomb $tombname is open, to resize it it needs to be close."
|
||||
fi
|
||||
|
||||
# MB to bytes conversion
|
||||
newtombsize=`expr \( $newtombsize \* 1024 \) \* 1024 2> /dev/null`
|
||||
|
||||
if ! [ "$newtombsize" ] ; then
|
||||
_failure "You must specify the new size of $tombname"
|
||||
elif [[ $newtombsize != <-> ]]; then
|
||||
@ -1667,12 +1664,12 @@ resize_tomb() {
|
||||
_failure "the new size must be greater then old tomb size."
|
||||
fi
|
||||
|
||||
local delta=`expr $newtombsize \- $oldtombsize`
|
||||
delta="$(( $newtombsize - $oldtombsize ))"
|
||||
|
||||
act "Generating ${tombfile} of ${newtombsize}MiB"
|
||||
|
||||
xxx "Data dump using ${DD[1]} from /dev/urandom"
|
||||
${=DD} if=/dev/urandom bs=1048576 count=${tombsize} of="${tmp_resize}"
|
||||
${=DD} if=/dev/urandom bs=1048576 count=${delta} of="${tmp_resize}"
|
||||
|
||||
if [ $? = 0 -a -e "${tmp_resize}" ]; then
|
||||
xxx "OK: `ls -lh ${tmp_resize}`"
|
||||
@ -1680,8 +1677,8 @@ resize_tomb() {
|
||||
_failure "Error creating the extra resize $tmp_resize, operation aborted."
|
||||
fi
|
||||
|
||||
cat "${tmp_resize}" >> "$1"
|
||||
${=WIPE} "${tmp_resize}"
|
||||
cat "${tmp_resize}" >> ${tombdir}/${tombfile}
|
||||
rm "${tmp_resize}"
|
||||
|
||||
|
||||
tombpass=`ask_key_password $tombkey`
|
||||
@ -1693,7 +1690,7 @@ resize_tomb() {
|
||||
_failure "too many tomb opened. Please close any of them to open another tomb"
|
||||
fi
|
||||
|
||||
losetup -f "$1"
|
||||
losetup -f ${tombdir}/${tombfile}
|
||||
|
||||
local mapdate=`date +%s`
|
||||
local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`"
|
||||
@ -1919,7 +1916,7 @@ main() {
|
||||
subcommands_opts[askpass]=""
|
||||
subcommands_opts[mktemp]=""
|
||||
subcommands_opts[source]=""
|
||||
subcommands_opts[resize]="s: -size=s k: -key=k"
|
||||
subcommands_opts[resize]="f -force -ignore-swap s: -size=s k: -key=k -tomb-pwd:"
|
||||
subcommands_opts[check]="-ignore-swap"
|
||||
# subcommands_opts[translate]=""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user