Просмотр исходного кода

add multi-site support (changing SITE meaning)

SITE variable now identifies the site repository to use, i.e. "ffpb"
(current global one) or "wag" (Warburg), etc.

The old SITE variable is now SITE_ID to identify a specific commit. The
build-version script was adapted to be backward-compatible: SITE_ID is
still written as "site=" in the version file and the new SITE is written
as "site_repo=" and defaults on "ffpb" if it not present.
Helge Jung 8 лет назад
Родитель
Сommit
b099b4068f
2 измененных файлов с 40 добавлено и 8 удалено
  1. 6 3
      build-version.sh
  2. 34 5
      build.sh

+ 6 - 3
build-version.sh

@@ -17,6 +17,7 @@ versionfile="${MY_DIR}/versions/${version}"
 base=`awk 'BEGIN { FS="=" } /^GLUON=([a-f0-9]+)(\s*#.+)?$/ { print $2; }' $versionfile | awk 'BEGIN { FS="#" } { print $1; }'`
 branch=`awk 'BEGIN { FS="=" } /^BRANCH=([a-z]+)$/ { print $2; }' $versionfile`
 version=`awk 'BEGIN { FS="=" } /^VERSION=([0-9\.\-+~a-z]+)$/ { print $2; }' $versionfile`
+site_repo=`awk 'BEGIN { FS="=" } /^SITE_REPO=([a-z]+)$/ { print $2; }' $versionfile`
 site=`awk 'BEGIN { FS="=" } /^SITE=([a-f0-9]+)(\s*#.+)?$/ { print $2; }' $versionfile | awk 'BEGIN { FS="#" } { print $1; }'`
 targets=`awk 'BEGIN { FS="=" } /^TARGETS=.+$/ { print $2; }' $versionfile`
 ts=`awk 'BEGIN { FS="=" } /^TS=.+$/ { print $2; }' $versionfile`
@@ -24,6 +25,7 @@ ts=`awk 'BEGIN { FS="=" } /^TS=.+$/ { print $2; }' $versionfile`
 [ -z "$base" ] && abort "Failed to parse Gluon base commit-id from version file."
 [ -z "$branch" ] && abort "Failed to parse branch name from version file."
 [ -z "$version" ] && abort "Failed to parse version from version file."
+[ -z "$site_repo" ] && site_repo="ffpb"
 [ -z "$site" ] && abort "Failed to parse site repo commit-id from version file."
 [ -z "$ts" ] && abort "Failed to parse timestamp from version file."
 
@@ -33,15 +35,16 @@ site="${site// /}"
 
 info "Building $branch version '$version' again ..."
 echo " * Gluon base = $base"
-echo " * Site repo  = $site"
+echo " * Site repo  = $site_repo"
+echo " * Site commit= $site"
 echo " * Timestamp  = $ts"
 echo " * Targets    = $targets"
 echo
 
 # invoke build script
 if [ "$NO_DOCKER" == "1" ]; then
-	BASE="$base" BRANCH="$branch" SITE="$site" VERSION="$version" BUILD_TS="$ts" TARGETS="$targets" BROKEN="$BROKEN" ./build.sh
+	BASE="$base" BRANCH="$branch" SITE="$site_repo" SITE_ID="$site" VERSION="$version" BUILD_TS="$ts" TARGETS="$targets" BROKEN="$BROKEN" ./build.sh
 else
-	BASE="$base" BRANCH="$branch" SITE="$site" VERSION="$version" BUILD_TS="$ts" TARGETS="$targets" BROKEN="$BROKEN" ./docker-build.sh
+	BASE="$base" BRANCH="$branch" SITE="$site_repo" SITE_ID="$site" VERSION="$version" BUILD_TS="$ts" TARGETS="$targets" BROKEN="$BROKEN" ./docker-build.sh
 fi
 

+ 34 - 5
build.sh

@@ -6,7 +6,8 @@
 #
 # BASE      = Gluon Version (tag or commit, i.e. v2014.4)
 # BRANCH    = Firmware Branch (stable/testing/experimental)
