diff --git a/.gitignore b/.gitignore index 5068be8..772670b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ base.code-workspace /module.lib load/ucishellgiturl -btpl.run \ No newline at end of file +/modules/scripting/btpl +/modules/scripting/smenu \ No newline at end of file diff --git a/modules/scripting/btpl.lib b/modules/scripting/btpl.lib index dda82a1..45a24e6 100755 --- a/modules/scripting/btpl.lib +++ b/modules/scripting/btpl.lib @@ -5,8 +5,8 @@ export BTPLDIR btpl_fetch () { # /opt/python/apps/bin/lastversion --assets --output /shell/base/modules/scripting/btpl.lib download bash-tpl -wget -O "$BTPLDIR"/btpl.run https://raw.githubusercontent.com/TekWizely/bash-tpl/main/bash-tpl -chmod +x "$BTPLDIR"/btpl.run +wget -O "$BTPLDIR"/btpl https://raw.githubusercontent.com/TekWizely/bash-tpl/main/bash-tpl +chmod +x "$BTPLDIR"/btpl # sed -i 's/\bmain\b/btpl/g' /shell/base/modules/scripting/btpl.lib } @@ -14,25 +14,15 @@ btpl () { local dir if [[ $1 == "-d" ]]; then shift; dir=$1; shift; pushd $dir 1>/dev/null || return; fi [[ ! $BTPLDIR ]] && echo unable to establish Bash Template directory && return 2 - [[ ! -f $BTPLDIR/btpl.run ]] && btpl_fetch + [[ ! -f $BTPLDIR/btpl ]] && btpl_fetch for btpl in *.btpl; do [[ -f "$btpl" ]] || break echo processing $btpl ... - # echo sudo $BTPLDIR/btpl.run --output-file $(basename $btpl .btpl)$([[ $1 ]] && echo .$1) $btpl - $BTPLDIR/btpl.run $btpl - source <($BTPLDIR/btpl.run $btpl) | sudo tee $(basename $btpl .btpl)$([[ $1 ]] && echo .$1) + # echo sudo $BTPLDIR/btpl --output-file $(basename $btpl .btpl)$([[ $1 ]] && echo .$1) $btpl + $BTPLDIR/btpl $btpl + source <($BTPLDIR/btpl $btpl) | sudo tee $(basename $btpl .btpl)$([[ $1 ]] && echo .$1) done if [[ $dir ]]; then popd 1>/dev/null || return; fi } -sDNS () { - output=$(basename $1 .dns) - cp $1 $output - cat $output - for host in $(sed -e 's/ /\n/g' $1 | sed -n 's/[Dd][Nn][Ss]://p'); do - echo $host: $(dip $host) - sed -i 's/[Dd][Nn][Ss]:'$host'/'$(dip $host)'/g' $output - cat $output - done -} \ No newline at end of file diff --git a/modules/scripting/smenu.lib b/modules/scripting/smenu.lib new file mode 100644 index 0000000..1c69d43 --- /dev/null +++ b/modules/scripting/smenu.lib @@ -0,0 +1,69 @@ +#!/bin/bash +SMENUDIR=$(dirname $BASH_SOURCE) +export SMENUDIR + +smenu_fetch () { +local repo=https://github.com/p-gen/smenu.git +if git clone $repo /tmp/smenu; then + pushd /tmp/smenu || return 1 + if bash ./build.sh; then + mv smenu "$SMENUDIR" + chmod +x "$SMENUDIR/smenu" + else + echo Error attempting to build smenu from the repo + return 1 + fi + rm -rf /tmp/smenu + popd || return 1 +else + echo Error unable to fetch repo at https://github.com/p-gen/smenu.git + return 1 +fi +} + +smenu () { + [[ ! $SMENUDIR ]] && echo unable to establish Bash Template directory && return 2 + [[ ! -f "$SMENUDIR/smenu" ]] && smenu_fetch + if [[ -f "$SMENUDIR/smenu" ]]; then + [[ ! $@ ]] && set -- --help + $SMENUDIR/smenu "$@" +else + echo unable to fetch/build smenu, see $BASH_SOURCE + return 1 +fi +} + +confirm () { +local res +prompt=${1:-Please confirm your choice:} +res=$( + smenu -2 ^Y -1 ^N -3 ^C -s /^N -x cur 10 \ + -m "${prompt}:" \ + <<< "YES NO CANCEL" + ) + +case $res in + YES) + res=0 ;; + NO) + res=1 ;; + CANCEL) + res=2 ;; + *) + res=3 ;; +esac +return $res +} + +smenu_test () { +echo "testing smenu using a simple confirmation" + +confirm "Choose or abort and see return value" +echo $? + +if confirm "Choose or abort and an if statement is evaluated"; then +echo "confirm returned 0/true (i.e. YES), proceed" +else +echo "confirm returned other than 0, i.e. false, do nothing" +fi +}