Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 209 lines (170 sloc) 8.49 KB
#!/bin/bash -x
source scripts/env
##
# Build release numbers should follow the convention expected by couch-android-launcher.
# E.g., 8-1.1 which translates to "build for froyo, version 1.1"
#
if [ -z "$1" ]; then
echo "Give me a release number bub!"
exit 1
fi
if [ -z "$2" ]; then
echo "Give me a release number for OTP/Erlang bub!"
exit 1
fi
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
OVERLAY_NAME="overlay-$DATE"
OVERLAY_PATH="out/$OVERLAY_NAME"
INSTALL_PATH="$OVERLAY_PATH/assets/install"
COUCHBASE_NAME="Couchbase"
BUILD_VERSION=$(git describe --tags --always)
cd $COUCH_ANDROID_HOME
# Now build the overlay.zip
mkdir -p $OVERLAY_PATH
mkdir -p $INSTALL_PATH
mkdir -p $INSTALL_PATH/couchdb/bin/
mkdir -p $INSTALL_PATH/couchdb/etc/
cp -Rdp /data/data/%app_name%/couchdb/etc/couchdb $INSTALL_PATH/couchdb/etc/couchdb
mkdir -p $INSTALL_PATH/couchdb/etc/
cp -Rdp /data/data/%app_name%/couchdb/etc/default $INSTALL_PATH/couchdb/etc/default
mkdir -p $INSTALL_PATH/couchdb/lib/couchdb/bin/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/bin/couchjs $INSTALL_PATH/couchdb/lib/couchdb/bin/couchjs
mkdir -p $INSTALL_PATH/couchdb/share/couchdb/
cp -Rdp /data/data/%app_name%/couchdb/share/couchdb/server $INSTALL_PATH/couchdb/share/couchdb/server
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/couch-*/priv/couchspawnkillable $INSTALL_PATH
mkdir -p $INSTALL_PATH/erlang/bin/
# Generate start.boot
[[ -f patches/start.boot ]] && rm patches/start.boot
cd patches
sh script2boot.sh
cd ..
cp patches/start.boot $INSTALL_PATH/erlang/bin/start.boot
cp build/deps/otp_rel/erts-5.8.5/bin/child_setup $INSTALL_PATH/erlang/bin/child_setup
cp build/deps/otp_rel/erts-5.8.5/bin/inet_gethost $INSTALL_PATH/erlang/bin/inet_gethost
# Create an android default config file
ANDROID_DEFAULT='[couchdb]
database_dir = %couch_data_dir%/db
view_index_dir = %couch_data_dir%/db
util_driver_dir = %couch_installation_dir%/
uri_file = %couch_data_dir%/db/couch.uri
file_compression = none
[httpd]
port = 0
bind_address = 0.0.0.0
[log]
file = %couch_data_dir%/db/couch.log
level = debug
[access_log]
file = %couch_data_dir%/db/couch_access.log
[query_servers]
javascript = %couch_installation_dir%/couchdb/bin/couchjs_wrapper %couch_installation_dir%/couchdb/share/couchdb/server/main.js
coffeescript = %couch_installation_dir%/couchdb/bin/couchjs %couch_installation_dir%/couchdb/share/couchdb/server/main-coffee.js
[daemons]
spatial_manager={couch_spatial, start_link, []}
[httpd_db_handlers]
_spatial_cleanup = {couch_httpd_spatial, handle_spatial_cleanup_req}
[httpd_design_handlers]
_spatial = {couch_httpd_spatial, handle_spatial_req}
_spatial/_list = {couch_httpd_spatial_list, handle_spatial_list_req}
_spatial/_info = {couch_httpd_spatial, handle_design_info_req}
_spatial/_compact = {couch_httpd_spatial, handle_compact_req}
;deprecated API
_spatiallist = {couch_httpd_spatial_list, handle_spatial_list_req_deprecated}'
echo "$ANDROID_DEFAULT" >> $INSTALL_PATH/couchdb/etc/couchdb/android.default.ini
touch $INSTALL_PATH/couchdb/etc/couchdb/overrides.ini
# Create couchjs_wrapper script (because we can't link to libmozjs.a and so need LD_LIBRARY_PATH set)
COUCHJS_WRAPPER='#!/system/bin/sh
export LD_LIBRARY_PATH=%couch_installation_dir%/lib
exec %couch_installation_dir%/couchdb/lib/couchdb/bin/couchjs $@'
echo "$COUCHJS_WRAPPER" >> $INSTALL_PATH/couchdb/bin/couchjs_wrapper
chmod +x $INSTALL_PATH/couchdb/bin/couchjs_wrapper
###
# 3) Update #!/bin/sh in data/data/$APP_NAME/erlang/lib/couch-1.0.1/priv/couchspawnkillable
# 4) Reflect new locations and the Android environment
#
[[ -f release ]] && rm release
ln -s $INSTALL_PATH release
patch -lp0 < patches/release.patch
rm release
mkdir -p $OVERLAY_PATH/assets/lib/couch/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/couch-*/ebin $OVERLAY_PATH/assets/lib/couch/ebin
mkdir -p $OVERLAY_PATH/assets/lib/crypto-2.0.3/
cp -Rdp build/deps/otp_rel/lib/crypto-2.0.3/ebin $OVERLAY_PATH/assets/lib/crypto-2.0.3/ebin
mkdir -p $OVERLAY_PATH/assets/lib/ejson-0.1.0/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/ejson-0.1.0/ebin $OVERLAY_PATH/assets/lib/ejson-0.1.0/ebin
mkdir -p $OVERLAY_PATH/assets/lib/erlang-oauth/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/erlang-oauth/ebin $OVERLAY_PATH/assets/lib/erlang-oauth/ebin
mkdir -p $OVERLAY_PATH/assets/lib/ibrowse-2.2.0/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/ibrowse-2.2.0/ebin $OVERLAY_PATH/assets/lib/ibrowse-2.2.0/ebin
mkdir -p $OVERLAY_PATH/assets/lib/inets-5.7/ebin
cp -Rdp build/deps/otp_rel/lib/inets-5.7/ebin/httpd_util.beam $OVERLAY_PATH/assets/lib/inets-5.7/ebin
cp -Rdp build/deps/otp_rel/lib/inets-5.7/ebin/inets.app $OVERLAY_PATH/assets/lib/inets-5.7/ebin
cp -Rdp build/deps/otp_rel/lib/inets-5.7/ebin/http_uri.beam $OVERLAY_PATH/assets/lib/inets-5.7/ebin
cp -Rdp build/deps/otp_rel/lib/inets-5.7/ebin/inets_regexp.beam $OVERLAY_PATH/assets/lib/inets-5.7/ebin
cp -Rdp build/deps/otp_rel/lib/inets-5.7/ebin/http_util.beam $OVERLAY_PATH/assets/lib/inets-5.7/ebin
mkdir -p $OVERLAY_PATH/assets/lib/kernel-2.14.5/
cp -Rdp build/deps/otp_rel/lib/kernel-2.14.5/ebin $OVERLAY_PATH/assets/lib/kernel-2.14.5/ebin
mkdir -p $OVERLAY_PATH/assets/lib/mochiweb-1.4.1/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/mochiweb-1.4.1/ebin $OVERLAY_PATH/assets/lib/mochiweb-1.4.1/ebin
mkdir -p $OVERLAY_PATH/assets/lib/os_mon-2.2.6/
cp -Rdp build/deps/otp_rel/lib/os_mon-2.2.6/ebin $OVERLAY_PATH/assets/lib/os_mon-2.2.6/ebin
mkdir -p $OVERLAY_PATH/assets/lib/public_key-0.12/
cp -Rdp build/deps/otp_rel/lib/public_key-0.12/ebin $OVERLAY_PATH/assets/lib/public_key-0.12/ebin
mkdir -p $OVERLAY_PATH/assets/lib/sasl-2.1.9.4/
cp -Rdp build/deps/otp_rel/lib/sasl-2.1.9.4/ebin $OVERLAY_PATH/assets/lib/sasl-2.1.9.4/ebin
mkdir -p $OVERLAY_PATH/assets/lib/snappy-1.0.3/
cp -Rdp /data/data/%app_name%/couchdb/lib/couchdb/erlang/lib/snappy-1.0.3/ebin $OVERLAY_PATH/assets/lib/snappy-1.0.3/ebin
mkdir -p $OVERLAY_PATH/assets/lib/ssl-4.1.6/
cp -Rdp build/deps/otp_rel/lib/ssl-4.1.6/ebin $OVERLAY_PATH/assets/lib/ssl-4.1.6/ebin
mkdir -p $OVERLAY_PATH/assets/lib/stdlib-1.17.5/
cp -Rdp build/deps/otp_rel/lib/stdlib-1.17.5/ebin $OVERLAY_PATH/assets/lib/stdlib-1.17.5/ebin
mkdir -p $OVERLAY_PATH/assets/lib/xmerl-1.2.9/ebin/
cp -Rdp build/deps/otp_rel/lib/xmerl-1.2.9/ebin/xmerl_ucs.beam $OVERLAY_PATH/assets/lib/xmerl-1.2.9/ebin/xmerl_ucs.beam
# Geocouch
mkdir -p $OVERLAY_PATH/assets/lib/geocouch
cp $GEOCOUCH_HOME/build/*.beam $OVERLAY_PATH/assets/lib/geocouch
# Put a version file into assets
echo $1 > $OVERLAY_PATH/assets/CouchbaseVersion.txt
# libs
mkdir -p $OVERLAY_PATH/libs
cp -Rdp $COUCHBASE_SERVICE_HOME/bin/couchbase-$1.jar $OVERLAY_PATH/libs/
cp -Rdp build/deps/otp_rel/lib/jinterface-1.5.4/priv/OtpErlang.jar $OVERLAY_PATH/libs/OtpErlang-$2.jar
# native libs
mkdir -p $OVERLAY_PATH/libs/armeabi
cp -Rdp build/deps/otp_rel/erts-5.8.5/bin/libbeam.so $OVERLAY_PATH/libs/armeabi
cp -Rdp build/deps/otp_rel/lib/crypto-2.0.3/priv/lib/crypto.so $OVERLAY_PATH/libs/armeabi/libcrypto_nif.so
cp -Rdp build/deps/mozilla-current/mozilla-central/js/src/libmozjs.so $OVERLAY_PATH/libs/armeabi
cp -Rdp ../couchdb/src/snappy/priv/snappy_nif.so $OVERLAY_PATH/libs/armeabi/libsnappy_nif.so
cp -Rdp $COUCHBASE_SERVICE_HOME/libs/armeabi/libcom_couchbase_android_ErlangThread.so $OVERLAY_PATH/libs/armeabi
# Strip unneeded symbols from the libs
arm-linux-androideabi-strip --strip-unneeded $OVERLAY_PATH/libs/armeabi/libbeam.so
arm-linux-androideabi-strip --strip-unneeded $OVERLAY_PATH/libs/armeabi/libcrypto_nif.so
arm-linux-androideabi-strip --strip-unneeded $OVERLAY_PATH/libs/armeabi/libmozjs.so
arm-linux-androideabi-strip --strip-unneeded $OVERLAY_PATH/libs/armeabi/libsnappy_nif.so
arm-linux-androideabi-strip --strip-unneeded $OVERLAY_PATH/libs/armeabi/libcom_couchbase_android_ErlangThread.so
# Strip beam files of debugging symbols
$ERL_HOME/bootstrap/bin/erl -noinput -eval "erlang:display(beam_lib:strip_release(\"$OVERLAY_PATH/assets\"))" -s init stop
##
# Archive the overlay
#
cd $OVERLAY_PATH
OVERLAY_FILE=overlay-$1-$BUILD_VERSION.zip
zip -r ../$OVERLAY_FILE *
cd $COUCH_ANDROID_HOME
##
# Build Couchbase.zip
#
cd out
mkdir -p $COUCHBASE_NAME
cp -Rdp $COUCHBASE_SERVICE_HOME/bin/script $COUCHBASE_NAME
cp $OVERLAY_FILE overlay.zip
COUCHBASE_FILE="Couchbase.zip"
zip -r $COUCHBASE_FILE overlay.zip $COUCHBASE_NAME
##
# Build Android-Couchbase.zip
#
cp -Rdp $COUCHBASE_NAME/script/couchbase.xml .
cp -Rdp $COUCHBASE_SERVICE_HOME/doc/README.txt .
repo manifest -r -o manifest.xml
zip android-couchbase-$1.zip $COUCHBASE_FILE couchbase.xml README.txt manifest.xml
cd $COUCH_ANDROID_HOME