Add format_binary_url.sh (#1331)
diff --git a/PSOL_BINARY_URL b/PSOL_BINARY_URL
index 07e34fc..3663eb1 100644
--- a/PSOL_BINARY_URL
+++ b/PSOL_BINARY_URL
@@ -1,4 +1,4 @@
 In a release this file would contain the URL to download the pre-compiled PSOL
 binary, but on development branches (like this one) you have to build PSOL from
 source yourself.  See:
-  https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-Source
\ No newline at end of file
+  https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-Source
diff --git a/config b/config
index bbe570f..2efec19 100644
--- a/config
+++ b/config
@@ -26,7 +26,8 @@
   if [ ! -e "$mod_pagespeed_dir" ] ; then
     echo "ngx_pagespeed: pagespeed optimization library not found:"
 
-    psol_binary_url="$(cat $ngx_addon_dir/PSOL_BINARY_URL)"
+    psol_binary_url="$($ngx_addon_dir/scripts/format_binary_url.sh \
+                           $ngx_addon_dir/PSOL_BINARY_URL)"
     if [[ "$psol_binary_url" != https://* ]]; then
       echo "
   This is a development branch of ngx_pagespeed, which means there is no
diff --git a/scripts/build_ngx_pagespeed.sh b/scripts/build_ngx_pagespeed.sh
index edf3314..6df92f4 100755
--- a/scripts/build_ngx_pagespeed.sh
+++ b/scripts/build_ngx_pagespeed.sh
@@ -428,7 +428,7 @@
   elif [ -e PSOL_BINARY_URL ]; then
     # Releases after 1.11.33.4 there is a PSOL_BINARY_URL file that tells us
     # where to look.
-    psol_url="$(cat PSOL_BINARY_URL)"
+    psol_url="$(scripts/format_binary_url.sh PSOL_BINARY_URL)"
     if [[ "$psol_url" != https://* ]]; then
       fail "Got bad psol binary location information: $psol_url"
     fi
diff --git a/scripts/format_binary_url.sh b/scripts/format_binary_url.sh
new file mode 100755
index 0000000..d56286d
--- /dev/null
+++ b/scripts/format_binary_url.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+set -e
+set -u
+
+if [ $# -ne 1 ]; then
+  echo "Usage: $(basename $0) <url_file>" >&2
+  exit 1
+fi
+
+url_file=$1
+
+if [ ! -e "$url_file" ]; then
+  echo "Url file '$url_file' missing!" >&2
+fi
+
+# The size names must match install/build_psol.sh in mod_pagespeed
+if [ "$(uname -m)" = x86_64 ]; then
+  bit_size_name=x64
+else
+  bit_size_name=ia32
+fi
+
+sed -e 's/$BIT_SIZE_NAME\b/'$bit_size_name'/g' $url_file