Created
April 26, 2013 09:03
-
-
Save ikait/53abfee6bb7bc214c080 to your computer and use it in GitHub Desktop.
Parallels をわりと簡単にコマンドから使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" | |
;; | |
* ) | |
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