initial commit

This commit is contained in:
a-sansara 2017-04-27 00:48:05 +02:00
commit e79a367f9d
4 changed files with 285 additions and 0 deletions

40
README.md Normal file
View File

@ -0,0 +1,40 @@
bes-build
=========
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 into a single `dist/project` executable file
### Install
```
wget https://raw.githubusercontent.com/meta-tech/bes-build/master/dist/bes-build
chmod +x bes-build
sudo mv bes-build /usr/local/bin
```
### Usage
```shell
# change directory to your project
cd /home/repo/meta-tech/bes
bes-build
# you can now execute program with :
./dist/bes
```
### Requirements
using bes-build script require you to conform to these following rules :
* respect this directory structure :
```pre
project/
|
|--- src/
|
|--- file1.sh
|--- file2.sh
|--- file3.sh
```
* each `src/` shell file require a `shebang` on first line (**#!/bin/bash**)

122
dist/bes-build vendored Executable file
View File

@ -0,0 +1,122 @@
#!/bin/bash
BES_TERM_WIDTH=105
BES_NOCOLOR=0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$BES_NOCOLOR" -eq 0 ]; then
Cok="\033[0;38;5;37m"; Cko="\033[0;38;5;217m"
Coff="\033[m"; Ctitle="\033[1;48;5;23;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"
fi
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo(){
local msg=${1:-''}
local isAction=${2:-'0'}
local symbol=${3:-' *'}
if [ ! "$BES_NOCOLOR" = 1 ]; then
local c=$Cko
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
c=$Cok
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.keyval(){
local c=': '
if [ ! "$BES_NOCOLOR" = 1 ]; then
c="$Citem: ${Cval}"
fi
bes.echo " $1 $c$2" 1 " "
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.state(){
if [ "$1" = 0 ]; then
echo " done !"
else
echo " fail !"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.error(){
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.sepline(){
local char=${1:-'_'}
local width=${2:-$BES_TERM_WIDTH}
echo -ne "${Csep} "
printf "%0.s$char" $(seq 1 $width)
echo -e "${Coff}"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.title(){
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.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.sepline
}
BES_BUILD_VERSION=0.2
bes.title 'bes-build' $BES_BUILD_VERSION
APP_DIR=$(pwd)
APP_NAME=$(basename $(pwd))
APP_BIN=$APP_DIR/dist/$APP_NAME
echo
bes.echo " ${Cspe}building project ${Copt}$APP_NAME${Coff}" 0
echo
if [ -d "$APP_DIR/src" ]; then
if [ ! -d "$APP_DIR/dist" ]; then
bes.echo.action "creating dist directory"
mkdir $APP_DIR/dist
bes.echo.state $?
fi
if [ -f "$APP_BIN" ]; then
bes.echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
rm $APP_BIN
bes.echo.state $?
fi
echo "#!/bin/bash" > $APP_BIN
bes.echo.action "reading ${Coff}src/"
for entry in "$APP_DIR/src"/*.sh; do
bes.echo " - appending ${Coff}src/$(basename $entry)"
tail -n +2 "$entry" >> "$APP_BIN"
done
bes.echo.state 0
bes.echo.action "set execution mode"
chmod +x $APP_BIN
bes.echo.state $?
else
bes.echo.error "no src/ directory. exit"
bes.echo.state 1
fi
echo

84
src/display.sh Executable file
View File

@ -0,0 +1,84 @@
#!/bin/bash
BES_TERM_WIDTH=105
BES_NOCOLOR=0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$BES_NOCOLOR" -eq 0 ]; then
Cok="\033[0;38;5;37m"; Cko="\033[0;38;5;217m"
Coff="\033[m"; Ctitle="\033[1;48;5;23;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"
fi
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo(){
local msg=${1:-''}
local isAction=${2:-'0'}
local symbol=${3:-' *'}
if [ ! "$BES_NOCOLOR" = 1 ]; then
local c=$Cko
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
c=$Cok
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.keyval(){
local c=': '
if [ ! "$BES_NOCOLOR" = 1 ]; then
c="$Citem: ${Cval}"
fi
bes.echo " $1 $c$2" 1 " "
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.state(){
if [ "$1" = 0 ]; then
echo " done !"
else
echo " fail !"
fi
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.echo.error(){
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.sepline(){
local char=${1:-'_'}
local width=${2:-$BES_TERM_WIDTH}
echo -ne "${Csep} "
printf "%0.s$char" $(seq 1 $width)
echo -e "${Coff}"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bes.title(){
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.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.sepline
}

39
src/main.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
BES_BUILD_VERSION=0.2
bes.title 'bes-build' $BES_BUILD_VERSION
APP_DIR=$(pwd)
APP_NAME=$(basename $(pwd))
APP_BIN=$APP_DIR/dist/$APP_NAME
echo
bes.echo " ${Cspe}building project ${Copt}$APP_NAME${Coff}" 0
echo
if [ -d "$APP_DIR/src" ]; then
if [ ! -d "$APP_DIR/dist" ]; then
bes.echo.action "creating dist directory"
mkdir $APP_DIR/dist
bes.echo.state $?
fi
if [ -f "$APP_BIN" ]; then
bes.echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
rm $APP_BIN
bes.echo.state $?
fi
echo "#!/bin/bash" > $APP_BIN
bes.echo.action "reading ${Coff}src/"
for entry in "$APP_DIR/src"/*.sh; do
bes.echo " - appending ${Coff}src/$(basename $entry)"
tail -n +2 "$entry" >> "$APP_BIN"
done
bes.echo.state 0
bes.echo.action "set execution mode"
chmod +x $APP_BIN
bes.echo.state $?
else
bes.echo.error "no src/ directory. exit"
bes.echo.state 1
fi
echo