220 lines
6.8 KiB
Bash
Executable File
220 lines
6.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
bes.build(){
|
|
bes.echo.title "building project" "$APP_NAME"
|
|
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
|
|
if [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
|
|
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
|
|
else
|
|
bes.echo.action "removing ${Coff}dist/$APP_NAME${Coff}"
|
|
rm $APP_BIN
|
|
fi
|
|
bes.echo.state $?
|
|
fi
|
|
echo "#!/bin/bash" > $APP_BIN
|
|
bes.echo.action "reading ${Coff}src/"
|
|
for entry in "$APP_DIR/src"/*.sh; do
|
|
if [ "$(basename $entry)" != "main.sh" ]; then
|
|
bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)"
|
|
tail -n +2 "$entry" >> "$APP_BIN"
|
|
fi
|
|
done
|
|
if [ -f "$APP_DIR/src/main.sh" ]; then
|
|
tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN"
|
|
bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/main.sh"
|
|
fi
|
|
bes.echo.state 0
|
|
bes.echo.action "set execution mode"
|
|
chmod +x $APP_BIN
|
|
done=$?
|
|
bes.echo.state $done
|
|
bes.echo.rs $done
|
|
else
|
|
bes.echo.error "no src/ directory. exit"
|
|
bes.echo.state 1
|
|
fi
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
bes.usage(){
|
|
echo -e " ${Cusa}Usage :${Coff}\n
|
|
${Ccom}\tBuild current project (overwrite existing build)
|
|
${Cspe}\tbes-build ${Copt}
|
|
${Ccom}\tBuild current project and backup existing build
|
|
${Cspe}\tbes-build ${Copt}-b${Ctext}, ${Copt}backup
|
|
${Ccom}\tInstall or update bes-build on specified BINDIR directory or in /etc/local/bin directory
|
|
${Cspe}\tbes-build ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ]
|
|
${Ccom}\tDisplay program version
|
|
${Cspe}\tbes-build ${Copt}-v${Ctext}, ${Copt}version
|
|
${Ccom}\tDisplay this help
|
|
${Cspe}\tbes-build ${Copt}-h${Ctext}, ${Copt}help"
|
|
|
|
echo -e "${Coff}"
|
|
}
|
|
|
|
BES_BUILD_VERSION=0.4
|
|
APP_DIR=$(pwd)
|
|
APP_NAME=$(basename $(pwd))
|
|
APP_BIN=$APP_DIR/dist/$APP_NAME
|
|
|
|
bes.main(){
|
|
if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
|
|
echo $BES_BUILD_VERSION
|
|
else
|
|
bes.title 'bes-build' $BES_BUILD_VERSION
|
|
echo
|
|
if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
|
|
bes.install "$2"
|
|
elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
|
|
bes.usage
|
|
elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
|
|
bes.build "$1"
|
|
fi
|
|
echo
|
|
fi
|
|
}
|
|
bes.main $*
|