Newer
Older
# get location of executed file.
EXECDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# global list of gluon targets
TARGET_LIST=()
help_print(){
echo "Usage: $0 <command>"
echo "command:"
echo " patch Apply patches on gluon build ENV"
echo " clean_patches Remove applied patches from gluon repo"

Lorenz Wenner
committed
echo " update_patches Create patches from local gluon commits"
echo " prepare <command>"

Jan-Tarek Butt
committed
echo " GLUON_AUTOUPDATER_BRANCH <str> Set ENV variable"
echo " GLUON_RELEASE <str> Set ENV variable"
# echo " fastd Prepare site repo for fastd build"
echo " l2tp prepare site repo for l2tp build"
echo " BROKEN y or n (default n)"
echo " build <target> targets provided by gluon"
echo " target_list build all gluon targets"
echo " (optional) add \"fast\" as a parameter to build on multicore"
echo " (optional) add \"silent\" as a parameter to avoid loads of output"
echo " clean <target> targets provided by gluon"
echo " all clean all targets"
echo " (optional) add \"fast\" as a parameter to clean on multicore"
echo " create_manifest create manifest"
echo
}
patch_gluon() {
if ! [ -f "$EXECDIR/.patched" ]; then
if [ "$(find "$EXECDIR"/gluon_patches/*.patch 2> /dev/null | wc -l)" -ge 1 ]; then
local base="$EXECDIR"
cd "$EXECDIR"/.. || exit 1
for patch in "$EXECDIR"/gluon_patches/*.patch; do
git am --ignore-space-change --ignore-whitespace "$patch"
done
cd "$base" || exit 1
else
echo "No patches found"
fi
touch "$EXECDIR/.patched"
else
echo "gluon is already patched!"
echo "Please run clean_patches first to reset gluon git repo"
fi
}
clean_patches(){
if [ -f "$EXECDIR/.patched" ]; then
local base="$EXECDIR"
cd "$EXECDIR"/.. || exit 1
git reset --hard "origin/$(git rev-parse --abbrev-ref HEAD)"
cd "$EXECDIR" || exit 1
rm "$EXECDIR/.patched"
else
echo "gluon is not patched"
update_patches() {
local base="$EXECDIR"
cd "$EXECDIR"/.. || exit 1
git format-patch "origin/$(git rev-parse --abbrev-ref HEAD)" -o "$EXECDIR/gluon_patches"
cd "$base" || exit 1
}
init_prepare(){
local vpn="$1"
local file="$2"
if ! [ -w "$EXECDIR/$file" ]; then
echo "$EXECDIR/$file not exsis or writeable"
echo "prepare $file for $vpn build ..."
# ensure reset possible local file changes
git checkout "$EXECDIR/$file"
prepare_siteconf(){
local vpn="$1"
init_prepare "$vpn" "site.conf"
# Start prepare site.conf for build
if grep -q "%A" < "$EXECDIR"/site.conf; then
sed -i "/^%A$/c\\modules = \\'http://mirror.ffnw.de/modules/$vpn/gluon-%GS-%GR/%S\\'," "$EXECDIR"/site.conf
echo "Set opkg modules URL ..."
else
echo "Placeholder %A not found"
fi
if grep -q "%B" < "$EXECDIR"/site.conf; then
sed -i "/^%B$/c\\\\'http://autoupdate-lede.ffnw/v1/$vpn/stable\\'," "$EXECDIR"/site.conf
echo "Set autoupdater stable URL ..."
else
echo "Placeholder %B not found"
fi
if grep -q "%C" < "$EXECDIR"/site.conf; then

Jan-Tarek Butt
committed
sed -i "/^%C$/c\\\\'http://autoupdate-lede.ffnw/v1/$vpn/rc\\'," "$EXECDIR"/site.conf
echo "Set autoupdater rc URL ..."
else
echo "Placeholder %C not found"
fi
if grep -q "%D" < "$EXECDIR"/site.conf; then

Jan-Tarek Butt
committed
sed -i "/^%D$/c\\\\'http://autoupdate-lede.ffnw/v1/$vpn/testing\\'," "$EXECDIR"/site.conf
echo "Set autoupdater testing URL ..."
else
echo "Placeholder %D not found"
fi

Jan-Tarek Butt
committed
if grep -q "%E" < "$EXECDIR"/site.conf; then
sed -i "/^%E$/c\\\\'http://autoupdate-lede.ffnw/v1/$vpn/nightly/master\\'," "$EXECDIR"/site.conf
echo "Set autoupdater nightly_master URL ..."
else
echo "Placeholder %E not found"
fi
}
prepare_sitemk(){
local vpn="$1"
init_prepare "$vpn" "site.mk"
# Start prepare site.mk for build

Jan-Tarek Butt
committed
if grep -q "%A" < "$EXECDIR"/image-customization.lua; then
if [ "$vpn" == "l2tp" ]; then
sed -i "/^%A$/c\\\\t'mesh-vpn-tunneldigger'," "$EXECDIR"/image-customization.lua
echo "Set mesh-vpn-tunneldigger feature ..."
fi
if [ "$vpn" == "fastd" ]; then

Jan-Tarek Butt
committed
sed -i "/^%A$/c\\\\tweb-mesh-vpn-fastd" "$EXECDIR"/image-customization.lua
echo "Set web-mesh-vpn-fastd feature ..."
fi
else
echo "Placeholder %A not found"
if grep -q "%B" < "$EXECDIR"/site.mk; then
sed -i "/^%B$/c\\GLUON_RELEASE ?= $(cat "$EXECDIR/.GLUON_RELEASE")" "$EXECDIR"/site.mk
echo "Set GLUON_RELEASE ..."
else
echo "Placeholder %B not found"
fi
if grep -q "%C" < "$EXECDIR"/site.mk; then

Jan-Tarek Butt
committed
sed -i "/^%C$/c\\GLUON_AUTOUPDATER_BRANCH ?= $(cat "$EXECDIR/.GLUON_AUTOUPDATER_BRANCH")" "$EXECDIR"/site.mk
echo "Set GLUON_AUTOUPDATER_BRANCH ..."
else
echo "Placeholder %C not found"
fi
gluon_build(){

Jan-Tarek Butt
committed
preflags=( -C "$EXECDIR"/..)
midflags=()
postflags=(GLUON_TARGET="$1" GLUON_AUTOUPDATER_ENABLED=1 GLUON_IMAGEDIR=output/images/"$(cat "$EXECDIR"/.prepare)"/"$(cat "$EXECDIR"/.GLUON_RELEASE)" GLUON_PACKAGEDIR=output/packages/"$(cat "$EXECDIR"/.prepare)")
if [ "$2" == "fast" ] && [ -a "/proc/cpuinfo" ]; then

Jan-Tarek Butt
committed
midflags=("${midflags[@]}" -j $(($(grep -c processor /proc/cpuinfo)+1)))
if [ "$3" == "silent" ]; then

Jan-Tarek Butt
committed
preflags=( --silent "${preflags[@]}")
fi;
if [ -a "$EXECDIR/.BROKEN" ]; then

Jan-Tarek Butt
committed
midflags=("${midflags[@]}" BROKEN=1)

Jan-Tarek Butt
committed
if ! make "${preflags[@]}" "${midflags[@]}" "${postflags[@]}"; then
if [ $error_build -eq 1 ]; then
exit 1
fi

Jan-Tarek Butt
committed
preflags=( -C "$EXECDIR"/..)
midflags=()
postflags=(GLUON_TARGET="$1" GLUON_IMAGEDIR=output/images/"$(cat "$EXECDIR"/.prepare)"/"$(cat "$EXECDIR"/.GLUON_RELEASE)" GLUON_PACKAGEDIR=output/packages/"$(cat "$EXECDIR"/.prepare)")
if [ "$2" == "fast" ] && [ -a "/proc/cpuinfo" ]; then

Jan-Tarek Butt
committed
midflags=("${midflags[@]}" -j $(($(grep -c processor /proc/cpuinfo)+1)))
fi
if [ -a "$EXECDIR/.BROKEN" ]; then

Jan-Tarek Butt
committed
midflags=("${midflags[@]}" BROKEN=1)

Jan-Tarek Butt
committed
make "${preflags[@]}" "${midflags[@]}" "${postflags[@]}" clean
prepare_precondition(){

Jan-Tarek Butt
committed
if ! [ -s "$EXECDIR/.GLUON_AUTOUPDATER_BRANCH" ]; then
echo "please run '$0 prepare GLUON_AUTOUPDATER_BRANCH' first"
exit 1
fi
if ! [ -s "$EXECDIR/.GLUON_RELEASE" ]; then
echo "please run '$0 prepare GLUON_RELEASE' first"
exit 1
fi
}
get_target_list(){
while read -r line; do
if [[ $line == *GluonTarget* ]]; then
# extract arcitecture parameter value
local targ
targ="$(echo "$line" | sed -e 's/^.*GluonTarget,//' -e 's/)).*//' -r -e 's/([^,]+,[^,]*).*/\1/' -e 's/[,]/-/')"
if [ -n "$targ" ]; then
TARGET_LIST[${#TARGET_LIST[@]}]="$targ"
fi
if [[ $line == *BROKEN* ]] && ! [[ $line == *GLUON_WLAN_MESH_11s* ]] && ! [ -a "$EXECDIR/.BROKEN" ]; then
fi
done < "$EXECDIR/../targets/targets.mk"
}

Jan-Tarek Butt
committed
if ! git -C "$EXECDIR"/.. rev-parse --abbrev-ref HEAD | grep -q "$GLUON_AUTOUPDATER_BRANCH"; then
echo "no gluon repo found or wrong branch. Please clone this git repository into the gluon git repository"
exit 1
fi
case "$1" in
"patch")
patch_gluon
;;
"clean_patches")
clean_patches
;;

