bes-build/src/update.sh

173 lines
5.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-03-02 01:26:26 +00:00
BES_LIB="color echo install ini service dep1 dep2"
BES_LOADED_LIB=
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-07-06 21:16:57 +00:00
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
2018-12-22 01:29:00 +00:00
echo.title "Loading" "${key//_/.}${Cusa} ${!name}${Coff}"
if [ ! -d "$APP_DIR/vendor/$vendor" ]; then
2018-12-22 01:29:00 +00:00
echo.action "creating vendor directory ${Cusa}$vendor"
mkdir -p "$APP_DIR/vendor/$vendor"
2018-12-22 01:29:00 +00:00
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
2018-12-22 01:29:00 +00:00
echo.msg " ${Cspe}- ${Cok}set for autoloading ${Coff}src/$(basename $entry)"
# tail -n +2 "$entry" >> "$APP_BIN"
done
2018-12-22 01:29:00 +00:00
echo.state $?
fi
fi
2018-12-22 01:29:00 +00:00
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
2018-12-22 01:29:00 +00:00
echo.title "Loading" "${key//_/.}${Cusa} ${!name}${Coff}"
if bes.inlist "$project" "$BES_LIB"; then
if bes.inlist "$project" "$BES_LOADED_LIB"; then
2018-12-22 01:29:00 +00:00
echo.action "dependencies already loaded for ${Cusa}$project"
echo
else
if [ "$bescheck" = "1" ]; then
if [ ! -d "$APP_DIR/vendor/$vendor" ]; then
2018-12-22 01:29:00 +00:00
echo.action "creating vendor directory ${Cusa}$vendor"
mkdir -p "$APP_DIR/vendor/$vendor"
else
2018-12-22 01:29:00 +00:00
echo.action "checking vendor directory ${Cusa}$vendor"
fi
2018-12-22 01:29:00 +00:00
echo.state $?
bescheck=0
echo "[bes_vendor]" > $APP_DIR/vendor/.bes
fi
echo "$project = $version" >> $APP_DIR/vendor/.bes
cd "$APP_DIR/vendor/$vendor"
2018-12-22 01:29:00 +00:00
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
2018-12-22 01:29:00 +00:00
#~ echo.state $?
cd $project
else
cd $project
git fetch --all -q 2>&1 >/dev/null
2018-12-22 01:29:00 +00:00
#~ echo.state $?
fi
2018-12-22 01:29:00 +00:00
#~ 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
2018-12-22 01:29:00 +00:00
echo.state $?
for entry in "$APP_DIR/vendor/$vendor/$project/src"/*.sh; do
2018-12-22 01:29:00 +00:00
echo.msg " ${Cspe}- ${Cok}set for autoloading ${Coff}src/$(basename $entry)"
# tail -n +2 "$entry" >> "$APP_BIN"
done
2018-12-22 01:29:00 +00:00
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
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-07-06 21:16:57 +00:00
function bes.update ()
{
2018-12-22 01:29:00 +00:00
echo.title "Reading Project" $APP_NAME
echo.keyval path $APP_DIR
2017-07-06 21:16:57 +00:00
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
2018-12-22 01:29:00 +00:00
echo.keyval $key "${!value}"
2017-07-06 21:16:57 +00:00
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
2017-07-06 21:16:57 +00:00
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
2018-12-22 01:29:00 +00:00
echo.title "Checking Dependencies"
2017-07-06 21:16:57 +00:00
for name in ${bes_ALL_VARS}; do
key=${name:${#prefix}+1}
2018-12-22 01:29:00 +00:00
echo.keyval ${key//_/.} ${!name}
2017-07-06 21:16:57 +00:00
done
echo
2017-07-06 21:16:57 +00:00
for name in ${bes_ALL_VARS}; do
bes.loadDep "$name" "$prefix"
bes.loadExtDep "$name" "$prefix"
2017-07-06 21:16:57 +00:00
done
fi
else
echo
2018-12-22 01:29:00 +00:00
echo.msg ' no bes.ini file for your project'
echo.state
fi
}