Compare commits

..

No commits in common. "master" and "0.5" have entirely different histories.
master ... 0.5

13 changed files with 834 additions and 1171 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
vendor/
.gitsy

View File

@ -1,13 +1,13 @@
bes-build bes-build
========= =========
**bes-build** is a small bash bes application to build bash program. bes-build is a bash script to build bash program.
the building process simply consist to append shell script files from your `src/` project directory the building process simply consist to append shell script files from your `src/` project directory
into a single `dist/project` executable file into a single `dist/project` executable file
since version **0.5** **bes-build** attempt to be a *dependency manager* like `composer` (for php projects) but in a more extra-light way since version 0.5 bes-build attempt to be a dependency manager like `composer` (for php projects) but in a more extra-light way
since version **0.7** **bes-build** is able to manage his own dependencies on self building process
### Install ### Install
@ -30,25 +30,18 @@ bes-build -h
### Requirements ### Requirements
using **bes-build** script require you to conform to these following rules : using bes-build script require you to conform to these following rules :
* respect this directory structure : * respect this directory structure :
```pre ```pre
project/ project/
|
|--- bes.ini # project information and requirements (optional)
|
|--- dist/project # project build (auto generated by bes-build)
| |
|--- src/ |--- src/
| | |
| |--- file1.sh |--- file1.sh
| |--- file2.sh |--- file2.sh
| | ... |--- file3.sh
| |--- filen.sh
|
|--- vendor/ # project dependencies (auto generated by bes-build update)
``` ```
* each `src/` shell file require a `shebang` on first line (**#!/bin/bash**) * each `src/` shell file require a `shebang` on first line (**#!/bin/bash**)
* `src/main.sh` file is append to the end of the build file * `src/main.sh` file is append to the end of the build file
@ -59,14 +52,14 @@ bes.install(){
} }
``` ```
### Dependency Manager ### Depency Manager Requirements
**note:** This functionnality is still in progress **note** This functionnality is still in progress
to use **bes-build** like a dependency manager, you need a `bes.ini` file in your application root path to use `bes-build` like a dependency manager, you need a `bes.ini` file in your application root path
```ini ```ini
[require] [require]
bes.echo = 1.4 bes.echo = 1.0
``` ```
then you can run the `update` command before building then you can run the `update` command before building
@ -75,38 +68,8 @@ then you can run the `update` command before building
bes-build update bes-build update
``` ```
**bes-build** call `git` on a `vendor` directory and clone the require lib `bes-build` call `git` on a `vendor` directory and clone the require lib
on next build, **bes-build** will append the dependencies to your dist file on next build, bes-build will append the dependencies
### External dependencies
since version 0.6 you can now add external dependencies :
```ini
[require]
test.echo = https://gitea.meta-tech.academy/meta-tech/bes-echo:master
```
### Releasing bes lib
if you intend to release your lib as a bes dependency you must provide a bes.ini file as following :
(example is taken from bes-echo)
```
[project]
vendor = bes
name = echo
version = 1.4
license = "GNU GPL v3"
author = a-Sansara
type = library
homepage = "https://gitea.meta-tech.academy/meta-tech/bes-echo"
description = "bash bes display utility library"
keywords = "bash, bes"
[require]
bes.color = 1.4
```

13
bes.ini
View File

@ -1,13 +0,0 @@
[project]
vendor = bes
name = build
version = 0.13
license = "GNU GPL v3"
author = a-Sansara
type = application
homepage = "https://gitea.meta-tech.academy/meta-tech/bes-build"
description = "bash bes build application for bash programs"
keywords = "bash, bes, build"
[require]
bes.install = 1.4

940
dist/bes-build vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,148 +1,62 @@
#!/bin/bash #!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.build () bes.build(){
{ bes.echo.title "building project" "$APP_NAME"
echo.title "building project" "$APP_NAME" if [ -d "$APP_DIR/src" ]; then
if [ -d "$APP_DIR/src" ]; then
if [ ! -d "$APP_DIR/dist" ]; then if [ ! -d "$APP_DIR/dist" ]; then
echo.action "creating dist directory" bes.echo.action "creating dist directory"
mkdir $APP_DIR/dist mkdir $APP_DIR/dist
echo.state $? bes.echo.state $?
fi fi
if [ -f "$APP_BIN" ]; then if [ -f "$APP_BIN" ]; then
if [ "$1" = "backup" ] || [ "$1" = "-b" ]; then if [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
echo.action "backup last build to ${Coff}dist/$(date +%y%m%d)-$APP_NAME${Coff}" bes.echo.action "backup last build to ${Coff}dist/$(date +%y%m%d)-$APP_NAME${Coff}"
mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME
else else
echo.action "removing ${Coff}dist/$APP_NAME${Coff}" bes.echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
rm $APP_BIN rm $APP_BIN
fi fi
echo.state $? bes.echo.state $?
fi fi
echo "#!/bin/bash echo "#!/bin/bash" > $APP_BIN
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bes.echo.action "reading ${Coff}dependencies"
BES_BOOT= for vendor in "$APP_DIR/vendor/*"; do
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$(basename $vendor)" != "." ] && [ "$(basename $vendor)" != ".." ]; then
function bes.exists () { local vendorName="$(basename $vendor)"
declare -f \$1 > /dev/null for project in "$vendor/*"; do
#~ [ x\$(type -t \$1) = xfunction ]; if [ "$(basename $project)" != "." ] && [ "$(basename $project)" != ".." ]; then
} for entry in "$project/src"/*.sh; do
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ local vendorName="$(basename $vendor)"
function bes.boot () local project="$(basename $(dirname $(dirname $entry)))"
{ bes.echo " ${Cspe}- ${Cok}appending ${Cusa}$vendorName/$project/${Coff}src/$(basename $entry)"
for fn in \$BES_BOOT; do tail -n +2 "$APP_DIR/vendor/$vendorName/$project/src/$(basename $entry)" >> "$APP_BIN"
if bes.exists \$fn.boot; then done
\$fn.boot fi
fi done
done fi
} done
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bes.echo.state 0
function bes.reg ()
{ bes.echo.action "reading ${Coff}src/"
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
if [ "$vendor" != "." ] && [ "$vendor" != ".." ]; then
for project in $(ls $APP_DIR/vendor/$vendor/); do
if [ "$project" != "." ] && [ "$project" != ".." ]; then
for entry in $(ls $APP_DIR/vendor/$vendor/$project/src/); do
local entrypath="$APP_DIR/vendor/$vendor/$project/src/$(basename $entry)"
if [ -f "$entrypath" ] && [ "${entrypath: -3}" = ".sh" ]; then
tail -n +2 "$entrypath" >> "$APP_BIN"
echo.msg " ${Cspe}- ${Cok}appending ${Cusa}$vendorName/$project/${Coff}src/$(basename $entry)"
fi
done
fi
done
fi
done
else
echo.msg " no dependencies, did you forget to run bes-build update ?"
fi
echo.state 0
echo.action "reading ${Coff}src/"
for entry in "$APP_DIR/src"/*.sh; do for entry in "$APP_DIR/src"/*.sh; do
if [ "$(basename $entry)" != "main.sh" ]; then if [ "$(basename $entry)" != "main.sh" ]; then
echo.msg " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)" bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)"
tail -n +2 "$entry" >> "$APP_BIN" tail -n +2 "$entry" >> "$APP_BIN"
fi fi
done done
echo "# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.boot" >> "$APP_BIN"
if [ -f "$APP_DIR/src/main.sh" ]; then if [ -f "$APP_DIR/src/main.sh" ]; then
tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN"
echo.msg " ${Cspe}- ${Cok}appending ${Coff}src/main.sh" bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/main.sh"
fi fi
echo.state 0 bes.echo.state 0
echo.action "set execution mode" bes.echo.action "set execution mode"
chmod +x $APP_BIN chmod +x $APP_BIN
done=$? done=$?
echo.state $done bes.echo.state $done
echo.rs $done bes.echo.rs $done
else else
echo.error "no src/ directory. exit" bes.echo.error "no src/ directory. exit"
echo.state 1 bes.echo.state 1
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.build.install ()
{
local path="/usr/share/bes/colors.ini"
if [ ! -f "$path" ]; then
local dir=$(dirname "$path")
if [ ! -d "$dir" ]; then
echo.action "Creating default bes share dir" "$Cspe$dir$Cofff"
sudo mkdir -p "$dir"
echo.state $?
fi
echo.action "Installing default colors file" "$Cspe$path$Cofff"
local tmp=$(mktemp)
echo "[set]
# background foreground
# R G B R G B
head = 53 114 160 195 223 255
headsep = 53 114 160 252 212 102
[bg]
# background
# R G B
done = 63 172 138
fail = 172 63 85
[fg]
# foreground
# R G B
title = 133 92 181
headline = 22 74 133
sep = 80 80 80
err = 194 48 64
val = 255 175 95
key = 40 168 134
action = 106 183 241
symbol = 255 175 95
item = 92 147 181
usa = 255 172 0
spe = 255 214 166
opt = 94 215 255
com = 175 135 175
text = 0 132 101
meta = 39 100 170" > "$tmp"
sudo mv "$tmp" "$path"
echo.state $?
else
echo.action "Installing default colors file" "$Cspe$path$Cofff"
echo.error "file already exists, do not rewrite."
echo.state 1
fi fi
} }

132
src/echo.sh Executable file
View File

@ -0,0 +1,132 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.echo ()
{
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
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.action ()
{
bes.echo "$1" 1
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.title ()
{
echo
bes.echo " ${Citem}${Csection}$1 ${Cspe}$2${Coff}"
echo
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 " "
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.state ()
{
local len=8
printf "%0.s " $(seq 1 $(($BES_TERM_WIDTH-${len})))
if [ "$1" = 0 ]; then
echo -e "${Cdone} OK ${Coff}"
else
echo -e "${Cfail} KO ${Coff}"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.rs ()
{
local rs=${1:-0}
if [ "$rs" -eq 0 ]; then
echo -e " ${Cdone} done ${Coff}"
else
echo -e " ${Cfail} failed ${Coff}"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.error ()
{
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.sepline ()
{
local char=${1:-'_'}
local width=${2:-$BES_TERM_WIDTH}
echo -ne "${Csep} "
printf "%0.s$char" $(seq 1 $width)
echo -e "${Coff}"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.app ()
{
local msg=${1:-''}
local version=${2:-''}
local author=${3:-'a-Sansara'}
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"
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
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.boot

290
src/ini.sh Normal file
View File

@ -0,0 +1,290 @@
#!/bin/bash
# bes alter '__' to '_'
#
# > https://github.com/rudimeier/bash_ini_parser
#
# Copyright (c) 2009 Kevin Porter / Advanced Web Construction Ltd
# (http://coding.tinternet.info, http://webutils.co.uk)
# Copyright (c) 2010-2014 Ruediger Meier <sweet_f_a@gmx.de>
# (https://github.com/rudimeier/)
#
# License: BSD-3-Clause, see LICENSE file
#
# Simple INI file parser.
#
# See README for usage.
#
#
function read_ini()
{
# Be strict with the prefix, since it's going to be run through eval
function check_prefix()
{
if ! [[ "${VARNAME_PREFIX}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] ;then
echo "read_ini: invalid prefix '${VARNAME_PREFIX}'" >&2
return 1
fi
}
function check_ini_file()
{
if [ ! -r "$INI_FILE" ] ;then
echo "read_ini: '${INI_FILE}' doesn't exist or not" \
"readable" >&2
return 1
fi
}
# enable some optional shell behavior (shopt)
function pollute_bash()
{
if ! shopt -q extglob ;then
SWITCH_SHOPT="${SWITCH_SHOPT} extglob"
fi
if ! shopt -q nocasematch ;then
SWITCH_SHOPT="${SWITCH_SHOPT} nocasematch"
fi
shopt -q -s ${SWITCH_SHOPT}
}
# unset all local functions and restore shopt settings before returning
# from read_ini()
function cleanup_bash()
{
shopt -q -u ${SWITCH_SHOPT}
unset -f check_prefix check_ini_file pollute_bash cleanup_bash
}
local INI_FILE=""
local INI_SECTION=""
# {{{ START Deal with command line args
# Set defaults
local BOOLEANS=1
local VARNAME_PREFIX=INI
local CLEAN_ENV=0
# {{{ START Options
# Available options:
# --boolean Whether to recognise special boolean values: ie for 'yes', 'true'
# and 'on' return 1; for 'no', 'false' and 'off' return 0. Quoted
# values will be left as strings
# Default: on
#
# --prefix=STRING String to begin all returned variables with (followed by '_').
# Default: INI
#
# First non-option arg is filename, second is section name
while [ $# -gt 0 ]
do
case $1 in
--clean | -c )
CLEAN_ENV=1
;;
--booleans | -b )
shift
BOOLEANS=$1
;;
--prefix | -p )
shift
VARNAME_PREFIX=$1
;;
* )
if [ -z "$INI_FILE" ]
then
INI_FILE=$1
else
if [ -z "$INI_SECTION" ]
then
INI_SECTION=$1
fi
fi
;;
esac
shift
done
if [ -z "$INI_FILE" ] && [ "${CLEAN_ENV}" = 0 ] ;then
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
if ! check_prefix ;then
cleanup_bash
return 1
fi
local INI_ALL_VARNAME="${VARNAME_PREFIX}_ALL_VARS"
local INI_ALL_SECTION="${VARNAME_PREFIX}_ALL_SECTIONS"
local INI_NUMSECTIONS_VARNAME="${VARNAME_PREFIX}_NUMSECTIONS"
if [ "${CLEAN_ENV}" = 1 ] ;then
eval unset "\$${INI_ALL_VARNAME}"
fi
unset ${INI_ALL_VARNAME}
unset ${INI_ALL_SECTION}
unset ${INI_NUMSECTIONS_VARNAME}
if [ -z "$INI_FILE" ] ;then
cleanup_bash
return 0
fi
if ! check_ini_file ;then
cleanup_bash
return 1
fi
# Sanitise BOOLEANS - interpret "0" as 0, anything else as 1
if [ "$BOOLEANS" != "0" ]
then
BOOLEANS=1
fi
# }}} END Options
# }}} END Deal with command line args
local LINE_NUM=0
local SECTIONS_NUM=0
local SECTION=""
# IFS is used in "read" and we want to switch it within the loop
local IFS=$' \t\n'
local IFS_OLD="${IFS}"
# we need some optional shell behavior (shopt) but want to restore
# current settings before returning
local SWITCH_SHOPT=""
pollute_bash
while read -r line || [ -n "$line" ]
do
#echo line = "$line"
((LINE_NUM++))
# Skip blank lines and comments
if [ -z "$line" -o "${line:0:1}" = ";" -o "${line:0:1}" = "#" ]
then
continue
fi
# Section marker?
if [[ "${line}" =~ ^\[[a-zA-Z0-9_]{1,}\]$ ]]
then
# Set SECTION var to name of section (strip [ and ] from section marker)
SECTION="${line#[}"
SECTION="${SECTION%]}"
eval "${INI_ALL_SECTION}=\"\${${INI_ALL_SECTION}# } $SECTION\""
((SECTIONS_NUM++))
continue
fi
# Are we getting only a specific section? And are we currently in it?
if [ ! -z "$INI_SECTION" ]
then
if [ "$SECTION" != "$INI_SECTION" ]
then
continue
fi
fi
# Valid var/value line? (check for variable name and then '=')
if ! [[ "${line}" =~ ^[a-zA-Z0-9._]{1,}[[:space:]]*= ]]
then
echo "Error: Invalid line:" >&2
echo " ${LINE_NUM}: $line" >&2
cleanup_bash
return 1
fi
# split line at "=" sign
IFS="="
read -r VAR VAL <<< "${line}"
IFS="${IFS_OLD}"
# delete spaces around the equal sign (using extglob)
VAR="${VAR%%+([[:space:]])}"
VAL="${VAL##+([[:space:]])}"
VAR=$(echo $VAR)
# Construct variable name:
# ${VARNAME_PREFIX}_$SECTION_$VAR
# Or if not in a section:
# ${VARNAME_PREFIX}_$VAR
# In both cases, full stops ('.') are replaced with underscores ('_')
if [ -z "$SECTION" ]
then
VARNAME=${VARNAME_PREFIX}_${VAR//./_}
else
VARNAME=${VARNAME_PREFIX}_${SECTION}_${VAR//./_}
fi
eval "${INI_ALL_VARNAME}=\"\${${INI_ALL_VARNAME}# } ${VARNAME}\""
if [[ "${VAL}" =~ ^\".*\"$ ]]
then
# remove existing double quotes
VAL="${VAL##\"}"
VAL="${VAL%%\"}"
elif [[ "${VAL}" =~ ^\'.*\'$ ]]
then
# remove existing single quotes
VAL="${VAL##\'}"
VAL="${VAL%%\'}"
elif [ "$BOOLEANS" = 1 ]
then
# Value is not enclosed in quotes
# Booleans processing is switched on, check for special boolean
# values and convert
# here we compare case insensitive because
# "shopt nocasematch"
case "$VAL" in
yes | true | on )
VAL=1
;;
no | false | off )
VAL=0
;;
esac
fi
# enclose the value in single quotes and escape any
# single quotes and backslashes that may be in the value
VAL="${VAL//\\/\\\\}"
VAL="\$'${VAL//\'/\'}'"
eval "$VARNAME=$VAL"
done <"${INI_FILE}"
# return also the number of parsed sections
eval "$INI_NUMSECTIONS_VARNAME=$SECTIONS_NUM"
cleanup_bash
}
# < https://github.com/rudimeier/bash_ini_parser
bes.ini(){
read_ini $*
}

26
src/install.sh Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.install(){
local path=${1:-/usr/local/bin}
local done=1
bes.echo.title "Installing bes-build ${Coff}in" "$path"
if [ -f "./bes-build" ]; then
rm ./bes-build
fi
wget -q https://git.pluie.org/meta-tech/bes-build/raw/latest/dist/bes-build
if [ $? -eq 0 ]; then
chmod +x ./bes-build
if [ -d $path ]; then
sudo mv ./bes-build $path/bes-build
local done=$?
bes.echo.state $done
else
bes.echo.error "install directory do not exists : ${Cspe}$path"
fi
else
bes.echo.error "can not download latest version of bes-build"
fi
bes.echo.rs $done
}

View File

@ -1,52 +1,27 @@
#!/bin/bash #!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# BES_BUILD_VERSION=0.5
# @author a-Sansara - https://gitea.meta-tech.academy/meta-tech/bes-build
# @app bes-build
# @license GNU GPL v3
# @date 2017-06-16 04:38:52 CET
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_VERSION=0.13
BES_NAME="bes-build"
BES_URL="https://gitea.meta-tech.academy/meta-tech/$BES_NAME/raw/latest/dist/$BES_NAME"
APP_DIR=$(pwd) APP_DIR=$(pwd)
APP_NAME=$(basename $(pwd)) APP_NAME=$(basename $(pwd))
APP_BIN=$APP_DIR/dist/$APP_NAME APP_BIN=$APP_DIR/dist/$APP_NAME
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.main () bes.main(){
{
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
echo $BES_VERSION echo $BES_BUILD_VERSION
else else
echo.app "$BES_NAME" "$BES_VERSION" bes.echo.app 'bes-build' $BES_BUILD_VERSION
echo echo
enusage=0
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
bes.install "$BES_NAME" "$BES_URL" "$2" "bes.build.install" bes.install "$2"
elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
enusage=1 bes.usage
elif [ "$1" = "update" ] || [ "$1" = "-u" ]; then elif [ "$1" = "update" ] || [ "$1" = "-u" ]; then
bes.update bes.update
elif [ "$1" = "new" ] || [ "$1" = "-n" ]; then
if [ ! -z "$2" ]; then
bes.build.new $2
else
enusage=1
fi
elif [ "$1" = "require" ] || [ "$1" = "-r" ]; then
if [ ! -z "$2" ]; then
bes.build.require $2
else
enusage=1
fi
elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
bes.build "$1" bes.build "$1"
fi fi
if [ "$enusage" = "1" ]; then
bes.usage
fi
echo echo
fi fi
} }

View File

@ -1,90 +0,0 @@
#!/bin/bash
function bes.build.new () {
local prj=${1}
echo.title "creating new project" "$prj"
if [ -d "$APP_DIR/$prj" ]; then
echo.error "directory $prj already exists" 1
else
echo.action "creating directory" "$prj" "*" "Cusa"
mkdir "$APP_DIR/$prj"
echo.state $?
echo.action "creating project config file" "bes.ini" "*" "Cusa"
echo -e "[project]
vendor =
name = $prj
version = 0.1
license = \"GNU GPL v3\"
author =
type = application
homepage =
description = \"bash bes $prj application\"
keywords = \"bash $prj\"
[require]
bes.install = 1.4
" > "$APP_DIR/$prj/bes.ini"
echo.state $?
echo.action "Creating directory" "src" "*" "Cusa"
mkdir $APP_DIR/$prj/src
echo.state $?
echo.action "Adding default templates" "main" "*" "Cusa"
echo "#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_VERSION=0.1
BES_AUTHOR=me
BES_LICENSE=MIT
BES_NAME=\"$prj\"
BES_URL=\"https://your.forge.git/vendor/\$BES_NAME/raw/latest/dist/\$BES_NAME\"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function $prj.main ()
{
echo.msg \"hello bes\" \"\$Citem\"
echo.rs \$?
echo
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.main ()
{
if [ \"\$1\" = \"version\" ] || [ \"\$1\" = \"-v\" ]; then
echo \$BES_VERSION
else
echo.app \"\$BES_NAME\" \"\$BES_VERSION\" \"\$BES_AUTHOR\" \"\$BES_LICENSE\"
echo
if [ \"\$1\" = \"install\" ] || [ \"\$1\" = \"-i\" ]; then
bes.install \"\$BES_NAME\" \"\$BES_URL\" \"\$2\"
elif [ \"\$1\" = \"help\" ] || [ \"\$1\" = \"-h\" ]; then
$prj.usage
else
$prj.main
fi
echo
fi
}
bes.main \$*
" > "$APP_DIR/$prj/src/main.sh"
echo.state $?
echo.action "Adding default template" "usage" "*" "Cusa"
echo "#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function $prj.usage ()
{
echo -e \" \${Cusa}Usage :\${Coff}\n
\${Ccom}\tInstall or update \$BES_NAME on specified BINDIR directory or in /usr/local/bin directory
\${Cspe}\t\$BES_NAME \${Copt}-i\${Ctext}, \${Copt}install \${Copt}[ \${Ctext}BINDIR\${Copt} ]
\${Ccom}\tDisplay program version
\${Cspe}\t\$BES_NAME \${Copt}-v\${Ctext}, \${Copt}version
\${Ccom}\tDisplay this help
\${Cspe}\t\$BES_NAME \${Copt}-h\${Ctext}, \${Copt}help\"
echo -e \"${Coff}\"
}
" > "$APP_DIR/$prj/src/usage.sh"
echo.state $?
echo.rs $?
echo
fi
}

View File

@ -1,7 +0,0 @@
#!/bin/bash
function bes.build.require () {
local dep=${1}
echo.msg "coming soon"
echo.rs 1
}

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
BES_LIB="color echo install ini service secure dep1 dep2" BES_LIB="echo"
BES_LOADED_LIB=
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.inlist () bes.inlist ()
{ {
local rs=1 local rs=1
if [[ "$2" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]] ; then if [[ "$2" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]] ; then
@ -12,161 +12,83 @@ function bes.inlist ()
return $rs return $rs
} }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.addLoadedLib () bes.update ()
{ {
local sep=" " bes.ini $APP_DIR/bes.ini -p bes -b 1
if [ -z "$BES_LOADED_LIB" ]; then
sep="" bes.echo.title "Reading Project" $APP_NAME
fi bes.echo.keyval path $APP_DIR
BES_LOADED_LIB=$BES_LOADED_LIB$sep$1 local keys="vendor name version license author"
} local value=""
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for key in $keys; do
function bes.loadExtDep () value="bes_project_$key"
{ if [ ! -z "${!value}" ]; then
local name=$1 bes.echo.keyval $key "${!value}"
local prefix=$2
local key=${name:${#prefix}+1}
local project=${key#*_}
local vendor=${key%_*}
local version=${!name}
if [ ! "$vendor" = "bes" ]; then
echo.title "Loading" "${key//_/.}${Cusa} ${!name}${Coff}"
if [ ! -d "$APP_DIR/vendor/$vendor" ]; then
echo.action "creating vendor directory ${Cusa}$vendor"
mkdir -p "$APP_DIR/vendor/$vendor"
echo.state $?
fi fi
if [ "${version:0:4}" = "http" ]; then done
local req=${!name}
local path=${req#*:} bes.ini "$APP_DIR/bes.ini" require -p bes -b 1
local tag=${req##*:} local prefix="bes_require"
local repo=${req%:*} local key=""
echo "$APP_DIR/vendor/$vendor/$project" if [ ! -z "${bes_ALL_VARS}" ]; then
echo $(pwd) bes.echo.title "Checking Dependencies"
if [ ! -d "$APP_DIR/vendor/$vendor/$project" ]; then for name in ${bes_ALL_VARS}; do
mkdir "$APP_DIR/vendor/$vendor" key=${name:${#prefix}+1}
cd $_ bes.echo.keyval ${key//_/.} ${!name}
git clone $repo $project echo
fi local project=${key#*_}
cd "$APP_DIR/vendor/$vendor/$project" local vendor=${key%_*}
git checkout $tag local version=${!name}
for entry in "$APP_DIR/vendor/$vendor/$project/src"/*.sh; do
echo.msg " ${Cspe}- ${Cok}set for autoloading ${Coff}src/$(basename $entry)" if [ "$vendor" = "bes" ]; then
# tail -n +2 "$entry" >> "$APP_BIN" if bes.inlist "$project" "$BES_LIB"; then
done
echo.state $?
fi
fi
echo.rs
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.loadDep ()
{
local name=$1
local prefix=$2
local key=${name:${#prefix}+1}
local project=${key#*_}
local vendor=${key%_*}
local version=${!name}
if [ "$vendor" = "bes" ]; then
echo.title "Loading" "${key//_/.}${Cusa} ${!name}${Coff}"
if bes.inlist "$project" "$BES_LIB"; then
if bes.inlist "$project" "$BES_LOADED_LIB"; then
echo.action "dependencies already loaded for ${Cusa}$project"
echo
else
if [ "$bescheck" = "1" ]; then
if [ ! -d "$APP_DIR/vendor/$vendor" ]; then if [ ! -d "$APP_DIR/vendor/$vendor" ]; then
echo.action "creating vendor directory ${Cusa}$vendor" bes.echo.action "creating vendor directory ${Cusa}$vendor"
mkdir -p "$APP_DIR/vendor/$vendor" mkdir -p "$APP_DIR/vendor/$vendor"
else else
echo.action "checking vendor directory ${Cusa}$vendor" bes.echo.action "checking vendor directory ${Cusa}$vendor"
fi fi
echo.state $? bes.echo.state $?
bescheck=0 cd "$APP_DIR/vendor/$vendor"
echo "[bes_vendor]" > $APP_DIR/vendor/.bes bes.echo.action "updating repository $Cusa$vendor.$project ${Coff}:$Cusa $version"
if [ ! -d "$project" ]; then
git clone -q "https://git.pluie.org/meta-tech/$vendor-$project" "$project" 2>&1 >/dev/null
#~ bes.echo.state $?
cd $project
else
cd $project
git fetch --all -q 2>&1 >/dev/null
#~ bes.echo.state $?
fi
#~ bes.echo.action "checkout to version $Cusa$version"
local branch=$(git branch --no-color | grep \* | cut -d ' ' -f2-)
# branch=${branch:5: -3}
if [ "$branch" != "$version" ]; then
git checkout -q -b $version 2>&1 >/dev/null
fi
bes.echo.state $?
for entry in "$APP_DIR/vendor/$vendor/$project/src"/*.sh; do
bes.echo " ${Cspe}- ${Cok}set for autoloading ${Coff}src/$(basename $entry)"
# tail -n +2 "$entry" >> "$APP_BIN"
done
bes.echo.state $?
fi fi
echo "$project = $version" >> $APP_DIR/vendor/.bes
cd "$APP_DIR/vendor/$vendor"
echo.action "updating repository $Cusa$vendor.$project ${Coff}:$Cusa $version"
if [ ! -d "$project" ]; then
git clone -q "https://gitea.meta-tech.academy/meta-tech/$vendor-$project" "$project" 2>&1 >/dev/null
#~ echo.state $?
cd $project
else
cd $project
git fetch --all -q 2>&1 >/dev/null
#~ echo.state $?
fi
#~ echo.action "checkout to version $Cusa$version"
local branch=$(git branch --no-color | grep \* | cut -d ' ' -f2-)
# branch=${branch:5: -3}
if [ "$branch" != "$version" ]; then
git checkout -q $version 2>&1 >/dev/null
fi
echo.state $?
for entry in "$APP_DIR/vendor/$vendor/$project/src"/*.sh; do
echo.msg " ${Cspe}- ${Cok}set for autoloading ${Coff}src/$(basename $entry)"
# tail -n +2 "$entry" >> "$APP_BIN"
done
echo.state $?
bes.addLoadedLib $project
bes.ini "$APP_DIR/vendor/$vendor/$project/bes.ini" require -p bes$project -b 1
local suballvarname=bes${project}_ALL_VARS
for subname in ${!suballvarname}; do
bes.loadDep "$subname" "bes${project}_require"
done
fi
fi
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.update ()
{
echo.title "Reading Project" $APP_NAME
echo.keyval path $APP_DIR
if [ -f $APP_DIR/bes.ini ]; then
bes.ini $APP_DIR/bes.ini -p bes -b 1
local keys="vendor name version license author"
local value=""
for key in $keys; do
value="bes_project_$key"
if [ ! -z "${!value}" ]; then
echo.keyval $key "${!value}"
fi fi
bes.echo.rs
local req=${!name}
local path=${req#*:}
local repo=${req%:*}
local repoName=bes_repo_$repo
local repoVar=${!repoName}
local src=${!repoName}$path
#~ echo "$name : ${!name}"
#~ echo "\$req : ${req}"
#~ echo "\$repo : ${repo}"
#~ echo "\$path : ${path}"
#~ echo "\$repoName : ${repoName}"
#~ echo "\$repoVar : ${repoVar}"
#~ echo "\$src : ${src}"
done done
if [ -f "$APP_DIR/vendor/.bes" ]; then
bes.ini "$APP_DIR/vendor/.bes" bes_vendor -p bessed -b 1
local prefix="bes_vendor"
for name in ${bessed_ALL_VARS}; do
local key=${name:${#prefix}+1}
local project=${key#*_}
bes.addLoadedLib "$project"
done
fi
bes.ini "$APP_DIR/bes.ini" require -p bes -b 1
local prefix="bes_require"
local key=""
local bescheck=1;
if [ ! -z "${bes_ALL_VARS}" ]; then
echo.title "Checking Dependencies"
for name in ${bes_ALL_VARS}; do
key=${name:${#prefix}+1}
echo.keyval ${key//_/.} ${!name}
done
echo
for name in ${bes_ALL_VARS}; do
bes.loadDep "$name" "$prefix"
bes.loadExtDep "$name" "$prefix"
done
fi
else
echo
echo.msg ' no bes.ini file for your project'
echo.state
fi fi
} }

View File

@ -1,23 +1,18 @@
#!/bin/bash #!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bes.usage () bes.usage(){
{
echo -e " ${Cusa}Usage :${Coff}\n echo -e " ${Cusa}Usage :${Coff}\n
${Ccom}\tCreate new bes project
${Cspe}\t$BES_NAME ${Copt}-n${Ctext}, ${Copt}new ${Copt}[ ${Ctext}PROJECT_NAME${Copt} ]
${Ccom}\tUpdate current project dependencies
${Cspe}\t$BES_NAME ${Copt}-u${Ctext}, ${Copt}update
${Ccom}\tBuild current project (overwrite existing build) ${Ccom}\tBuild current project (overwrite existing build)
${Cspe}\t$BES_NAME ${Copt} ${Cspe}\tbes-build ${Copt}
${Ccom}\tBuild current project and backup existing build ${Ccom}\tBuild current project and backup existing build
${Cspe}\t$BES_NAME ${Copt}-b${Ctext}, ${Copt}backup ${Cspe}\tbes-build ${Copt}-b${Ctext}, ${Copt}backup
${Ccom}\tInstall or update $APP_NAME on specified BINDIR directory or in /usr/local/bin directory ${Ccom}\tInstall or update bes-build on specified BINDIR directory or in /etc/local/bin directory
${Cspe}\t$BES_NAME ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ] ${Cspe}\tbes-build ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ]
${Ccom}\tDisplay program version ${Ccom}\tDisplay program version
${Cspe}\t$BES_NAME ${Copt}-v${Ctext}, ${Copt}version ${Cspe}\tbes-build ${Copt}-v${Ctext}, ${Copt}version
${Ccom}\tDisplay this help ${Ccom}\tDisplay this help
${Cspe}\t$BES_NAME ${Copt}-h${Ctext}, ${Copt}help" ${Cspe}\tbes-build ${Copt}-h${Ctext}, ${Copt}help"
echo -e "${Coff}" echo -e "${Coff}"
} }