diff options
author | LAN-TW <lantw44@gmail.com> | 2012-06-11 00:27:06 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2012-06-11 00:27:06 +0800 |
commit | 23d75b28069f40d859976cc934f5aa02aa2118af (patch) | |
tree | 0da77735c20ebef8268c20aeec0e41c7f91e70c9 | |
parent | f776db8ef7ff7cf009158fe2a291c8e017b06216 (diff) | |
download | xenstore-editor-23d75b28069f40d859976cc934f5aa02aa2118af.tar.gz xenstore-editor-23d75b28069f40d859976cc934f5aa02aa2118af.tar.zst xenstore-editor-23d75b28069f40d859976cc934f5aa02aa2118af.zip |
Update - version 1.1v1.1
- 修改數值的畫面加入「檔案瀏覽器」功能
- 如果項目的值是 XenStore 路徑,那麼在 Chdir 選單中會出現 UseValue 項目,允許使
用者直接切換到該路徑
-rw-r--r-- | change.log | 7 | ||||
-rwxr-xr-x | xenstore-editor-zh_TW.utf8.sh | 98 | ||||
-rwxr-xr-x | xenstore-editor.sh | 69 |
3 files changed, 130 insertions, 44 deletions
diff --git a/change.log b/change.log new file mode 100644 index 0000000..a4d934b --- /dev/null +++ b/change.log @@ -0,0 +1,7 @@ +* 2012-06-11 lantw44 <lantw44@www.tfcis.org> - 1.1 +- 修改數值的畫面加入「檔案瀏覽器」功能 +- 如果項目的值是 XenStore 路徑,那麼在 Chdir 選單中會出現 UseValue 項目,允許使 + 用者直接切換到該路徑 + +* 2012-06-08 lantw44 <lantw44@www.tfcis.org> - 1.0 +- 最初版本 diff --git a/xenstore-editor-zh_TW.utf8.sh b/xenstore-editor-zh_TW.utf8.sh index ffaeb8b..e1ba2e6 100755 --- a/xenstore-editor-zh_TW.utf8.sh +++ b/xenstore-editor-zh_TW.utf8.sh @@ -1,9 +1,8 @@ #!/bin/bash -### Name: Simple XenStore Editor -### Version: 1.0 -### Release Date: 2012-06-08 +### 名稱: Simple XenStore Editor +### 版本: 1.1 +### 發行日期: 2012-06-11 -# [ "`id -u`" != "0" ] && echo "This script should be run as root." && exit 40 [ "`id -u`" != "0" ] && echo "這個 script 必須以 root 身份執行。" && exit 40 if [ "$1" ];then @@ -17,12 +16,10 @@ first_run=1 setdefault=0 prevdir="$current" tmpfile=`mktemp` -# scripttitle=" Simple XenStore Editor " -scripttitle=" 簡易 XenStore 編輯工具 " +scripttitle=" 簡易 XenStore 編輯工具 版本 1.1 " scriptshorttitle="簡易 XenStore 編輯工具" -# scriptshorttitle="Simple XenStore Editor" -function getxenfullpath { +function getxenfullpath () { if [ "$1" = "/" ] then echo "/$2" @@ -31,6 +28,43 @@ function getxenfullpath { fi } +function getusernewvalue () { + local initvalue="$3" + while true + do + dialog --ascii-lines --title "$1" --extra-button --extra-label "檔案瀏覽器" --inputbox "$2" 0 0 "$initvalue" 2> "$tmpfile" + local exitstat=$? + case "$exitstat" in + 0|1) + return "$exitstat" + ;; + 3) + local initdir="/" + local tmpfile2="`mktemp`" + local selectedfile="/" + local nowvalue="`cat "$tmpfile"`" + local parentdir="`dirname "$nowvalue"`" + if [ "`echo "$nowvalue" | cut -c 1`" != "/" ] || [ '!' -e "$parentdir" ] + then + dialog --ascii-lines --title "檔案瀏覽器" --msgbox "$parentdir 目錄不存在" 0 0 + initdir="`pwd`/" + else + initdir="$nowvalue" + fi + dialog --ascii-lines --title "請用空白鍵來複製游標所在位置的檔案路徑" --fselect "$initdir" 13 75 2> "$tmpfile2" + if [ "$?" = "0" ] + then + selectedfile="`cat "$tmpfile2"`" + initvalue="$selectedfile" + else + initvalue="$nowvalue" + fi + rm -f "$tmpfile2" + ;; + esac + done +} + while [ "$should_exit" = "0" ] do unset dirlist @@ -39,8 +73,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 --ascii-lines --title "$scripttitle" --msgbox "無法從 $current 取得檔案清單" 0 0 + dialog --ascii-lines --title "$scripttitle" --msgbox "無法從 $current 取得檔案清班" 0 0 if [ "$first_run" != "0" ] then exit 1 @@ -71,10 +104,8 @@ 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 --ascii-lines --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 "Chdir" --cancel-label "Exit" --extra-button --extra-label "Edit" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" dialog --ascii-lines --title "$scripttitle" --ok-label "切換目錄" --cancel-label "離開" --extra-button --extra-label "編輯" --default-item "$setdefaultvalue" --menu "$current" 0 0 0 "${valuelist[@]}" 2> "$tmpfile" fi dialogexit=$? @@ -82,15 +113,21 @@ do setdefault=0 case "$dialogexit" in 0) + unset valuepathvalid descending="`getxenfullpath "$current" "$dialogout"`" ascending="`dirname "$current"`" - 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" + usevalue="`xenstore-read "$descending"`" + if [ "$usevalue" ]; then + xenstore-read "$usevalue" 2> /dev/null + [ "$?" = "0" ] && valuepathvalid=1 + fi + if [ "$dialogout" = "(Empty)" ]; then dialog --ascii-lines --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" + 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 --ascii-lines --title "$scriptshorttitle - 切換目錄" --menu "請從清單中選取" 0 0 0 "Enter" "進入 $descending" "Back" "進入 $ascending" "Manual" "輸入 XenStore 路徑" 2> "$tmpfile" dialogexit=$? fi @@ -106,8 +143,11 @@ do prevdir="$current" current="$ascending" ;; + "UseValue") + prevdir="$current" + current="$usevalue" + ;; "Manual") - # dialog --ascii-lines --title "$scriptshorttitle - Chdir - Manual" --inputbox "XenStore Directory Name" 0 0 "$current" 2> "$tmpfile" dialog --ascii-lines --title "$scriptshorttitle - 切換目錄 - Manual" --inputbox "XenStore 目錄名稱" 0 0 "$current" 2> "$tmpfile" if [ "$?" = "0" ] then @@ -125,7 +165,6 @@ do fi ;; 1) - # if dialog --ascii-lines --title "$scriptshorttitle - Exit" --yesno "Do you really want to quit?" 0 0 if dialog --ascii-lines --title "$scriptshorttitle - 離開" --yesno "你確定要離開嗎?" 0 0 then should_exit=1 @@ -134,12 +173,10 @@ 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 --ascii-lines --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Add" "加入新值" 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 --ascii-lines --title "$scriptshorttitle - 編輯" --menu "請從清單中選取" 0 0 0 "Modify" "修改此值" "Remove" "刪除此值" "Add" "加入新值" 2> "$tmpfile" dialogexit=$? dialogout2="`cat "$tmpfile"`" @@ -148,7 +185,6 @@ do then case "$dialogout2" in "Add") - # dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --inputbox "Name" 0 0 2> "$tmpfile" dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Add" --inputbox "名稱" 0 0 2> "$tmpfile" if [ "$?" = "0" ] then @@ -158,8 +194,7 @@ do setdefaultvalue="$dialogout" continue fi - # dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --inputbox "Value" 0 0 2> "$tmpfile" - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Add" --inputbox "值" 0 0 2> "$tmpfile" + getusernewvalue "$scriptshorttitle - 編輯 - Add" "值" "" if [ "$?" = "0" ] then newvalue="`cat "$tmpfile"`" @@ -172,7 +207,6 @@ do outmsg="`xenstore-write "$fullpath" "$newvalue" 2>&1`" if [ "$?" != "0" ] then - # dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --msgbox "$outmsg" 0 0 dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Add" --msgbox "$outmsg" 0 0 else setdefault=1 @@ -180,16 +214,14 @@ do fi ;; "Modify") - fullpath="`getxenfullpath "$current" "$dialogout"`" - # dialog --ascii-lines --title "$scriptshorttitle - Edit - Modify" --inputbox "New value" 0 0 "`xenstore-read "$fullpath"`" 2> "$tmpfile" - dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Modify" --inputbox "值" 0 0 "`xenstore-read "$fullpath"`" 2> "$tmpfile" + fullpath="`getxenfullpath "$current" "$dialogout"`" + getusernewvalue "$scriptshorttitle - 編輯 - Modify" "值" "`xenstore-read "$fullpath"`" if [ "$?" = "0" ] then dialogout3="`cat "$tmpfile"`" outmsg="`xenstore-write "$fullpath" "$dialogout3" 2>&1`" if [ "$?" != "0" ] then - # dialog --ascii-lines --title "$scriptshorttitle - Edit - Modify" --msgbox "$outmsg" 0 0 dialog --ascii-lines --title "$scriptshorttitle - 編輯 - Modify" --msgbox "$outmsg" 0 0 else setdefault=1 @@ -202,13 +234,11 @@ 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 --ascii-lines --title "$scriptshorttitle - 編輯 - Remove" --yesno "你確定要刪除 $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 --ascii-lines --title "$scriptshorttitle - 編輯 - Remove" --msgbox "$outmsg" 0 0 else setdefault=1 @@ -220,12 +250,12 @@ do fi ;; esac - else - setdefault=1 - setdefaultvalue="$dialogout" + else + setdefault=1 + setdefaultvalue="$dialogout" fi ;; esac done -rm "$tmpfile" +rm -f "$tmpfile" diff --git a/xenstore-editor.sh b/xenstore-editor.sh index f2f9ecb..e44d302 100755 --- a/xenstore-editor.sh +++ b/xenstore-editor.sh @@ -1,7 +1,7 @@ #!/bin/bash ### Name: Simple XenStore Editor -### Version: 1.0 -### Release Date: 2012-06-08 +### Version: 1.1 +### Release Date: 2012-06-11 [ "`id -u`" != "0" ] && echo "This script should be run as root." && exit 40 @@ -16,10 +16,10 @@ first_run=1 setdefault=0 prevdir="$current" tmpfile=`mktemp` -scripttitle=" Simple XenStore Editor " +scripttitle=" Simple XenStore Editor Version 1.1 " scriptshorttitle="Simple XenStore Editor" -function getxenfullpath { +function getxenfullpath () { if [ "$1" = "/" ] then echo "/$2" @@ -28,6 +28,43 @@ function getxenfullpath { fi } +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" + local exitstat=$? + case "$exitstat" in + 0|1) + return "$exitstat" + ;; + 3) + local initdir="/" + local tmpfile2="`mktemp`" + local selectedfile="/" + local nowvalue="`cat "$tmpfile"`" + 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 + initdir="`pwd`/" + else + initdir="$nowvalue" + fi + dialog --ascii-lines --title "Use space-bar to copy the current selection" --fselect "$initdir" 13 75 2> "$tmpfile2" + if [ "$?" = "0" ] + then + selectedfile="`cat "$tmpfile2"`" + initvalue="$selectedfile" + else + initvalue="$nowvalue" + fi + rm -f "$tmpfile2" + ;; + esac + done +} + while [ "$should_exit" = "0" ] do unset dirlist @@ -76,12 +113,20 @@ do setdefault=0 case "$dialogexit" in 0) + unset valuepathvalid descending="`getxenfullpath "$current" "$dialogout"`" ascending="`dirname "$current"`" - if [ "$dialogout" = "(Empty)" ] - then + usevalue="`xenstore-read "$descending"`" + if [ "$usevalue" ]; then + xenstore-read "$usevalue" 2> /dev/null + [ "$?" = "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" 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" + 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" dialogexit=$? @@ -98,6 +143,10 @@ do prevdir="$current" current="$ascending" ;; + "UseValue") + prevdir="$current" + current="$usevalue" + ;; "Manual") dialog --ascii-lines --title "$scriptshorttitle - Chdir - Manual" --inputbox "XenStore Directory Name" 0 0 "$current" 2> "$tmpfile" if [ "$?" = "0" ] @@ -145,7 +194,7 @@ do setdefaultvalue="$dialogout" continue fi - dialog --ascii-lines --title "$scriptshorttitle - Edit - Add" --inputbox "Value" 0 0 2> "$tmpfile" + getusernewvalue "$scriptshorttitle - Edit - Add" "Value" "" if [ "$?" = "0" ] then newvalue="`cat "$tmpfile"`" @@ -165,8 +214,8 @@ do fi ;; "Modify") - fullpath="`getxenfullpath "$current" "$dialogout"`" - dialog --ascii-lines --title "$scriptshorttitle - Edit - Modify" --inputbox "New value" 0 0 "`xenstore-read "$fullpath"`" 2> "$tmpfile" + fullpath="`getxenfullpath "$current" "$dialogout"`" + getusernewvalue "$scriptshorttitle - Edit - Modify" "New value" "`xenstore-read "$fullpath"`" if [ "$?" = "0" ] then dialogout3="`cat "$tmpfile"`" @@ -209,4 +258,4 @@ do esac done -rm "$tmpfile" +rm -f "$tmpfile" |