summaryrefslogtreecommitdiff
path: root/mobile.sh
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-03-04 17:25:47 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-03-04 17:25:47 +0100
commitc82cf0fa106ef9ea589962f59c784cda7a7a17f8 (patch)
treeddf8283dffca49e25f81dcc53aed1c67a37d605e /mobile.sh
parentf7dcf37f972c1b7ed6d63e350b3bc5ba118b0fd4 (diff)
downloadsnap-yow-c82cf0fa106ef9ea589962f59c784cda7a7a17f8.tar.gz
snap-yow-c82cf0fa106ef9ea589962f59c784cda7a7a17f8.zip
add mobile version
Diffstat (limited to 'mobile.sh')
-rwxr-xr-xmobile.sh89
1 files changed, 89 insertions, 0 deletions
diff --git a/mobile.sh b/mobile.sh
new file mode 100755
index 0000000..bd003a1
--- /dev/null
+++ b/mobile.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+if [[ "$snapsource" == "" ]]
+then
+ export snapsource="https://github.com/Gubolin/snap.git"
+fi
+
+if [[ $1 = "" ]]
+then
+ echo "Usage: mobile.sh PLATFORM [BUILDSOURCE]"
+ exit 0
+fi
+
+scriptdir=$(readlink -e ".")
+
+# Requirements:
+# git, nodejs, android SDK / other platform(s)
+# cordova (https://cordova.apache.org/)
+# optional: crosswalk-cordova (https://github.com/crosswalk-project/crosswalk-cordova-android)
+
+if [[ $2 != "" ]]
+then
+ buildsource=$(readlink -e "$2")
+fi
+
+builddir=$(mktemp -d)
+
+cordova create $builddir edu.berkeley.snap "Snap\!"
+cd $builddir
+rm -rf www config.xml
+
+if [[ $2 == "" ]]
+then
+ git clone "$snapsource" www
+ cd www/
+else
+ mv "$buildsource" www
+ cd www
+fi
+
+# add mobile-specific library; it's made available at runtime
+sed -i '/link rel="shortcut icon"/a\
+ <script type="text/javascript" src="cordova.js"></script>' snap.html
+
+echo "Adding cordova plugins"
+# add everything needed and build for $device
+cordova platform add "$1" > /dev/null
+cordova plugin add org.apache.cordova.plugin.softkeyboard \
+ org.apache.cordova.vibration \
+ org.apache.cordova.device-motion \
+ org.apache.cordova.device-orientation \
+ org.apache.cordova.geolocation \
+ de.appplant.cordova.plugin.local-notification 2> /dev/null
+
+if [[ $1 == "android" ]]
+then
+ # Remove default icons
+ cd "$builddir/platforms/android"
+ find -name '*.png' | xargs rm
+
+ if [[ $crosswalk != "" ]]
+ then
+ # adapted from https://crosswalk-project.org/documentation/cordova/migrate_an_application.html#migrate
+ echo "Preparing crosswalk"
+ rm -Rf "$builddir/platforms/android/CordovaLib/*"
+ cp -a $crosswalk/framework/* "$builddir/platforms/android/CordovaLib/"
+ cp -a "$crosswalk/VERSION" "$builddir/platforms/android/"
+ export ANDROID_HOME=$(dirname $(dirname $(which android)))
+ cd "$builddir/platforms/android/CordovaLib/"
+ android update project --subprojects --target android-21 --path . > /dev/null
+ ant debug > /dev/null
+ cd "$builddir"
+ # prepend permissions to end of manifest
+ sed -i "s,</manifest>,\
+ <uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" />\
+ <uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />\
+ <uses-permission android:name=\"android.permission.INTERACT_ACROSS_USERS\" />\
+ </manifest>,g" \
+ "$builddir/platforms/android/AndroidManifest.xml"
+ fi
+fi
+
+echo "Building application"
+cordova build "$1" > /dev/null
+
+cd $builddir
+# TODO other platforms
+find -name '*.apk' | xargs -I {} mv {} $scriptdir
+echo "Finished."