Skip to content

Instantly share code, notes, and snippets.

@YOU54F
Created October 4, 2023 14:42
Show Gist options
  • Save YOU54F/47e221be45eb0dcde6afb1fe8e161e4a to your computer and use it in GitHub Desktop.
Save YOU54F/47e221be45eb0dcde6afb1fe8e161e4a to your computer and use it in GitHub Desktop.
Parallels VM Manager - helps list, snapshot and show details about a machine
#!/bin/bash
name=$(basename $0)
prlctl list --info "${1}" > /dev/null
if [ "$?" -eq 0 ] ; then
os="$1"
id=$(prlctl snapshot-list "${os}" | grep -oE '\*{.*\}' | tr -d '*{}')
action="$2"
snapshots=( $(prlctl snapshot-list "${os}" -t | tr -d '}_\\* \n' | sed -e 's/^{//' -e 'y/{/ /') )
case "$action" in
"up" | "on" | "start" )
prlctl start "${os}"
;;
"down" | "off" | "stop" )
prlctl stop "${os}"
;;
"reset" )
prlctl reset "${os}"
;;
"list" )
for ((i = $((${#snapshots[*]} - 1)); i >= 0; i--)) ; do
ss_id_s=$(echo ${snapshots[$i]} | sed 's/-.*$//')
ss_id_f=$(echo ${snapshots[$i]} | cut -b1-36)
ss_info=$(prlctl snapshot-list ${os} -i ${ss_id_f})
ss_date=$(echo "$ss_info" | grep 'Date:' | sed 's/Date://')
ss_name=$(echo "$ss_info" | grep 'Name:' | sed 's/Name://')
echo $((i + 1)): $ss_id_s $ss_date $ss_name
done
;;
"save" )
if [ "$#" -ge 3 ] ; then
echo $3
prlctl snapshot "${os}" -n $3
else
prlctl snapshot "${os}"
fi
;;
"delete" )
if [ "$#" -ge 3 ] ; then
n=$((${3} - 1))
if [ ${snapshots[$n]} ] ; then
ss_id_f=$(echo ${snapshots[$n]} | cut -b1-36)
echo -e "\n********************WARNING********************\n"
echo -e "You're about to delete the following snapshot:\n"
prlctl snapshot-list "${os}" -i "${ss_id_f}"
echo "If you like, press y (y/n)."
read ans;
case "$ans" in
"y" )
prlctl snapshot-delete "${os}" -i "${ss_id_f}"
;;
* )
echo "Aborted."
;;
esac
else
echo "$name: Invalid snapshot number -- $n"
fi
fi
;;
"back" )
if [ "${id}" ] ; then
prlctl snapshot-switch "${os}" -i "${id}"
else
echo "Couldn't find the snapshot."
fi
;;
"info" | "show" )
prlctl list --info "${os}"
;;
"" )
prlctl list -a
;;
* )
echo "$name: Unknown option -- $action"
;;
esac
else
echo ""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment