Skip to content

Commit

Permalink
ternarytest.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
KathrynMorgan committed Feb 20, 2018
1 parent 0e19bd2 commit 76962b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 15 additions & 6 deletions img-convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ discard_DIR=/tmp/libvirt/images/

# Enable or disable compression during qcow2 conversion to save additional space
# Notice: takes longer and has slight impact on performance
if [[ $compress_SWITCH = "true" ]]; then
compress_IMG="-c"
elif [[ $compress_SWITCH = "false" ]]; then
compress_IMG=""
fi
[[ $compress_SWITCH ]] && compress_IMG="-c" || compress_IMG=""
#if [[ $compress_SWITCH = "true" ]]; then
# compress_IMG="-c"
#elif [[ $compress_SWITCH = "false" ]]; then
# compress_IMG=""
#fi

#################################################################################
# Replace original disk image with new qcow2 format
Expand All @@ -73,10 +74,16 @@ image_replace () {
# Perform disk image file conversion
image_convert () {
echo " Converting $disk"
qemu-img convert -p $img_INPUT_TYPE -O qcow2 $compress_IMG $disk $disk.tmp
qemu-img convert \
-p $img_INPUT_TYPE \
-O qcow2 $compress_IMG $disk $disk.$temp_STAMP
echo "qcow2 conversion complete for $disk"
}

# Generate unique hash for temp file naming
gen_hash () {
temp_STAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.%N+00:00" | md5sum)
}
#################################################################################
# Find disk images
image_find () {
Expand Down Expand Up @@ -114,13 +121,15 @@ virsh_LIST_DOM=$(virsh list --name --all)
echo ">> Found RAW disk image file $disk"
echo ">> Converting to qcow2 format..."
img_INPUT_TYPE="-f raw"
gen_hash
image_convert
image_replace
elif [[ $image_TYPE_CHECK = "qcow2" ]] && \
[[ $convert_QCOW2 = "true" ]]; then
echo ">> Found QCOW2 disk image file $disk"
echo ">> Compressing with qcow2 format..."
img_INPUT_TYPE=""
gen_hash
image_convert
image_replace
fi
Expand Down
6 changes: 6 additions & 0 deletions ternarytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

compress_SWITCH="1"
[[ $compress_SWITCH ]] && compress_IMG="true" || compress_IMG="false"

echo "$compress_IMG"

0 comments on commit 76962b7

Please sign in to comment.