postbuild.sh: add force_version

SpaceCast team are currently cutting their own releases. Since the
person cutting the release is now the same person that creates the tree,
we want to change the build_tagged_spacecast.sh script so that the
release build is a purely readonly operation within an existing
repository. In its current version, the script creates a temporary
spacecast-$version-pvt tag before building in order to force the build
image's version string to the desired value, and removes the tag
immediately afterwards. We would like to provide a different mechanism
so that the desired version string can be passed without having to
write into the existing repository.

Change-Id: I8d957fcd20f33c3aafbd6f8b7d68b4d8ba2dd9c6
diff --git a/support/scripts/postbuild.sh b/support/scripts/postbuild.sh
index 84cc09f..d0a8e94 100755
--- a/support/scripts/postbuild.sh
+++ b/support/scripts/postbuild.sh
@@ -32,8 +32,8 @@
   exit 1;
 fi
 
-version="${PLATFORM_PREFIX}$(support/scripts/version.sh)"
-echo -n "$version" >"$TARGET_DIR/etc/version" 2>/dev/null
+version=$(support/scripts/version.sh "$TARGET_DIR/..")
+echo -n "$PLATFORM_PREFIX$version" >"$TARGET_DIR/etc/version" 2>/dev/null
 echo -n "fiberos" >"$TARGET_DIR/etc/os" 2>/dev/null
 
 if [ "$PROD" != "y" ]; then
diff --git a/support/scripts/version.sh b/support/scripts/version.sh
index 582d638..a28e57e 100755
--- a/support/scripts/version.sh
+++ b/support/scripts/version.sh
@@ -2,6 +2,12 @@
 # Returns current version being built, without leading platform string
 # For ex. "-48-pre1-test-rel-739-gf1d6349"
 
+OUTPUT_DIR="$1"
+if [ -n "$OUTPUT_DIR" -a -r "$OUTPUT_DIR/force_version" ]; then
+  echo -n "-" && cat "$OUTPUT_DIR/force_version"
+  exit
+fi
+
 if support/scripts/is-repo.sh; then
   FORALL="repo forall -c"
 elif support/scripts/is-git.sh; then