Lorenz Wenner
committed
"update_patches")
"prepare")
case "$2" in
# "fastd")
# prepare_precondition
# if ! [ -f "$EXECDIR/.patched" ]; then
# patch_gluon
# fi
# prepare_siteconf "$2"
# prepare_sitemk "$2"
# make -C "$EXECDIR"/.. update
# echo "$2" > "$EXECDIR/.prepare"
# ;;
"l2tp")
prepare_precondition
if ! [ -f "$EXECDIR/.patched" ]; then
patch_gluon
fi
prepare_siteconf "$2"
prepare_sitemk "$2"
make -C "$EXECDIR/.." update
echo "$2" > "$EXECDIR/.prepare"

Jan-Tarek Butt
committed
"GLUON_AUTOUPDATER_BRANCH")
if [ -n "$3" ]; then

Jan-Tarek Butt
committed
echo "$3" > "$EXECDIR/.GLUON_AUTOUPDATER_BRANCH"
else
echo "$2 needs a parameter e.g. testing"
fi
;;
"GLUON_RELEASE")
if [ -n "$3" ]; then
echo "$3" > "$EXECDIR/.GLUON_RELEASE"
else
echo "$2 needs a parameter e.g. 20170104"
fi
;;
"BROKEN")
if [ "$3" == "y" ]; then
touch "$EXECDIR/.BROKEN"
elif [ "$3" == "n" ]; then
if [ -a "$EXECDIR/.BROKEN" ]; then
rm "$EXECDIR/.BROKEN"
fi
else
echo "$2 needs the parameter: y or n"
fi
;;
*)
help_print
;;
esac
;;
"build")
if ! [ -r "$EXECDIR"/.prepare ]; then
echo "please run the prepare mode first"
exit 1
fi
get_target_list
case "$2" in
"target_list")
for targ in "${TARGET_LIST[@]}"; do
if [ "$3" == "fast" ]; then
if [ "$4" == "silent" ]; then
gluon_build "$targ" "fast" "silent"
else
gluon_build "$targ" "fast"
fi
else
gluon_build "$targ"
fi
done
;;
"all")
# "$EXECDIR/$0" prepare fastd
# "$EXECDIR/$0" build target_list "fast" "silent"
# "$EXECDIR/$0" create_manifest
"$EXECDIR/$0" prepare l2tp
"$EXECDIR/$0" build target_list "fast" "silent"
"$EXECDIR/$0" create_manifest
;;
*)
err="yes"
for targ in "${TARGET_LIST[@]}"; do
if [ "$targ" == "$2" ]; then
err="no"
if [ "$3" == "fast" ]; then
gluon_build "$targ" "fast"
else
gluon_build "$targ"
fi
fi
done
if [ "$err" == "yes" ]; then
echo "Please use targets from the following list as parameter:"
for targ in "${TARGET_LIST[@]}"; do
echo "$targ"
done
fi
;;
esac
;;
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
"clean")
if ! [ -r "$EXECDIR"/.prepare ]; then
echo "please run the prepare mode first"
exit 1
fi
get_target_list
case "$2" in
"all")
for targ in "${TARGET_LIST[@]}"; do
if [ "$3" == "fast" ]; then
gluon_clean "$targ" "fast"
else
gluon_clean "$targ"
fi
done
;;
*)
err="yes"
for targ in "${TARGET_LIST[@]}"; do
if [ "$targ" == "$2" ]; then
err="no"
if [ "$3" == "fast" ]; then
gluon_clean "$targ" "fast"
else
gluon_clean "$targ"
fi
fi
done
if [ "$err" == "yes" ]; then
echo "Please use targets from the following list as parameter:"
for targ in "${TARGET_LIST[@]}"; do
echo "$targ"
done
fi
;;
esac
;;
"create_manifest")
if ! [ -r "$EXECDIR"/.prepare ]; then
echo "please run the prepare mode first"
exit 1
fi
preflags=(-C "$EXECDIR"/..)
midflags=()
postflags=( GLUON_IMAGEDIR=output/images/"$(cat "$EXECDIR"/.prepare)"/"$(cat "$EXECDIR"/.GLUON_RELEASE)" GLUON_PACKAGEDIR=output/packages/"$(cat "$EXECDIR"/.prepare)")
if [ -a "$EXECDIR/.BROKEN" ]; then
midflags=("${midflags[@]}" BROKEN=1)
fi;
make "${preflags[@]}" manifest "${midflags[@]}" "${postflags[@]}"
# create rc branch manifest
if [ -f "$EXECDIR/../output/images/$(cat "$EXECDIR"/.prepare)/$(cat "$EXECDIR"/.GLUON_RELEASE)/sysupgrade/$(cat "$EXECDIR"/.GLUON_AUTOUPDATER_BRANCH).manifest" ]; then
cp "$EXECDIR/../output/images/$(cat "$EXECDIR"/.prepare)/$(cat "$EXECDIR"/.GLUON_RELEASE)/sysupgrade/$(cat "$EXECDIR"/.GLUON_AUTOUPDATER_BRANCH).manifest" "$EXECDIR/../output/images/$(cat "$EXECDIR"/.prepare)/$(cat "$EXECDIR"/.GLUON_RELEASE)/sysupgrade/rc.manifest"
sed -i 's/BRANCH=stable/BRANCH=rc/g' "$EXECDIR/../output/images/$(cat "$EXECDIR"/.prepare)/$(cat "$EXECDIR"/.GLUON_RELEASE)/sysupgrade/rc.manifest"
fi;