diff options
author | pgen <p.gen.progs@gmail.com> | 2016-03-02 23:32:46 +0100 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2016-03-02 23:32:46 +0100 |
commit | 3714031448790d12cd03b633c6fbca3ad1423631 (patch) | |
tree | ab18883eed093569d193a8b782980fccd101ed2b /examples | |
parent | caacc9ad615a413f36ac53bce49f77d2b5fb4713 (diff) |
Add an example in the form of scripts providing a simple menuing system
Diffstat (limited to 'examples')
-rw-r--r-- | examples/lvm_menu/README | 7 | ||||
-rwxr-xr-x | examples/lvm_menu/lvm_menu.sh | 49 | ||||
-rwxr-xr-x | examples/lvm_menu/menu.sh | 85 | ||||
-rw-r--r-- | examples/lvm_menu/screenshot.png | bin | 0 -> 6069 bytes |
4 files changed, 141 insertions, 0 deletions
diff --git a/examples/lvm_menu/README b/examples/lvm_menu/README new file mode 100644 index 0000000..a88aec9 --- /dev/null +++ b/examples/lvm_menu/README @@ -0,0 +1,7 @@ +This is an example of bash tool to build a customized LVM management menu. + +menu.sh is used to create a generic menu with smenu +lvm_menu.sh uses menu.sh to create a specialized menu to manage LVM objects + +Running lvm_menu.sh -i should display something similar to the screenshot +provided. In this screenshot the user is about to delete a LV. diff --git a/examples/lvm_menu/lvm_menu.sh b/examples/lvm_menu/lvm_menu.sh new file mode 100755 index 0000000..cad4db0 --- /dev/null +++ b/examples/lvm_menu/lvm_menu.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +MENU+="\ +'Create' 'Delete' 'Extend' 'Shrink' +'VGC VG' 'VGD VG' 'VGE VG' 'VGS VG' +'LVC LV' 'LVD LV' 'LVE LV' 'LVS LV' +'PVC PV' 'PVD PV' +# +'L List' +# +'Quit Exit menu'" + +trap "exit 1" INT + +while true +do + clear + echo "Executing ${0##*/}" + echo + + MESSAGE="LVM management" + read REP <<< $(echo "$MENU" | ./menu.sh -i "$MESSAGE" "-Rd1") + + case $REP in + ABORT) exit 1 ;; + QUIT) exit 0 ;; + + L) echo List ;; + + VGC) echo VG create ;; + VGD) echo VG delete ;; + VGE) echo VG expand ;; + VGS) echo VG shrink ;; + + LVC) echo LV create ;; + LVD) echo LV delete ;; + LVE) echo LV expand ;; + LVS) echo LV list ;; + + PVC) echo PV create ;; + PVD) echo PV delete ;; + esac + + echo + echo -n "Press <Enter> to continue" + read +done + +exit 0 diff --git a/examples/lvm_menu/menu.sh b/examples/lvm_menu/menu.sh new file mode 100755 index 0000000..cf1bafe --- /dev/null +++ b/examples/lvm_menu/menu.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# ################################################################ # +# Frontend to smenu to display a nice menu # +# # +# FLAGS: -i (optional) add some help in the title # +# # +# ARGS: $1 (required) must contain a string which will become # +# the menu title # +# $2... (optional) adds more options passed to smenu # +# # +# RC: 0 OK # +# 1 KO # +# ################################################################ # + +# ============== # +# usage function # +# ============== # +function usage +{ + echo "menu.sh [-i] title [smenu options]" + exit 1 +} + +declare integer INFO=0 + +# Option processing +# """"""""""""""""" +while getopts ih OPT 2>/dev/null +do + case ${OPT} in + i) INFO=1 + ;; + + h|*) usage + exit 1 + ;; + esac +done +shift $((${OPTIND} - 1)) + +# Menu title generation +# """"""""""""""""""""" +if [[ $1 ]]; then + MESSAGE="$1" + (( INFO )) && MESSAGE+=$'\n'"[ q=quit arrows=move ?=help ]" + TITLE="-m" + TITLE+=$MESSAGE$'\n' + shift +else + TITLE="-m " +fi + +# Menu display +# """""""""""" +REP=$(../../smenu "$TITLE" \ + -s /"* Exit" \ + -q -d -M -n 30 -c -w \ + -e '^#' -E '/(^#)+(.*)$/ \2/v' \ + -1 '\\* Exit' 7/4,b \ + -I '/([^ ]+) (.*)/* \2/v' \ + $1 \ + || echo Abort) + +read KEY DUMMY <<< $REP + +# Action processing +# """"""""""""""""" +case $KEY in + Abort) + echo ABORT + ;; + + ""|Quit) + echo QUIT + ;; + + *) + echo $KEY + ;; +esac + +# Normal exit +# """"""""""" +exit 0 diff --git a/examples/lvm_menu/screenshot.png b/examples/lvm_menu/screenshot.png Binary files differnew file mode 100644 index 0000000..5d98376 --- /dev/null +++ b/examples/lvm_menu/screenshot.png |