update bes.echo dependency to 1.2

This commit is contained in:
a-sansara 2018-12-22 11:38:53 +01:00
parent 5d39ad2255
commit 17a86492d7
4 changed files with 176 additions and 137 deletions

View File

@ -1,7 +1,7 @@
[project]
vendor = bes
name = config
version = 1.0
version = 1.1
license = "GNU GPL v3"
author = a-Sansara
type = application
@ -11,5 +11,5 @@ keywords = "bash, bes, config"
[require]
bes.ini = 1.1
bes.echo = 1.1
bes.install = 1.0
bes.echo = 1.2
bes.install = 1.1

291
dist/bes-config vendored
View File

@ -1,6 +1,103 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# @author a-Sansara - https://git.pluie.org/meta-tech/bes-color
# @app bes-color
# @license GNU GPL v3
# @date 2017-10-23 23:30:54 CET
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.color.boot () {
BES_NOCOLOR=${BES_NOCOLOR:-0}
if [ "$BES_NOCOLOR" -eq 0 ]; then
# by convention all colors begins with 'C' uppercase
# followed by a name in lowercase
# background foreground
# R G B R G B
color.set "Chead" 53 114 160 195 223 255
color.set "Cheadsep" 53 114 160 252 212 102
# background
# R G B
color.bg "Cdone" 63 172 138
color.bg "Cfail" 172 63 85
# foreground
# R G B
color.fg "Ctitle" 133 92 181
color.fg "Cheadline" 22 74 133
color.fg "Csep" 80 80 80
color.fg "Cerr" 194 48 64
color.fg "Cval" 255 175 95
color.fg "Ckey" 40 168 134
color.fg "Caction" 106 183 241
color.fg "Csymbol" 255 175 95
color.fg "Citem" 92 147 181
color.fg "Cusa" 255 172 0
color.fg "Cspe" 255 214 166
color.fg "Copt" 94 215 255
color.fg "Ccom" 175 135 175
color.fg "Ctext" 0 132 101
color.fg "Cmeta" 39 100 170
Coff="\\033[m"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function color.fg()
{
local -n var=$1
var="\033[1;38;2;$2;$3;$4m"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function color.bg()
{
local -n var=$1
var="\033[1;48;2;$2;$3;$4m"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function color.set()
{
local -n var=$1
var="\033[1;48;2;$2;$3;$4;1;38;2;$5;$6;$7m"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function color.rgb ()
{
local c=${3:-0}
local v=$1
local -n r=${2}_r
local -n g=${2}_g
local -n b=${2}_b
if [ -z "$v" ]; then
r=$c
g=$c
b=$c
return
fi
r=${v%%;*}
[ "$v" = "$r" ] && v='' || v="${v#*;}"
if [ -z "$r" ]; then r=$c; fi
g=${v%%;*}
[ "$v" = "$g" ] && v='' || v="${v#*;}"
if [ -z "$g" ]; then g=$c; fi
b=${v%%;*}
if [ -z "$b" ]; then b=$c; fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function color.env () {
local -n var=${2:-shenv}
local v=ctx$1
local ctxPROD="174 8 49"
local ctxINT="218 84 0"
local ctxDEV="218 159 0"
local ctxLOCAL="122 122 122"
if [ -z "${!v}" ]; then
v=ctxLOCAL
SHENV_CTX=LOCAL
fi
var=${!v}
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.color.boot
#
# @author a-Sansara - https://git.pluie.org/meta-tech/bes-echo
# @app bes-echo
# @license GNU GPL v3
@ -9,80 +106,49 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.boot ()
{
BES_TERM_WIDTH=${BES_TERM_WIDTH:-105}
BES_NOCOLOR=${BES_NOCOLOR:-0}
if [ "$BES_NOCOLOR" -eq 0 ]; then
Cok="\033[0;38;5;43m"; Cko="\033[0;38;5;217m"
Coff="\033[m"; Ctitle="\033[1;48;5;24;1;38;5;15m"
Cdone="\033[1;48;5;36;1;38;5;15m"; Cfail="\033[1;48;5;196;1;38;5;15m"
Cspe="\033[1;38;5;223m"; Citem="\033[1;38;5;214m"
Cval="\033[1;38;5;215m"; Cusa="\033[1;38;5;214m"
Cbra="\033[1;38;5;203m"; Crepo="\033[1;38;5;223m"
Cmeta="\033[1;38;5;30m"; Ctext="\033[1;38;5;30m"
Copt="\033[1;38;5;81m"; Csep="\033[1;38;5;241m"
Cerr="\033[1;38;5;196m"; Ccom="\033[0;38;5;139m"
Csection="\033[1;38;5;97m"; Caction="\033[0;38;5;37m"
fi
BES_TERM_WIDTH=${COLUMNS:-130}
BES_TERM_WIDTH=$(($BES_TERM_WIDTH - 20))
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo ()
function echo.msg ()
{
local msg=${1:-''}
local isAction=${2:-'0'}
local symbol=${3:-' *'}
if [ ! "$BES_NOCOLOR" = 1 ]; then
local c=" "
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
c=$Caction
fi
if [ ! "$isAction" = 0 ]; then
c=" $Citem$symbol $c"
fi
echo -e " $c$msg$Coff"
else
if [ ! "$isAction" = 0 ]; then
msg=" $symbol $msg"
fi
echo -e "$msg"
fi
local c=${2:-}
local m=${1:-}
echo -e " $c$m$Coff"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.action ()
function echo.state ()
{
bes.echo "$1" 1
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.title ()
{
echo
bes.echo " ${Citem}☪ ${Csection}$1 ${Cspe}$2${Coff}"
echo
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.keyval ()
{
local c=': '
if [ ! "$BES_NOCOLOR" = 1 ]; then
c="$Citem: ${Cval}"
fi
local len="%-15s "
# printf "%s %s [UP]\n" $PROC_NAME "${line:${#PROC_NAME}}"
bes.echo "$(printf $len $1) $c$2 " 1 " "
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.state ()
{
local len=8
printf "%0.s " $(seq 1 $(($BES_TERM_WIDTH-${len})))
local len=14
echo -en " $Csep"
printf "%0.s-" $(seq 1 $(($BES_TERM_WIDTH-${len})))
if [ "$1" = 0 ]; then
echo -e "${Cdone} OK ${Coff}"
echo -e "$Coff $Cdone OK $Coff\n"
else
echo -e "${Cfail} KO ${Coff}"
echo -e "$Coff $Cfail KO $Coff\n"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.rs ()
function echo.action ()
{
local symbol=${3:-*}
local color=${4:-Citem}
echo -e " $Csymbol$symbol ${Caction}$1 ${!color}$2$Coff"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function echo.title ()
{
echo -e "\n $Csymbol☪ $Ctitle$1 $Coff$Cspe$2$Coff\n"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function echo.keyval ()
{
local len=${3:-20}
local c="$Ckey: ${Cval}"
echo -e " $Ckey $(printf "%-${len}s " "$1") ${c}${2} $Coff"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function echo.rs ()
{
local rs=${1:-0}
if [ "$rs" -eq 0 ]; then
@ -92,47 +158,39 @@ function bes.echo.rs ()
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.error ()
function echo.error ()
{
local leave=${2:-0}
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
if [ "$leave" = "1" ]; then
exit 1;
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.sepline ()
function echo.sepline ()
{
local char=${1:-'_'}
local width=${2:-$BES_TERM_WIDTH}
echo -ne "${Csep} "
echo -ne "${Cheadline} "
printf "%0.s$char" $(seq 1 $width)
echo -e "${Coff}"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.app ()
function echo.app ()
{
local msg=${1:-''}
local version=${2:-''}
local author=${3:-'a-Sansara'}
local license=${3:-'GNU GPL v3'}
if [ ! -z "$2" ]; then
msg="$msg ${Cval}v$version"
fi
local len="$1${version}license : GNU GPL v3 author:$author"
bes.echo.sepline
echo -ne "\n $Ctitle $msg $Coff"
local len="$1${version}license : $license author:$author"
echo.sepline
echo -ne "\n $Chead $msg $Coff"
printf "%0.s " $(seq 1 $(($BES_TERM_WIDTH-${#len}-15)))
echo -e " ${Cmeta}license : ${Coff}GNU GPL v3 ${Cmeta}author : ${Cval}$author"
bes.echo.sepline
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.echo.colormap ()
{
for fgbg in 38 48 ; do
for color in {0..256} ; do
echo -en "\e[${fgbg};5;${color}m ${color}\t\e[0m"
if [ $((($color + 1) % 7)) == 0 ] ; then
echo
fi
done
echo
done
echo -e " ${Cmeta}license : ${Coff}$license ${Cmeta}author : ${Cval}$author"
echo.sepline
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.boot
@ -143,7 +201,7 @@ bes.echo.boot
# @license GNU GPL v3
# @date 2017-05-19 22:52:59 CET
#
# bes alter '__' to '_' , rename bes.ini to bes.ini
# bes alter '__' to '_' , rename read_ini to bes.ini
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
@ -167,7 +225,7 @@ function bes.ini ()
function check_prefix()
{
if ! [[ "${VARNAME_PREFIX}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] ;then
echo "bes.ini: invalid prefix '${VARNAME_PREFIX}'" >&2
echo "read_ini: invalid prefix '${VARNAME_PREFIX}'" >&2
return 1
fi
}
@ -175,7 +233,7 @@ function bes.ini ()
function check_ini_file()
{
if [ ! -r "$INI_FILE" ] ;then
echo "bes.ini: '${INI_FILE}' doesn't exist or not" \
echo "read_ini: '${INI_FILE}' doesn't exist or not" \
"readable" >&2
return 1
fi
@ -194,7 +252,7 @@ function bes.ini ()
}
# unset all local functions and restore shopt settings before returning
# from bes.ini()
# from read_ini()
function cleanup_bash()
{
shopt -q -u ${SWITCH_SHOPT}
@ -261,8 +319,8 @@ function bes.ini ()
done
if [ -z "$INI_FILE" ] && [ "${CLEAN_ENV}" = 0 ] ;then
echo -e "Usage: bes.ini [-c] [-b 0| -b 1]] [-p PREFIX] FILE"\
"[SECTION]\n or bes.ini -c [-p PREFIX]" >&2
echo -e "Usage: read_ini [-c] [-b 0| -b 1]] [-p PREFIX] FILE"\
"[SECTION]\n or read_ini -c [-p PREFIX]" >&2
cleanup_bash
return 1
fi
@ -442,8 +500,10 @@ function bes.install ()
local url=${2}
local path=${3:-/usr/local/bin}
local done=1
bes.echo.title "Installing $app ${Coff}in" "$path"
echo.title "Installing $app ${Coff}in" "$path"
if [ -z "$app" ] || [ -s "$url" ]; then
echo.error "in bes.install : \$app '$app' & \$url '$url' are required" 1
fi
if [ -f "./$app" ]; then
rm ./$app
fi
@ -453,20 +513,20 @@ function bes.install ()
if [ -d $path ]; then
sudo mv ./$app $path/$app
local done=$?
bes.echo.state $done
echo.state $done
else
bes.echo.error "install directory do not exists : ${Cspe}$path"
echo.error "install directory do not exists : ${Cspe}$path"
fi
else
bes.echo.error "can not download latest version of app $app. please check url : $url"
echo.error "can not download latest version of app $app. please check url : $url"
fi
bes.echo.rs $done
echo.rs $done
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.config ()
{
bes.echo.title "Reading Configuration Project" $APP_NAME
echo.title "Reading Configuration Project" $APP_NAME
if [ -f ./bes.ini ]; then
bes.ini ./bes.ini -p bes -b 1
@ -477,49 +537,28 @@ function bes.config ()
value="bes_project_$key"
if [ ! -z "${!value}" ]; then
hasconf=1
bes.echo.keyval $key "${!value}"
echo.keyval $key "${!value}"
fi
done
if [ "$hasconf" = "0" ]; then
bes.echo " -"
echo.msg " -"
fi
bes.echo.title "Dependencies"
echo.title "Dependencies"
bes.ini ./bes.ini require -p bes -b 1
local prefix="bes_require"
local key=""
for name in ${bes_ALL_VARS}; do
key=${name:${#prefix}+1}
local tmp=${key//_/.}
bes.echo.keyval "$tmp" "${!name}"
echo.keyval "$tmp" "${!name}"
done
else
bes.echo " $project does not have bes.ini file"
echo " $project does not have bes.ini file"
fi
echo
}
BES_BIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.fn.list ()
{
while IFS= read -r line; do
if [ ! "${line:11}" = "bes.fn.list" ] && [ ! "${line:11}" = "read_ini" ]; then
echo "${line:11}"
fi
done < <(declare -F)
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.export ()
{
# $1 : fromFnName
# $2 : toFnName
local code=$(declare -f "$1")
local len=${#1}
source /dev/stdin < <(echo "$2${code:len}")
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.usage ()
{
@ -543,7 +582,7 @@ function bes.usage ()
# @date 2017-06-16 04:38:52 CET
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_VERSION=0.2
BES_VERSION=1.1
BES_NAME="bes-config"
BES_URL="https://git.pluie.org/meta-tech/$BES_NAME/raw/latest/dist/$BES_NAME"
APP_DIR=$(pwd)
@ -556,7 +595,7 @@ function bes.main ()
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
echo $BES_VERSION
else
bes.echo.app $BES_NAME $BES_VERSION
echo.app $BES_NAME $BES_VERSION
echo
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
bes.install "$BES_NAME" "$BES_URL" "$2"

View File

@ -3,7 +3,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.config ()
{
bes.echo.title "Reading Configuration Project" $APP_NAME
echo.title "Reading Configuration Project" $APP_NAME
if [ -f ./bes.ini ]; then
bes.ini ./bes.ini -p bes -b 1
@ -14,24 +14,24 @@ function bes.config ()
value="bes_project_$key"
if [ ! -z "${!value}" ]; then
hasconf=1
bes.echo.keyval $key "${!value}"
echo.keyval $key "${!value}"
fi
done
if [ "$hasconf" = "0" ]; then
bes.echo " -"
echo.msg " -"
fi
bes.echo.title "Dependencies"
echo.title "Dependencies"
bes.ini ./bes.ini require -p bes -b 1
local prefix="bes_require"
local key=""
for name in ${bes_ALL_VARS}; do
key=${name:${#prefix}+1}
local tmp=${key//_/.}
bes.echo.keyval "$tmp" "${!name}"
echo.keyval "$tmp" "${!name}"
done
else
bes.echo " $project does not have bes.ini file"
echo " $project does not have bes.ini file"
fi
echo
}

View File

@ -7,7 +7,7 @@
# @date 2017-06-16 04:38:52 CET
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_VERSION=0.2
BES_VERSION=1.1
BES_NAME="bes-config"
BES_URL="https://git.pluie.org/meta-tech/$BES_NAME/raw/latest/dist/$BES_NAME"
APP_DIR=$(pwd)
@ -20,7 +20,7 @@ function bes.main ()
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
echo $BES_VERSION
else
bes.echo.app $BES_NAME $BES_VERSION
echo.app $BES_NAME $BES_VERSION
echo
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
bes.install "$BES_NAME" "$BES_URL" "$2"