|
|
@@ -1,6 +1,8 @@
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
-set -x
|
|
|
+# -x echos commands. -u exits if an unintialized variable is used.
|
|
|
+# -e exits if a command returns an error.
|
|
|
+set -x -u -e
|
|
|
|
|
|
# Reset the PATH to macOS default. This is mainly so we don't execute the wrong
|
|
|
# gomobile executable.
|
|
|
@@ -14,7 +16,7 @@ BUILD_DIR="${BASE_DIR}/build"
|
|
|
|
|
|
# Ensure go is installed
|
|
|
which go 2>&1 > /dev/null
|
|
|
-if [ $? -ne 0 ]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "Go is not installed in the path, aborting"
|
|
|
exit 1
|
|
|
fi
|
|
|
@@ -35,9 +37,9 @@ TRUSTED_ROOT_CA_FILE=${BASE_DIR}/PsiphonTunnel/PsiphonTunnel/rootCAs.txt
|
|
|
# Download trustedroot CAs off curl website, see https://curl.haxx.se/docs/caextract.html for details
|
|
|
curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem
|
|
|
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: curl -o $TRUSTED_ROOT_CA_FILE https://curl.haxx.se/ca/cacert.pem"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
# Exporting these seems necessary for subcommands to pick them up.
|
|
|
@@ -48,7 +50,7 @@ export PATH=${GOPATH}/bin:${PATH}
|
|
|
rm -rf ${GOPATH}
|
|
|
|
|
|
# When updating the pinned rev, you will have to manually delete go-ios-build
|
|
|
-GOMOBILE_PINNED_REV=aa9922ad4c79ee8a56cd45bf433f2aa943712b09
|
|
|
+GOMOBILE_PINNED_REV=72eef9d09307f0b437153fd152229f56edc0ab20
|
|
|
GOMOBILE_PATH=${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
|
|
|
|
|
|
IOS_SRC_DIR=${GOPATH}/src/github.com/Psiphon-Labs/psiphon-ios
|
|
|
@@ -58,35 +60,35 @@ OPENSSL_SRC_DIR=${GOPATH}/src/github.com/Psiphon-Inc/openssl
|
|
|
PATH=${PATH}:${GOPATH}/bin
|
|
|
|
|
|
mkdir -p ${GOPATH}
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: mkdir -p ${GOPATH}"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
# Symlink the current source directory into GOPATH, so that we're building the
|
|
|
# code in this local repo, rather than pulling from Github and building that.
|
|
|
mkdir -p ${GOPATH}/src/github.com/Psiphon-Labs
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "mkdir -p ${GOPATH}/src/github.com/Psiphon-Labs"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
ln -s "${BASE_DIR}/../.." "${GOPATH}/src/github.com/Psiphon-Labs/psiphon-tunnel-core"
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "ln -s ../.. ${GOPATH}/src/github.com/Psiphon-Labs/psiphon-tunnel-core"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
mkdir -p ${INTERMEDIATE_OUPUT_DIR}
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: mkdir -p ${INTERMEDIATE_OUPUT_DIR}"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
if [ ! -e ${IOS_SRC_DIR} ]; then
|
|
|
echo "iOS source directory (${IOS_SRC_DIR}) not found, creating link"
|
|
|
mkdir -p $(dirname ${IOS_SRC_DIR})
|
|
|
ln -s $(pwd -P) $IOS_SRC_DIR
|
|
|
- if [ $? -ne 0 ]; then
|
|
|
+ if [[ $? != 0 ]]; then
|
|
|
echo "..Could not create symlink, aborting"
|
|
|
exit 1
|
|
|
fi
|
|
|
@@ -100,9 +102,9 @@ function strip_architectures() {
|
|
|
if ! [[ "${valid_archs}" == *"$ARCH"* ]]; then
|
|
|
echo "Stripping ARCH ${ARCH} from $1"
|
|
|
lipo -remove "$ARCH" -output "$1" "$1"
|
|
|
- rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+ if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: lipo $1"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
fi
|
|
|
done
|
|
|
@@ -115,16 +117,16 @@ strip_architectures "${LIBSSL}"
|
|
|
strip_architectures "${LIBCRYPTO}"
|
|
|
|
|
|
go get -d -u -v github.com/Psiphon-Inc/openssl
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: go get -d -u -v github.com/Psiphon-Inc/openssl"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
# Don't use -u, because this path points to our local repo, and we don't want it overridden.
|
|
|
go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
|
|
|
-rc=$?; if [[ $rc != 0 ]]; then
|
|
|
+if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi"
|
|
|
- exit $rc
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
function check_pinned_version() {
|
|
|
@@ -146,21 +148,23 @@ function check_pinned_version() {
|
|
|
fi
|
|
|
}
|
|
|
|
|
|
+set +e
|
|
|
check_pinned_version
|
|
|
-if [ $? -ne 0 ]; then
|
|
|
+rc=$?
|
|
|
+set -e
|
|
|
+if [[ rc != 0 ]]; then
|
|
|
go get -u golang.org/x/mobile/cmd/gomobile
|
|
|
cd ${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
|
|
|
git checkout master
|
|
|
- git branch -d pinned
|
|
|
git checkout -b pinned ${GOMOBILE_PINNED_REV}
|
|
|
go install
|
|
|
${GOPATH}/bin/gomobile init -v
|
|
|
- if [ $? -ne 0 ]; then
|
|
|
+ if [[ $? != 0 ]]; then
|
|
|
echo "FAILURE: ${GOPATH}/bin/gomobile init -v"
|
|
|
exit 1
|
|
|
fi
|
|
|
check_pinned_version
|
|
|
- if [ $? -ne 0 ]; then
|
|
|
+ if [[ $? != 0 ]]; then
|
|
|
echo "gomobile not found, aborting"
|
|
|
exit 1
|
|
|
fi
|