Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
98dd0da601 | |||
|
1ee9ac25e7 | ||
|
bc386594d9 | ||
|
8cf4729a34 | ||
|
1f795886f1 | ||
|
dd14205677 | ||
|
fa7aa891b5 | ||
|
808a6cfb90 | ||
|
9b7bf95b94 | ||
|
3d2df2da3c | ||
|
8ad1d2aaa2 | ||
|
0a0dea72c7 | ||
|
0abc7d132b | ||
|
f3c2b3ae53 | ||
|
aabfed3613 | ||
|
1df53566be |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
vendor/
|
||||||
|
.gitsy
|
77
README.md
77
README.md
|
@ -1,10 +1,14 @@
|
||||||
bes-build
|
bes-build
|
||||||
=========
|
=========
|
||||||
|
|
||||||
bes-build is a bash script to build bash program.
|
**bes-build** is a small bash bes application 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.7** **bes-build** is able to manage his own dependencies on self building process
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -26,24 +30,83 @@ 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/
|
||||||
|
|
|
|
||||||
|--- src/
|
|--- bes.ini # project information and requirements (optional)
|
||||||
|
|
|
|
||||||
|--- file1.sh
|
|--- dist/project # project build (auto generated by bes-build)
|
||||||
|--- file2.sh
|
|
|
||||||
|--- file3.sh
|
|--- src/
|
||||||
|
| |
|
||||||
|
| |--- file1.sh
|
||||||
|
| |--- file2.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
|
||||||
* we strongly recommand you to use function and prefix function name
|
* we strongly recommand you to use function and prefix function name
|
||||||
```shell
|
```shell
|
||||||
bes.install(){
|
bes.install(){
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Dependency Manager
|
||||||
|
|
||||||
|
**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
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[require]
|
||||||
|
bes.echo = 1.4
|
||||||
|
```
|
||||||
|
|
||||||
|
then you can run the `update` command before building
|
||||||
|
|
||||||
|
```shell
|
||||||
|
bes-build update
|
||||||
|
```
|
||||||
|
|
||||||
|
**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
|
||||||
|
|
||||||
|
|
||||||
|
### 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
Normal file
13
bes.ini
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[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
|
1151
dist/bes-build
vendored
1151
dist/bes-build
vendored
File diff suppressed because it is too large
Load Diff
139
src/build.sh
139
src/build.sh
|
@ -1,43 +1,148 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
bes.build(){
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
bes.echo.title "building project" "$APP_NAME"
|
function bes.build ()
|
||||||
|
{
|
||||||
|
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
|
||||||
bes.echo.action "creating dist directory"
|
echo.action "creating dist directory"
|
||||||
mkdir $APP_DIR/dist
|
mkdir $APP_DIR/dist
|
||||||
bes.echo.state $?
|
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
|
||||||
bes.echo.action "backup last build to ${Coff}dist/$(date +%y%m%d)-$APP_NAME${Coff}"
|
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
|
||||||
bes.echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
|
echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
|
||||||
rm $APP_BIN
|
rm $APP_BIN
|
||||||
fi
|
fi
|
||||||
bes.echo.state $?
|
echo.state $?
|
||||||
fi
|
fi
|
||||||
echo "#!/bin/bash" > $APP_BIN
|
echo "#!/bin/bash
|
||||||
bes.echo.action "reading ${Coff}src/"
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
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
|
||||||
|
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
|
||||||
bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)"
|
echo.msg " ${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"
|
||||||
bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/main.sh"
|
echo.msg " ${Cspe}- ${Cok}appending ${Coff}src/main.sh"
|
||||||
fi
|
fi
|
||||||
bes.echo.state 0
|
echo.state 0
|
||||||
bes.echo.action "set execution mode"
|
echo.action "set execution mode"
|
||||||
chmod +x $APP_BIN
|
chmod +x $APP_BIN
|
||||||
done=$?
|
done=$?
|
||||||
bes.echo.state $done
|
echo.state $done
|
||||||
bes.echo.rs $done
|
echo.rs $done
|
||||||
else
|
else
|
||||||
bes.echo.error "no src/ directory. exit"
|
echo.error "no src/ directory. exit"
|
||||||
bes.echo.state 1
|
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
|
||||||
}
|
}
|
||||||
|
|
114
src/display.sh
114
src/display.sh
|
@ -1,114 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
BES_TERM_WIDTH=105
|
|
||||||
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(){
|
|
||||||
bes.echo " ${Citem}☪ ${Csection}$1 ${Cspe}$2${Coff}"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
bes.echo.keyval(){
|
|
||||||
local c=': '
|
|
||||||
if [ ! "$BES_NOCOLOR" = 1 ]; then
|
|
||||||
c="$Citem: ${Cval}"
|
|
||||||
fi
|
|
||||||
bes.echo " $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.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.color.map(){
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
#!/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
|
|
||||||
}
|
|
43
src/main.sh
43
src/main.sh
|
@ -1,23 +1,52 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
BES_BUILD_VERSION=0.4
|
#
|
||||||
|
# @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
|
||||||
|
|
||||||
bes.main(){
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
function bes.main ()
|
||||||
|
{
|
||||||
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
|
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
|
||||||
echo $BES_BUILD_VERSION
|
echo $BES_VERSION
|
||||||
else
|
else
|
||||||
bes.title 'bes-build' $BES_BUILD_VERSION
|
echo.app "$BES_NAME" "$BES_VERSION"
|
||||||
echo
|
echo
|
||||||
|
enusage=0
|
||||||
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
|
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
|
||||||
bes.install "$2"
|
bes.install "$BES_NAME" "$BES_URL" "$2" "bes.build.install"
|
||||||
elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
|
elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
|
||||||
bes.usage
|
enusage=1
|
||||||
|
elif [ "$1" = "update" ] || [ "$1" = "-u" ]; then
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
90
src/new.sh
Normal file
90
src/new.sh
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
#!/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
|
||||||
|
}
|
7
src/require.sh
Normal file
7
src/require.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function bes.build.require () {
|
||||||
|
local dep=${1}
|
||||||
|
echo.msg "coming soon"
|
||||||
|
echo.rs 1
|
||||||
|
}
|
172
src/update.sh
Normal file
172
src/update.sh
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BES_LIB="color echo install ini service secure dep1 dep2"
|
||||||
|
BES_LOADED_LIB=
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
function bes.inlist ()
|
||||||
|
{
|
||||||
|
local rs=1
|
||||||
|
if [[ "$2" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]] ; then
|
||||||
|
rs=0
|
||||||
|
fi
|
||||||
|
return $rs
|
||||||
|
}
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
function bes.addLoadedLib ()
|
||||||
|
{
|
||||||
|
local sep=" "
|
||||||
|
if [ -z "$BES_LOADED_LIB" ]; then
|
||||||
|
sep=""
|
||||||
|
fi
|
||||||
|
BES_LOADED_LIB=$BES_LOADED_LIB$sep$1
|
||||||
|
}
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
function bes.loadExtDep ()
|
||||||
|
{
|
||||||
|
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 [ ! -d "$APP_DIR/vendor/$vendor" ]; then
|
||||||
|
echo.action "creating vendor directory ${Cusa}$vendor"
|
||||||
|
mkdir -p "$APP_DIR/vendor/$vendor"
|
||||||
|
echo.state $?
|
||||||
|
fi
|
||||||
|
if [ "${version:0:4}" = "http" ]; then
|
||||||
|
local req=${!name}
|
||||||
|
local path=${req#*:}
|
||||||
|
local tag=${req##*:}
|
||||||
|
local repo=${req%:*}
|
||||||
|
echo "$APP_DIR/vendor/$vendor/$project"
|
||||||
|
echo $(pwd)
|
||||||
|
if [ ! -d "$APP_DIR/vendor/$vendor/$project" ]; then
|
||||||
|
mkdir "$APP_DIR/vendor/$vendor"
|
||||||
|
cd $_
|
||||||
|
git clone $repo $project
|
||||||
|
fi
|
||||||
|
cd "$APP_DIR/vendor/$vendor/$project"
|
||||||
|
git checkout $tag
|
||||||
|
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 $?
|
||||||
|
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
|
||||||
|
echo.action "creating vendor directory ${Cusa}$vendor"
|
||||||
|
mkdir -p "$APP_DIR/vendor/$vendor"
|
||||||
|
else
|
||||||
|
echo.action "checking vendor directory ${Cusa}$vendor"
|
||||||
|
fi
|
||||||
|
echo.state $?
|
||||||
|
bescheck=0
|
||||||
|
echo "[bes_vendor]" > $APP_DIR/vendor/.bes
|
||||||
|
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
|
||||||
|
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
|
||||||
|
}
|
20
src/usage.sh
20
src/usage.sh
|
@ -1,17 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
bes.usage(){
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
function 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}\tbes-build ${Copt}
|
${Cspe}\t$BES_NAME ${Copt}
|
||||||
${Ccom}\tBuild current project and backup existing build
|
${Ccom}\tBuild current project and backup existing build
|
||||||
${Cspe}\tbes-build ${Copt}-b${Ctext}, ${Copt}backup
|
${Cspe}\t$BES_NAME ${Copt}-b${Ctext}, ${Copt}backup
|
||||||
${Ccom}\tInstall or update bes-build on specified BINDIR directory or in /etc/local/bin directory
|
${Ccom}\tInstall or update $APP_NAME on specified BINDIR directory or in /usr/local/bin directory
|
||||||
${Cspe}\tbes-build ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ]
|
${Cspe}\t$BES_NAME ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ]
|
||||||
${Ccom}\tDisplay program version
|
${Ccom}\tDisplay program version
|
||||||
${Cspe}\tbes-build ${Copt}-v${Ctext}, ${Copt}version
|
${Cspe}\t$BES_NAME ${Copt}-v${Ctext}, ${Copt}version
|
||||||
${Ccom}\tDisplay this help
|
${Ccom}\tDisplay this help
|
||||||
${Cspe}\tbes-build ${Copt}-h${Ctext}, ${Copt}help"
|
${Cspe}\t$BES_NAME ${Copt}-h${Ctext}, ${Copt}help"
|
||||||
|
|
||||||
echo -e "${Coff}"
|
echo -e "${Coff}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user