-# SITE      = specific site repository commit-id (leave blank to use HEAD)
+# SITE      = site repository to use
+# SITE_ID   = specific site repository commit-id (leave blank to use HEAD)
 # VERSION   = the version tag (can only be empty if BRANCH=experimental)
 # BUILD_TS  = build timestamp (format: %Y-%m-%d %H:%M:%S)
 # BROKEN    = 0 (default) or 1, build the untested hardware model firmwares, too
@@ -70,12 +71,39 @@ if [ ! -d "$CODE_DIR" ]; then
 fi
 
 if [ "_${SITE_REPO_FETCH_METHOD}" != "_git" ]; then
-    SITE_REPO_URL="https://git.c3pb.de/freifunk-pb/site-ffpb.git"
+	SITE_REPO_URL="https://git.c3pb.de/freifunk-pb/site-${SITE}.git"
 else
-    SITE_REPO_URL="git@git.c3pb.de:freifunk-pb/site-ffpb.git"
+	SITE_REPO_URL="git@git.c3pb.de:freifunk-pb/site-${SITE}.git"
 fi
 
 ### INIT /src/site IF NECESSARY
+if [ -d "$CODE_DIR/site" ]; then
+	# verify the site-repo is the correct one ($SITE), otherwise delete the repo
+	pushd "$CODE_DIR/site"
+	url=$(git remote show origin | awk '/Fetch URL/ { print $3; }')
+	if [ "$SITE_REPO_URL" != "$url" ]; then
+		info "The site repository is not the correct one."
+		if ! git diff-index --quiet HEAD --; then
+			popd > /dev/null
+			abort "The site repo is the wrong one but has local modifications, please fix this manually."
+		fi
+		# check on the actual branch, not the target one given as parameter
+		local_branch=$(git branch --list --no-color | awk '/^*/ { print $2; }')
+		commits=$(git log origin/${local_branch}..HEAD)
+		if [ -n "$commits" ]; then
+			popd > /dev/null
+			abort "The site repo is the wrong one but has unpushed commits, please fix this manually."
+		fi
+
+		# remove the directory without asking further questions
+		popd > /dev/null
+		rm -Rf "$CODE_DIR/site" || abort "Failed to remove wrong site-repository."
+		success "Removed old site directory in order to be able to clone the correct one."
+	else
+		popd > /dev/null
+	fi
+fi
+
 if [ ! -d "$CODE_DIR/site" ]; then
     info "Site repository does not exist, fetching it ..."
     git clone "$SITE_REPO_URL" "$CODE_DIR/site" || abort "Failed to fetch SITE repository."
@@ -98,7 +126,7 @@ GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
 progress "Checking out SITE REPO ..."
 cd site
 # TODO: check if site got modified locally and bail out if necessary
-if [ "_$SITE" == "_" ]; then
+if [ "_${SITE_ID}" == "_" ]; then
 	# no specific site given - get the most current one
 	git checkout -q $BRANCH ; git pull
 	[ "$?" -eq "0" ] || abort "Failed to get newest '$BRANCH' in site repository, mimimi."
@@ -106,7 +134,7 @@ else
 	# fetch site repo updates
 	git fetch || true
 	# commit given - use this one
-	git checkout -q $SITE || abort "Failed to checkout requested site commit, mimimi."
+	git checkout -q ${SITE_ID} || abort "Failed to checkout requested site commit, mimimi."
 fi
 SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
 
@@ -150,6 +178,7 @@ touch $(dirname ${build_info_path})
 echo "VERSION=${VERSION}" >> ${build_info_path}
 echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> ${build_info_path}
 echo "BRANCH=${BRANCH}" >> ${build_info_path}
+echo "SITE_REPO=${SITE}" >> ${build_info_path}
 echo "SITE=${SITE_COMMIT} # ${VERSION}" >> ${build_info_path}
 echo "TARGETS=${TARGETS}" >> ${build_info_path}
 echo "TS=${BUILD_TS}" >> ${build_info_path}