Przeglądaj źródła

add build script

Helge Jung 10 lat temu
rodzic
commit
46fee4eb3f
2 zmienionych plików z 126 dodań i 0 usunięć
  1. 98 0
      build.sh
  2. 28 0
      functions.sh

+ 98 - 0
build.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+
+if [ "_$BRANCH" == "_" ]; then
+	echo "Please specify BRANCH environment variable." >&2
+	exit 1
+fi
+
+if [ "_$BASE" == "_" ]; then
+	echo "Please specify BASE environment variable (Gluon, i.e. 'v2014.3' or commit-id)." >&2
+	exit 1
+fi
+
+if [ "_$VERSION" == "_" -a "$BRANCH" != "experimental" ]; then
+	echo "Please specify VERSION environment variable (not necessary for experimental branch)." >&2
+	exit 1
+fi
+
+MY_DIR=$(dirname $0)
+MY_DIR=$(readlink -f "$MY_DIR")
+CODE_DIR="src"
+pushd $MY_DIR > /dev/null
+
+. functions.sh
+
+if [ ! -d "$CODE_DIR" ]; then
+	info "Code directory does not exist yet - fetching Gluon ..."
+	git clone https://github.com/freifunk-gluon/gluon.git "$CODE_DIR"
+fi
+
+if [ ! -d "$CODE_DIR/site" ]; then
+        info "Site repository does not exist, fetching it ..."
+	git clone https://git.c3pb.de/freifunk-pb/site-ffpb.git "$CODE_DIR/site"
+fi
+
+### CHECKOUT GLUON
+progress "Checking out GLUON '$BASE' ..."
+cd $CODE_DIR
+# TODO: check if gluon got modified and bail out if necessary
+git fetch ; git checkout -q $BASE
+[ "$?" -eq "0" ] || abort "Failed to checkout '$BASE' gluon base version, mimimi." >&2
+GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
+
+### CHECKOUT SITE REPO
+progress "Pulling SITE REPO for '$BRANCH' ..."
+cd site
+# TODO: check if site got modified locally and bail out if necessary
+git checkout -q $BRANCH ; git pull
+[ "$?" -eq "0" ] || abort "Failed to checkout '$BRANCH' branch in site repository, mimimi."
+SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
+
+cd ..
+
+### CLEAN
+if [ "$BRANCH" != "experimental" ]; then
+	progress "Cleaning your build environment ..."
+	make clean
+fi
+
+### PREPARE
+progress "Preparing the build environment (make update) ..."
+make update
+[ "$?" -eq "0" ] || abort "Failed to update the build environment, mimimi."
+
+### BUILD TOOLCHAIN
+progress "Building toolchain if necessary (this is not possible on a fresh build) ..."
+make toolchain -j 1
+
+### BUILD FIRMWARE
+progress "Building the firmware - please stand by!"
+if [ "$BRANCH" != "experimental" ]; then
+	GLUON_BRANCH=$BRANCH GLUON_RELEASE=$VERSION make
+else
+	GLUON_BRANCH=experimental make -j 4
+fi
+
+[ "$?" -eq "0" ] || abort "Failed to build the firmware, mimimi."
+
+cd ..
+
+# write build info
+progress "Writing build info ..."
+mkdir -p "output/${BRANCH}"
+echo -en "" > "output/${BRANCH}/build_info.txt"
+echo "VERSION=${VERSION}" >> "output/${BRANCH}/build_info.txt"
+echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> "output/${BRANCH}/build_info.txt"
+echo "SITE=${SITE_COMMIT} # ${VERSION}" >> "output/${BRANCH}/build_info.txt"
+
+# compress all binaries into 7z archive
+progress "Assembling images.7z ..."
+[ -e "output/${BRANCH}/images.7z" ] && rm "output/${BRANCH}/images.7z"
+7z a "output/${BRANCH}/images.7z" ${CODE_DIR}/images/sysupgrade/*.bin ${CODE_DIR}/images/factory/*.bin
+
+# copy generated manifest
+cp "${CODE_DIR}/images/sysupgrade/${BRANCH}.manifest" "output/${BRANCH}/"
+
+success "We're done, go and checkout your new firmware in output/${BRANCH}!"
+
+popd > /dev/null

+ 28 - 0
functions.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+
+function progress {
+	echo -en "\033[1;34m➔  "
+	echo -en $*
+	echo -en "\033[0m\n"
+}
+
+function info {
+	echo -en "\033[1;36m"
+	echo -en $*
+	echo -en "\033[0m\n"
+}
+
+function success {
+	echo -en "\033[1;32m  ✔ "
+	echo -en $*
+	echo -en "\033[0m\n"
+}
+
+function abort {
+	echo -en "\033[1;31m  ✘ "
+	echo -en $*
+	echo -en "\033[0m\n"
+	popd > /dev/null
+	exit 99
+}
+