diff options
author | LAN-TW <lantw44@gmail.com> | 2012-08-18 23:49:36 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2012-08-18 23:49:36 +0800 |
commit | c97aae5a472eed886deb35a73493c7b611d9a39e (patch) | |
tree | fe143d4c4b690a0a477f5ef30ad41d395120439a | |
parent | 23d75b28069f40d859976cc934f5aa02aa2118af (diff) | |
download | xenstore-editor-c97aae5a472eed886deb35a73493c7b611d9a39e.tar.gz xenstore-editor-c97aae5a472eed886deb35a73493c7b611d9a39e.tar.zst xenstore-editor-c97aae5a472eed886deb35a73493c7b611d9a39e.zip |
Update - version 1.2v1.2
- 可用 DIALOG 環境變數更改要使用的 dialog 指定與參數
- 加入 XenStore Viewer,方便檢視 domain 資訊而不需要直接看 XenStore 的內容
-rw-r--r-- | change.log | 4 | ||||
-rwxr-xr-x | xenstore-editor-zh_TW.utf8.sh | 52 | ||||
-rwxr-xr-x | xenstore-editor.sh | 52 | ||||
-rwxr-xr-x | xenstore-viewer-zh_TW.utf8.sh | 170 | ||||
-rwxr-xr-x | xenstore-viewer.sh | 170 |
5 files changed, 406 insertions, 42 deletions
@@ -1,3 +1,7 @@ +* 2012-08-18 lantw44 <lantw44@www.tfcis.org> - 1.2 +- 可用 DIALOG 環境變數更改要使用的 dialog 指定與參數 +- 加入 XenStore Viewer,方便檢視 domain 資訊而不需要直接看 XenStore 的內容 + * 2012-06-11 lantw44 <lantw44@www.tfcis.org> - 1.1 - 修改數值的畫面加入「檔案瀏覽器」功能 - 如果項目的值是 XenStore 路徑,那麼在 Chdir 選單中會出現 UseValue 項目,允許使 diff --git a/xenstore-editor-zh_TW.utf8.sh b/xenstore-editor-zh_TW.utf8.sh index e1ba2e6..d83aeff 100755 --- a/xenstore-editor-zh_TW.utf8.sh +++ b/xenstore-editor-zh_TW.utf8.sh @@ -1,7 +1,7 @@ #!/bin/bash ### 名稱: Simple XenStore Editor -### 版本: 1.1 -### 發行日期: 2012-06-11 +### 版本: 1.2 +### 發行日期: 2012-08-18 [ "`id -u`" != "0" ] && echo "這個 script 必須以 root 身份執行。" && exit 40 @@ -16,9 +16,19 @@ first_run=1 setdefault=0 prevdir="$current" tmpfile=`mktemp` -scripttitle=" 簡易 XenStore 編輯工具 版本 1.1 " +scripttitle=" 簡易 XenStore 編輯工具 版本 1.2 " scriptshorttitle="簡易 XenStore 編輯工具" +if [ -z "$DIALOG" ]; then + for i in dialog cdialog + do + DIALOG=`which $i 2> /dev/null` + [ "$DIALOG" ] && break + done +fi + +[ -z "$DIALOG" ] && echo "在 PATH 中找不到必要的程式 dialog (可以嘗試用環境變數 DIALOG 來指定這個可執行檔的位置)" && exit 42 + function getxenfullpath () { if [ "$1" = "/" ] then @@ -32,7 +42,7 @@ function getusernewvalue () { local initvalue="$3" while true do - dialog --ascii-lines --title "$1" --extra-button --extra-label "檔案瀏覽器" --inputbox "$2" 0 0 "$initvalue" 2> "$tmpfile" + $DIALOG --title "$1" --extra-button --extra-label "檔案瀏覽器" --inputbox "$2" 0 0 "$initvalue" 2> "$tmpfile" local exitstat=$? case "$exitstat" in 0|1) @@ -46,12 +56,12 @@ function getusernewvalue () { local parentdir="`dirname "$nowvalue"`" if [ "`echo "$nowvalue" | cut -c 1`" != "/" ] || [ '!' -e "$parentdir" ] then - dialog --ascii-lines --title "檔案瀏覽器" --msgbox "$parentdir 目錄不存在" 0 0 + $DIALOG --title "檔案瀏覽器" --msgbox "$parentdir 目錄不存在" 0 0 initdir="`pwd`/" else initdir="$nowvalue" fi - dialog --ascii-lines --title "請用空白鍵來複製游標所在位置的檔案路徑" --fselect "$initdir" 13 75 2> "$tmpfile2" + $DIALOG --title "請用空白鍵來複製游標所在位置的檔案路徑" --fselect "$initdir" 13 75 2> "$tmpfile2" if [ "$?" = "0" ] then selectedfile="`cat "$tmpfile2"`" @@ -73,7 +83,7 @@ do unset j xenstore-list "$current" > "$tmpfile" if [ "$?" != "0" ]; then - dialog --ascii-lines --title "$scripttitle" --msgbox "無法從 $current 取得檔案清班" 0 0 + $DIALOG --title "$scripttitle" --msgbox "無法從 $current 取得檔案清班" 0 0 if [ "$first_run" != "0" ] then exit 1 @@ -104,9 +114,9 @@ do fi if [ "$setdefault" = "0" ] then - dialog --ascii-lines --title "$scripttitle" --ok-label "切換目錄" --cancel-label "離開" --extra-button --extra-label "編輯" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" + $DIALOG --title "$scripttitle" --ok-label "切換目錄" --cancel-label "離開" --extra-button --extra-label "編輯" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" else - dialog --ascii-lines --title "$scripttitle" --ok-label "切換目錄" --cancel-label "離開" --extra-button --extra-label "編輯" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" + $DIALOG --title "$scripttitle" --ok-label "切換目錄" --cancel-label "離開" --extra-button --extra-label "編輯" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" fi dialogexit=$? dialogout="`cat "$tmpfile"`" @@ -122,13 +132,13 @@ do [ "$?" = "0" ] && valuepathvalid=1 fi if [ "$dialogout" = "(Empty)" ]; then - dialog --ascii-lines --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Back" "進入 $ascending" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Back" "進入 $ascending" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" dialogexit=$? elif [ "$usevalue" ] && [ "$valuepathvalid" = "1" ]; then - dialog --ascii-lines --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Enter" "進入 $descending" "Back" "進入 $ascending" "UseValue" "進入 $usevalue" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Enter" "進入 $descending" "Back" "進入 $ascending" "UseValue" "進入 $usevalue" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" dialogexit=$? else - dialog --ascii-lines --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Enter" "進入 $descending" "Back" "進入 $ascending" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Enter" "進入 $descending" "Back" "進入 $ascending" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" dialogexit=$? fi if [ "$dialogexit" = "0" ] @@ -148,7 +158,7 @@ do current="$usevalue" ;; "Manual") - dialog --ascii-lines --title "$scriptshorttitle - 切換目錄 - Manual" --inputbox "XenStore 目錄名稱" 0 0 "$current" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 切換目錄 - Manual" --inputbox "XenStore 目錄名稱" 0 0 "$current" 2> "$tmpfile" if [ "$?" = "0" ] then prevdir="$current" @@ -165,7 +175,7 @@ do fi ;; 1) - if dialog --ascii-lines --title "$scriptshorttitle - 離開" --yesno "你確定要離開嗎?" 0 0 + if $DIALOG --title "$scriptshorttitle - 離開" --yesno "你確定要離開嗎?" 0 0 then should_exit=1 fi @@ -173,11 +183,11 @@ do 3) if [ "$dialogout" = "(Empty)" ] then - dialog --ascii-lines --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Add" "加入新值" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Add" "加入新值" 2> "$tmpfile" dialogexit=$? dialogout2="`cat "$tmpfile"`" else - dialog --ascii-lines --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Modify" "修改此值" "Remove" "刪除此值" "Add" "加入新值" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Modify" "修改此值" "Remove" "刪除此值" "Add" "加入新值" 2> "$tmpfile" dialogexit=$? dialogout2="`cat "$tmpfile"`" fi @@ -185,7 +195,7 @@ do then case "$dialogout2" in "Add") - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Add" --inputbox "名稱" 0 0 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - 編輯 - Add" --inputbox "名稱" 0 0 2> "$tmpfile" if [ "$?" = "0" ] then newname="`cat "$tmpfile"`" @@ -207,7 +217,7 @@ do outmsg="`xenstore-write "$fullpath" "$newvalue" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Add" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - 編輯 - Add" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" @@ -222,7 +232,7 @@ do outmsg="`xenstore-write "$fullpath" "$dialogout3" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Modify" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - 編輯 - Modify" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" @@ -234,12 +244,12 @@ do ;; "Remove") fullpath="`getxenfullpath "$current" "$dialogout"`" - if dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Remove" --yesno "你確定要刪除 $dialogout 嗎?" 0 0 + if $DIALOG --title "$scriptshorttitle - 編輯 - Remove" --yesno "你確定要刪除 $dialogout 嗎?" 0 0 then outmsg="`xenstore-rm "$fullpath" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Remove" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - 編輯 - Remove" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" diff --git a/xenstore-editor.sh b/xenstore-editor.sh index e44d302..1d5550a 100755 --- a/xenstore-editor.sh +++ b/xenstore-editor.sh @@ -1,7 +1,7 @@ #!/bin/bash ### Name: Simple XenStore Editor -### Version: 1.1 -### Release Date: 2012-06-11 +### Version: 1.2 +### Release Date: 2012-08-18 [ "`id -u`" != "0" ] && echo "This script should be run as root." && exit 40 @@ -16,9 +16,19 @@ first_run=1 setdefault=0 prevdir="$current" tmpfile=`mktemp` -scripttitle=" Simple XenStore Editor Version 1.1 " +scripttitle=" Simple XenStore Editor Version 1.2 " scriptshorttitle="Simple XenStore Editor" +if [ -z "$DIALOG" ]; then + for i in dialog cdialog + do + DIALOG=`which $i 2> /dev/null` + [ "$DIALOG" ] && break + done +fi + +[ -z "$DIALOG" ] && echo "A required program \`dialog' cannot be found in your PATH. (You can specify it by setting the environment variable DIALOG)" && exit 42 + function getxenfullpath () { if [ "$1" = "/" ] then @@ -32,7 +42,7 @@ function getusernewvalue () { local initvalue="$3" while true do - dialog --ascii-lines --title "$1" --extra-button --extra-label "File Browser" --inputbox "$2" 0 0 "$initvalue" 2> "$tmpfile" + $DIALOG --title "$1" --extra-button --extra-label "File Browser" --inputbox "$2" 0 0 "$initvalue" 2> "$tmpfile" local exitstat=$? case "$exitstat" in 0|1) @@ -46,12 +56,12 @@ function getusernewvalue () { local parentdir="`dirname "$nowvalue"`" if [ "`echo "$nowvalue" | cut -c 1`" != "/" ] || [ '!' -e "$parentdir" ] then - dialog --ascii-lines --title "File Browser" --msgbox "$parentdir directory does not exits" 0 0 + $DIALOG --title "File Browser" --msgbox "$parentdir directory does not exits" 0 0 initdir="`pwd`/" else initdir="$nowvalue" fi - dialog --ascii-lines --title "Use space-bar to copy the current selection" --fselect "$initdir" 13 75 2> "$tmpfile2" + $DIALOG --title "Use space-bar to copy the current selection" --fselect "$initdir" 13 75 2> "$tmpfile2" if [ "$?" = "0" ] then selectedfile="`cat "$tmpfile2"`" @@ -73,7 +83,7 @@ do unset j xenstore-list "$current" > "$tmpfile" if [ "$?" != "0" ]; then - dialog --ascii-lines --title "$scripttitle" --msgbox "Cannot list the directory $current" 0 0 + $DIALOG --title "$scripttitle" --msgbox "Cannot list the directory $current" 0 0 if [ "$first_run" != "0" ] then exit 1 @@ -104,9 +114,9 @@ do fi if [ "$setdefault" = "0" ] then - dialog --ascii-lines --title "$scripttitle" --ok-label "Chdir" --cancel-label "Exit" --extra-button --extra-label "Edit" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" + $DIALOG --title "$scripttitle" --ok-label "Chdir" --cancel-label "Exit" --extra-button --extra-label "Edit" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" else - dialog --ascii-lines --title "$scripttitle" --ok-label "Chdir" --cancel-label "Exit" --extra-button --extra-label "Edit" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" + $DIALOG --title "$scripttitle" --ok-label "Chdir" --cancel-label "Exit" --extra-button --extra-label "Edit" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" fi dialogexit=$? dialogout="`cat "$tmpfile"`" @@ -122,13 +132,13 @@ do [ "$?" = "0" ] && valuepathvalid=1 fi if [ "$dialogout" = "(Empty)" ]; then - dialog --ascii-lines --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Back" "Go to $ascending" "Manual" "Type a XenStore Path" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Back" "Go to $ascending" "Manual" "Type a XenStore Path" 2> "$tmpfile" dialogexit=$? elif [ "$usevalue" ] && [ "$valuepathvalid" = "1" ]; then - dialog --ascii-lines --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Enter" "Go to $descending" "Back" "Go to $ascending" "UseValue" "Go to $usevalue" "Manual" "Type a XenStore Path" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Enter" "Go to $descending" "Back" "Go to $ascending" "UseValue" "Go to $usevalue" "Manual" "Type a XenStore Path" 2> "$tmpfile" dialogexit=$? else - dialog --ascii-lines --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Enter" "Go to $descending" "Back" "Go to $ascending" "Manual" "Type a XenStore Path" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Chdir" --menu "Choose from the list" 0 0 0 "Enter" "Go to $descending" "Back" "Go to $ascending" "Manual" "Type a XenStore Path" 2> "$tmpfile" dialogexit=$? fi if [ "$dialogexit" = "0" ] @@ -148,7 +158,7 @@ do current="$usevalue" ;; "Manual") - dialog --ascii-lines --title "$scriptshorttitle - Chdir - Manual" --inputbox "XenStore Directory Name" 0 0 "$current" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Chdir - Manual" --inputbox "XenStore Directory Name" 0 0 "$current" 2> "$tmpfile" if [ "$?" = "0" ] then prevdir="$current" @@ -165,7 +175,7 @@ do fi ;; 1) - if dialog --ascii-lines --title "$scriptshorttitle - Exit" --yesno "Do you really want to quit?" 0 0 + if $DIALOG --title "$scriptshorttitle - Exit" --yesno "Do you really want to quit?" 0 0 then should_exit=1 fi @@ -173,11 +183,11 @@ do 3) if [ "$dialogout" = "(Empty)" ] then - dialog --ascii-lines --title "$scriptshorttitle - Edit" --menu "Choose from the list" 0 0 0 "Add" "Add a new value" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Edit" --menu "Choose from the list" 0 0 0 "Add" "Add a new value" 2> "$tmpfile" dialogexit=$? dialogout2="`cat "$tmpfile"`" else - dialog --ascii-lines --title "$scriptshorttitle - Edit" --menu "Choose from the list" 0 0 0 "Modify" "Modify this value" "Remove" "Remove this value" "Add" "Add a new value" 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Edit" --menu "Choose from the list" 0 0 0 "Modify" "Modify this value" "Remove" "Remove this value" "Add" "Add a new value" 2> "$tmpfile" dialogexit=$? dialogout2="`cat "$tmpfile"`" fi @@ -185,7 +195,7 @@ do then case "$dialogout2" in "Add") - dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --inputbox "Name" 0 0 2> "$tmpfile" + $DIALOG --title "$scriptshorttitle - Edit - Add" --inputbox "Name" 0 0 2> "$tmpfile" if [ "$?" = "0" ] then newname="`cat "$tmpfile"`" @@ -207,7 +217,7 @@ do outmsg="`xenstore-write "$fullpath" "$newvalue" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - Edit - Add" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" @@ -222,7 +232,7 @@ do outmsg="`xenstore-write "$fullpath" "$dialogout3" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - Edit - Modify" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - Edit - Modify" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" @@ -234,12 +244,12 @@ do ;; "Remove") fullpath="`getxenfullpath "$current" "$dialogout"`" - if dialog --ascii-lines --title "$scriptshorttitle - Edit - Remove" --yesno "Do you really want to delete the value $dialogout?" 0 0 + if $DIALOG --title "$scriptshorttitle - Edit - Remove" --yesno "Do you really want to delete the value $dialogout?" 0 0 then outmsg="`xenstore-rm "$fullpath" 2>&1`" if [ "$?" != "0" ] then - dialog --ascii-lines --title "$scriptshorttitle - Edit - Remove" --msgbox "$outmsg" 0 0 + $DIALOG --title "$scriptshorttitle - Edit - Remove" --msgbox "$outmsg" 0 0 else setdefault=1 setdefaultvalue="$dialogout" diff --git a/xenstore-viewer-zh_TW.utf8.sh b/xenstore-viewer-zh_TW.utf8.sh new file mode 100755 index 0000000..782c386 --- /dev/null +++ b/xenstore-viewer-zh_TW.utf8.sh @@ -0,0 +1,170 @@ +#!/bin/bash +### Name: Simple XenStore Viewer +### Version: 1.2 +### Release Date: 2012-08-17 + +function xenstoregetstatestr () { + case "$1" in + 1) + echo "正在初始化" + ;; + 2) + echo "等待初始化" + ;; + 3) + echo "已初始化" + ;; + 4) + echo "已連接" + ;; + 5) + echo "正在關閉" + ;; + 6) + echo "已關閉" + ;; + *) + echo "不明" + ;; + esac +} + +function xenstoregetinfo () { + case "$1" in + m|h|'?'|'') + echo " b 區塊裝置" + echo " c 主控台" + echo " n 網路介面卡" + echo " p 虛擬 CPU" + echo " r 記憶體" + ;; + b) + vbdpath="$xenstorepath/device/vbd" + for i in `xenstore-list $vbdpath` + do + echo "虛擬裝置名稱: $i" + echo "虛擬裝置類型: `xenstore-read $vbdpath/$i/device-type`" + echo "虛擬裝置狀態: `xenstoregetstatestr $(xenstore-read $vbdpath/$i/state)`" + vbdbackpath="`xenstore-read $vbdpath/$i/backend`" + echo "虛擬裝置後端名稱:`xenstore-read $vbdbackpath/dev`" + echo "虛擬裝置後端類型:`xenstore-read $vbdbackpath/type`" + echo "虛擬裝置後端參數:`xenstore-read $vbdbackpath/params`" + echo -n "其他資訊: " + case "`xenstore-read $vbdbackpath/online`" in + 0) + echo -n "離線" + ;; + 1) + echo -n "線上" + ;; + *) + echo -n "不明" + ;; + esac + case "`xenstore-read $vbdbackpath/removable`" in + 0) + echo -n "、不可卸除" + ;; + 1) + echo -n "、卸除式裝置" + ;; + *) + echo -n "、不明" + ;; + esac + case "`xenstore-read $vbdbackpath/bootable`" in + 0) + echo "、不可開機" + ;; + 1) + echo "、可開機" + ;; + *) + echo "、不明" + ;; + esac + echo "" + done + ;; + c) + conpath="$xenstorepath/console" + echo "Xen Console 後端 TTY: `xenstore-read $conpath/tty`" + echo "Xen Console 緩衝區大小限制:`xenstore-read $conpath/limit`" + echo "VNC 伺服器接聽於: `xenstore-read $conpath/vnc-listen`:`xenstore-read $conpath/vnc-port`" + echo "" + ;; + n) + vifpath="$xenstorepath/device/vif" + for i in `xenstore-list $vifpath` + do + echo "虛擬裝置名稱: $i" + echo "虛擬裝置狀態: `xenstoregetstatestr $(xenstore-read $vifpath/$i/state)`" + echo "虛擬網路介面卡 MAC 位址:`xenstore-read $vifpath/$i/mac`" + vifbackpath="`xenstore-read $vifpath/$i/backend`" + echo "橋接至: `xenstore-read $vifbackpath/bridge`" + echo "用來啟動/停止的 script: `xenstore-read $vifbackpath/script`" + echo "" + done + ;; + p) + cpupath="$xenstorepath/cpu" + for i in `xenstore-list $cpupath` + do + echo "CPU $i: `xenstore-read $cpupath/$i/availability`" + done + ;; + r) + mempath="$xenstorepath/memory" + echo "記憶體大小 :`xenstore-read $mempath/target`" + echo "記憶體大小上限:`xenstore-read $mempath/static-max`" + echo "視訊記憶體大小:`xenstore-read $mempath/videoram`" + ;; + *) + echo "不明的指令。請輸入 m 來查看說明。" + ;; + esac +} + +[ "`id -u`" != "0" ] && echo "這個 script 必須以 root 身份執行" && exit 40 + +if [ -z "$1" ] +then + read -p "請輸入 domain ID 或 domain 名稱:" xendominput +else + xendominput="$1" +fi + +[ -z "$xendominput" ] && echo "使用預設值 doamin 0" && xendominput=0 + +echo "正在搜尋 domain $xendominput ......" + +if xenstore-read /local/domain/$xendominput 1> /dev/null 2> /dev/null +then + xenstorepath="/local/domain/$xendominput" +else + for i in `xenstore-list /local/domain` + do + if [ "$xendominput" = "`xenstore-read /local/domain/$i/name 2> /dev/null`" ] + then + xenstorepath="/local/domain/$i" + break + fi + done +fi + +if [ -z "$xenstorepath" ] +then + echo "找不到 domain $xendominput" && exit 42 +else + echo "XenStore 路徑是 $xenstorepath" +fi + +if [ -z "$2" ] +then + while read -p "XSView>>> " infocmdinput + do + xenstoregetinfo "$infocmdinput" + done +else + xenstoregetinfo "$2" +fi diff --git a/xenstore-viewer.sh b/xenstore-viewer.sh new file mode 100755 index 0000000..6759bd6 --- /dev/null +++ b/xenstore-viewer.sh @@ -0,0 +1,170 @@ +#!/bin/bash +### Name: Simple XenStore Viewer +### Version: 1.2 +### Release Date: 2012-08-17 + +function xenstoregetstatestr () { + case "$1" in + 1) + echo "Initializing" + ;; + 2) + echo "Waiting for initializing" + ;; + 3) + echo "Initialized" + ;; + 4) + echo "Connected" + ;; + 5) + echo "Closing" + ;; + 6) + echo "Closed" + ;; + *) + echo "Unknown" + ;; + esac +} + +function xenstoregetinfo () { + case "$1" in + m|h|'?'|'') + echo " b Block device" + echo " c Console" + echo " n Network" + echo " p Virtual CPUs" + echo " r Memory" + ;; + b) + vbdpath="$xenstorepath/device/vbd" + for i in `xenstore-list $vbdpath` + do + echo "Virtual Device Name: $i" + echo "Virtual Device Type: `xenstore-read $vbdpath/$i/device-type`" + echo "Virtual Device State: `xenstoregetstatestr $(xenstore-read $vbdpath/$i/state)`" + vbdbackpath="`xenstore-read $vbdpath/$i/backend`" + echo "Virtual Device Backend Name: `xenstore-read $vbdbackpath/dev`" + echo "Virtual Device Backend Type: `xenstore-read $vbdbackpath/type`" + echo "Virtual Device Backend Parameter: `xenstore-read $vbdbackpath/params`" + echo -n "Other Information: " + case "`xenstore-read $vbdbackpath/online`" in + 0) + echo -n "Offline" + ;; + 1) + echo -n "Online" + ;; + *) + echo -n "Unknown" + ;; + esac + case "`xenstore-read $vbdbackpath/removable`" in + 0) + echo -n ", Non-removable" + ;; + 1) + echo -n ", Removable" + ;; + *) + echo -n ", Unknown" + ;; + esac + case "`xenstore-read $vbdbackpath/bootable`" in + 0) + echo ", Non-bootable" + ;; + 1) + echo ", Bootable" + ;; + *) + echo ", Unknown" + ;; + esac + echo "" + done + ;; + c) + conpath="$xenstorepath/console" + echo "Xen Console Backend TTY: `xenstore-read $conpath/tty`" + echo "Xen Console Buffer Size Limit: `xenstore-read $conpath/limit`" + echo "VNC Server Listen on: `xenstore-read $conpath/vnc-listen`:`xenstore-read $conpath/vnc-port`" + echo "" + ;; + n) + vifpath="$xenstorepath/device/vif" + for i in `xenstore-list $vifpath` + do + echo "Virtual Device Name: $i" + echo "Virtual Device State: `xenstoregetstatestr $(xenstore-read $vifpath/$i/state)`" + echo "Virtual Interface MAC Address: `xenstore-read $vifpath/$i/mac`" + vifbackpath="`xenstore-read $vifpath/$i/backend`" + echo "Bridge to: `xenstore-read $vifbackpath/bridge`" + echo "Script used to create/stop: `xenstore-read $vifbackpath/script`" + echo "" + done + ;; + p) + cpupath="$xenstorepath/cpu" + for i in `xenstore-list $cpupath` + do + echo "CPU $i: `xenstore-read $cpupath/$i/availability`" + done + ;; + r) + mempath="$xenstorepath/memory" + echo "Memory Size: `xenstore-read $mempath/target`" + echo "Maximum Memory Size: `xenstore-read $mempath/static-max`" + echo "Video Memory Size: `xenstore-read $mempath/videoram`" + ;; + *) + echo "Unrecognized command. Type m for help." + ;; + esac +} + +[ "`id -u`" != "0" ] && echo "This script should be run as root." && exit 40 + +if [ -z "$1" ] +then + read -p "Type a domain ID or domain name: " xendominput +else + xendominput="$1" +fi + +[ -z "$xendominput" ] && echo "Using default doamin 0" && xendominput=0 + +echo "Searching for domain $xendominput ..." + +if xenstore-read /local/domain/$xendominput 1> /dev/null 2> /dev/null +then + xenstorepath="/local/domain/$xendominput" +else + for i in `xenstore-list /local/domain` + do + if [ "$xendominput" = "`xenstore-read /local/domain/$i/name 2> /dev/null`" ] + then + xenstorepath="/local/domain/$i" + break + fi + done +fi + +if [ -z "$xenstorepath" ] +then + echo "Domain $xendominput not found." && exit 42 +else + echo "XenStore Path is $xenstorepath" +fi + +if [ -z "$2" ] +then + while read -p "XSView>>> " infocmdinput + do + xenstoregetinfo "$infocmdinput" + done +else + xenstoregetinfo "$2" +fi |