1 # Hey Emacs, this is a -*- shell-script -*- !!!
3 # This file provides functions to implement access/update of disk
4 # images via guestfish.
6 ######################################################################
8 diskimage_mount_guestfish ()
10 echo "Using guestfish to update disk image ${disk}..."
14 for m in $SYSTEM_DISK_MOUNTS ; do
15 d="${m#*:}" # Device is after colon
16 m="${m%:*}" # Mountpoint is before colon
17 mount_args="${mount_args}${mount_args:+ } --mount ${d}:${m}"
18 echo " mount ${m} from device ${d} configured"
21 eval $(guestfish --listen -a "$1" $mount_args)
23 guestfish --remote ping-daemon || \
24 die "Failed to initialise guestfish session"
26 diskimage is_directory "/root" || {
27 echo "Mounted directory does not look like a root filesystem"
28 guestfish --remote ll /
32 echo $GUESTFISH_PID > tmp/guestfish.pid
33 echo "To attach to guestfish image"
34 echo " export GUESTFISH_PID=$GUESTFISH_PID"
35 echo " guestfish --remote"
38 # unmount a qemu image
39 diskimage_unmount_guestfish ()
41 read GUESTFISH_PID < tmp/guestfish.pid
44 echo "Unmounting disk"
45 guestfish --remote sync
46 guestfish --remote exit
49 diskimage_mkdir_p_guestfish ()
51 local t=$(guestfish --remote is-dir "$1/.")
52 if [ "$t" = "false" ] ; then
53 guestfish --remote mkdir-p "$1"
57 diskimage_substitute_vars_guestfish ()
60 substitute_vars "$1" "$t"
61 guestfish --remote upload "$t" "$2"
65 diskimage_chmod_guestfish ()
67 local mode="$1" ; shift
69 # For guestfish, octal mode must start with '0'.
72 (*) mode="0${mode}" ;;
77 guestfish --remote glob chmod "$mode" "$i"
81 diskimage_chmod_reference_guestfish ()
83 local mode=$(printf "%o\n" $(( 0x$(stat -c "%f" "$1") )) )
89 guestfish --remote glob chmod "$mode" "$i"
93 diskimage_is_file_guestfish ()
95 local t=$(guestfish --remote is-file "$1")
99 diskimage_is_directory_guestfish ()
101 local t=$(guestfish --remote is-dir "$1/.")
105 diskimage_append_text_file_guestfish ()
108 guestfish --remote download "$2" "$t"
110 guestfish --remote upload "$t" "$2"
114 diskimage_append_text_guestfish ()
117 guestfish --remote download "$2" "$t"
119 guestfish --remote upload "$t" "$2"
123 diskimage_sed_guestfish ()
125 local file="$1" ; shift
128 guestfish --remote download "$file" "$t"
130 guestfish --remote upload "$t" "$file"
134 diskimage_grep_guestfish ()
136 local file="$1" ; shift
138 # guestfish's grep doesn't support options like -f, so don't use it.
141 guestfish --remote download "$file" "$t"
149 diskimage_put_guestfish ()
151 guestfish --remote upload "$1" "$2"
154 diskimage_ln_s_guestfish ()
156 guestfish --remote ln-s "$1" "$2"
159 diskimage_command_guestfish ()
161 # Yes, I mean "$*" and not "$@". The command passed must be a
162 # single string... and, yes, quoting is lost.
163 guestfish --remote command "$*"
166 diskimage_mv_guestfish ()
168 guestfish --remote mv "$1" "$2"
171 diskimage_rm_f_guestfish ()
173 if diskimage_is_file_guestfish "$1" ; then
174 guestfish --remote rm "$1"
178 ######################################################################
180 diskimage_guestfish_sanity_check ()
182 if [ "$SYSTEM_DISK_ACCESS_METHOD" = "guestfish" ] ; then
183 check_command guestfish
187 register_hook post_config_hooks diskimage_guestfish_sanity_check