From 3714031448790d12cd03b633c6fbca3ad1423631 Mon Sep 17 00:00:00 2001 From: pgen Date: Wed, 2 Mar 2016 23:32:46 +0100 Subject: Add an example in the form of scripts providing a simple menuing system --- examples/lvm_menu/README | 7 ++++ examples/lvm_menu/lvm_menu.sh | 49 ++++++++++++++++++++++ examples/lvm_menu/menu.sh | 85 +++++++++++++++++++++++++++++++++++++++ examples/lvm_menu/screenshot.png | Bin 0 -> 6069 bytes 4 files changed, 141 insertions(+) create mode 100644 examples/lvm_menu/README create mode 100755 examples/lvm_menu/lvm_menu.sh create mode 100755 examples/lvm_menu/menu.sh create mode 100644 examples/lvm_menu/screenshot.png (limited to 'examples') 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 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 new file mode 100644 index 0000000..5d98376 Binary files /dev/null and b/examples/lvm_menu/screenshot.png differ -- cgit v1.2.3