aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2018-05-08 08:00:20 +0200
committerGerd Hoffmann <kraxel@redhat.com>2018-05-08 08:00:20 +0200
commitf145606b6beb33c12d8c45ebbdd5ca8d6c5c33bd (patch)
treed7349c8be728449077d2df05f91e753595a4ba96 /scripts
parent4b8a19d3220c92c14f64561d35af8548a72e344d (diff)
downloadimagefish-f145606b6beb33c12d8c45ebbdd5ca8d6c5c33bd.tar.gz
add forgotton files
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/create-testimage.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/create-testimage.sh b/scripts/create-testimage.sh
new file mode 100755
index 0000000..768d052
--- /dev/null
+++ b/scripts/create-testimage.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# args
+qcow="${1-testimage.qcow2}"
+name="${2-testimage}"
+size="${3-1G}"
+
+function msg() {
+ local txt="$1"
+ local bold="\x1b[1m"
+ local normal="\x1b[0m"
+ echo -e "${bold}### ${txt}${normal}"
+}
+
+######################################################################
+# guestfish script helpers
+
+function fish() {
+ echo "#" "$@"
+ guestfish --remote -- "$@" || exit 1
+}
+
+function fish_init() {
+ local format
+
+ case "$qcow" in
+ *.raw) format="raw" ;;
+ *) format="qcow2";;
+ esac
+
+ msg "creating and adding disk image"
+ fish disk-create $qcow $format $size
+ fish add $qcow
+ fish run
+}
+
+function fish_format() {
+ local label="$1"
+
+ msg "creating partition"
+ fish part-init /dev/sda mbr
+ fish part-add /dev/sda p 2048 -2048
+ fish part-set-mbr-id /dev/sda 1 0x0c
+
+ msg "creating filesystem"
+ fish mkfs fat /dev/sda1 "label:$label"
+}
+
+function fish_fini() {
+ fish umount-all
+}
+
+######################################################################
+# go!
+
+#export LIBGUESTFS_BACKEND=direct
+eval $(guestfish --listen)
+if test "$GUESTFISH_PID" = ""; then
+ echo "ERROR: starting guestfish failed"
+ exit 1
+fi
+
+rm -f "$qcow"
+fish_init
+fish_format "$name"
+fish_fini
+msg "all done."