summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-12-07 12:13:53 +0200
committerLars Wirzenius <liw@liw.fi>2019-12-07 12:13:53 +0200
commit75063303533f106db8ceec7f9a25ed746a4ae103 (patch)
tree70d6428f4f66a6f7e50a4e3e9ee8d1dddf4f3bd8 /create-vm
parent3607b16668245cd9f7ee1746c3979f51ed8994c0 (diff)
downloadansibleness-75063303533f106db8ceec7f9a25ed746a4ae103.tar.gz
Change: allow create-vm handle uncomprssed image input files
Diffstat (limited to 'create-vm')
-rwxr-xr-xcreate-vm33
1 files changed, 28 insertions, 5 deletions
diff --git a/create-vm b/create-vm
index 3f7535c..b8ed1ad 100755
--- a/create-vm
+++ b/create-vm
@@ -36,6 +36,11 @@ xz_uncompressed_size()
xz --robot --verbose --list "$1" | awk '/^file/ { print $5 }'
}
+raw_uncompressed_size()
+{
+ stat -c %s "$1"
+}
+
# Check parameters.
@@ -66,8 +71,20 @@ then
fi
verbose "$basepath exists"
+# Is base image compressed?
+case "$basepath" in
+ *.xz) xz=true ;;
+ *) xz=false ;;
+esac
+
+
# How large is the (uncompressed) image? In bytes.
-size="$(xz_uncompressed_size "$basepath")"
+if $xz
+then
+ size="$(xz_uncompressed_size "$basepath")"
+else
+ size="$(raw_uncompressed_size "$basepath")"
+fi
verbose "Image is $size bytes"
# Create new LV.
@@ -79,10 +96,16 @@ verbose "lvpath=$lvpath"
#sudo lvchange -ay "$lvpath"
# Copy uncompressed image to LV.
-verbose "Uncompressing and copying image to LV"
-unxz < "$basepath" |
- pv --size "$size" |
- sudo ionice -c3 tee "$lvpath" > /dev/null
+if $xz
+then
+ verbose "Uncompressing and copying image to LV"
+ unxz < "$basepath" |
+ pv --size "$size" |
+ sudo ionice -c3 tee "$lvpath" > /dev/null
+else
+ pv "$basepath" |
+ sudo ionice -c3 tee "$lvpath" > /dev/null
+fi
# Edit /etc/hostname
verbose "Set hostname on new system to $name"