From fa7aa891b58f7a2eaf2bcd8469e57eba9b2fd50b Mon Sep 17 00:00:00 2001 From: a-sansara Date: Sat, 22 Dec 2018 17:25:03 +0100 Subject: [PATCH] update boot sequence --- bes.ini | 6 +- dist/bes-build | 167 +++++++++++++++++++++++++++++++++++++++---------- src/build.sh | 32 +++++++++- src/main.sh | 2 +- 4 files changed, 167 insertions(+), 40 deletions(-) diff --git a/bes.ini b/bes.ini index cbf374c..7fa9234 100644 --- a/bes.ini +++ b/bes.ini @@ -1,7 +1,7 @@ [project] vendor = bes name = build -version = 0.6 +version = 0.9 license = "GNU GPL v3" author = a-Sansara type = application @@ -10,6 +10,4 @@ description = "bash bes build application for bash programs" keywords = "bash, bes, build" [require] -bes.ini = 1.1 -bes.echo = 1.2 -bes.install = 1.1 +bes.install = 1.2 diff --git a/dist/bes-build b/dist/bes-build index d2cc452..96e9b17 100755 --- a/dist/bes-build +++ b/dist/bes-build @@ -1,5 +1,31 @@ #!/bin/bash # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BES_BOOT= +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.exists () { + declare -f $1 > /dev/null + #~ [ x$(type -t $1) = xfunction ]; +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.boot () +{ + for fn in $BES_BOOT; do + if bes.exists $fn.boot; then + $fn.boot + fi + done +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.reg () +{ + local sep=" " + if [ -z "$BES_BOOT" ]; then + sep="" + fi + BES_BOOT=$BES_BOOT$sep$1 +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # # @author a-Sansara - https://git.pluie.org/meta-tech/bes-color # @app bes-color @@ -10,52 +36,67 @@ 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 + color.load + if [ $? -eq 1 ]; then + # by convention all colors begins with 'C' uppercase + # followed by a name in lowercase + # but in this calls you dont need to prefix names + # + # background foreground + # R G B R G B + color.set "head" 53 114 160 195 223 255 + color.set "headsep" 53 114 160 252 212 102 + # background + # R G B + color.bg "done" 63 172 138 + color.bg "fail" 172 63 85 + # foreground + # R G B + color.fg "title" 133 92 181 + color.fg "headline" 22 74 133 + color.fg "sep" 80 80 80 + color.fg "err" 194 48 64 + color.fg "val" 255 175 95 + color.fg "key" 40 168 134 + color.fg "action" 106 183 241 + color.fg "symbol" 255 175 95 + color.fg "item" 92 147 181 + color.fg "usa" 255 172 0 + color.fg "spe" 255 214 166 + color.fg "opt" 94 215 255 + color.fg "com" 175 135 175 + color.fg "text" 0 132 101 + color.fg "meta" 39 100 170 + echo -e "$Cerr warning ${Coff}cannot load colors config file" + fi Coff="\\033[m" fi } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function color.fg() { - local -n var=$1 + local s=${1} + if [ ${s:0:1} = "C" ]; then s=${s:1}; fi + s=${s,,} + local -n var=C$1 var="\033[1;38;2;$2;$3;$4m" } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function color.bg() { - local -n var=$1 + local s=${1} + if [ ${s:0:1} = "C" ]; then s=${s:1}; fi + s=${s,,} + local -n var=C$1 var="\033[1;48;2;$2;$3;$4m" } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function color.set() { - local -n var=$1 + local s=${1} + if [ ${s:0:1} = "C" ]; then s=${s:1}; fi + s=${s,,} + local -n var=C$1 var="\033[1;48;2;$2;$3;$4;1;38;2;$5;$6;$7m" } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -96,7 +137,30 @@ function color.env () { var=${!v} } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bes.color.boot +function color.load () { + local file=${1:-/usr/share/bes/colors.ini} + if [ -f "$file" ]; then + local prefix="bes_colors" + bes.ini "$file" -p "$prefix" -b 1 + for name in ${bes_colors_ALL_VARS}; do + key="${name:${#prefix}+1}" + if [ "${key:0:2}" = "fg" ]; then + color.fg "${key:3}" ${!name} + elif [ "${key:0:2}" == "bg" ]; then + color.bg "${key:3}" ${!name} + elif [ "${key:0:3}" == "set" ]; then + color.set "${key:4}" ${!name} + fi + done + else + return 1 + fi +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +declare -f bes.reg > /dev/null +if [ $? -eq 0 ]; then + bes.reg bes.color +fi # # @author a-Sansara - https://git.pluie.org/meta-tech/bes-echo # @app bes-echo @@ -193,7 +257,10 @@ function echo.app () echo.sepline } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bes.echo.boot +declare -f bes.reg > /dev/null +if [ $? -eq 0 ]; then + bes.reg bes.echo +fi # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # @author a-Sansara - https://git.pluie.org/meta-tech/bes-echo @@ -543,7 +610,35 @@ function bes.build () fi echo.state $? fi - echo "#!/bin/bash" > $APP_BIN + echo "#!/bin/bash +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BES_BOOT= +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.exists () { + declare -f \$1 > /dev/null + #~ [ x\$(type -t \$1) = xfunction ]; +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.boot () +{ + for fn in \$BES_BOOT; do + if bes.exists \$fn.boot; then + \$fn.boot + fi + done +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.reg () +{ + local sep=\" \" + if [ -z \"\$BES_BOOT\" ]; then + sep=\"\" + fi + BES_BOOT=\$BES_BOOT\$sep\$1 +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +" > $APP_BIN + #~ echo "#!/bin/bash" > $APP_BIN echo.action "reading ${Coff}dependencies" if [ -d "$APP_DIR/vendor" ]; then for vendor in $(ls $APP_DIR/vendor/); do @@ -573,6 +668,8 @@ function bes.build () tail -n +2 "$entry" >> "$APP_BIN" fi done + echo "# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +bes.boot" >> "$APP_BIN" if [ -f "$APP_DIR/src/main.sh" ]; then tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" echo.msg " ${Cspe}- ${Cok}appending ${Coff}src/main.sh" @@ -778,6 +875,8 @@ function bes.usage () echo -e "${Coff}" } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +bes.boot +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # @author a-Sansara - https://git.pluie.org/meta-tech/bes-build # @app bes-build @@ -785,7 +884,7 @@ function bes.usage () # @date 2017-06-16 04:38:52 CET # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - BES_VERSION=0.8 + BES_VERSION=0.9 BES_NAME="bes-build" BES_URL="https://git.pluie.org/meta-tech/$BES_NAME/raw/latest/dist/$BES_NAME" APP_DIR=$(pwd) diff --git a/src/build.sh b/src/build.sh index 3bff0a1..db579ac 100644 --- a/src/build.sh +++ b/src/build.sh @@ -20,7 +20,35 @@ function bes.build () fi echo.state $? fi - echo "#!/bin/bash" > $APP_BIN + echo "#!/bin/bash +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BES_BOOT= +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.exists () { + declare -f \$1 > /dev/null + #~ [ x\$(type -t \$1) = xfunction ]; +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.boot () +{ + for fn in \$BES_BOOT; do + if bes.exists \$fn.boot; then + \$fn.boot + fi + done +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.reg () +{ + local sep=\" \" + if [ -z \"\$BES_BOOT\" ]; then + sep=\"\" + fi + BES_BOOT=\$BES_BOOT\$sep\$1 +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +" > $APP_BIN + #~ echo "#!/bin/bash" > $APP_BIN echo.action "reading ${Coff}dependencies" if [ -d "$APP_DIR/vendor" ]; then for vendor in $(ls $APP_DIR/vendor/); do @@ -50,6 +78,8 @@ function bes.build () tail -n +2 "$entry" >> "$APP_BIN" fi done + echo "# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +bes.boot" >> "$APP_BIN" if [ -f "$APP_DIR/src/main.sh" ]; then tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" echo.msg " ${Cspe}- ${Cok}appending ${Coff}src/main.sh" diff --git a/src/main.sh b/src/main.sh index 1c671a3..4a4119c 100755 --- a/src/main.sh +++ b/src/main.sh @@ -7,7 +7,7 @@ # @date 2017-06-16 04:38:52 CET # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - BES_VERSION=0.8 + BES_VERSION=0.9 BES_NAME="bes-build" BES_URL="https://git.pluie.org/meta-tech/$BES_NAME/raw/latest/dist/$BES_NAME" APP_DIR=$(pwd)