Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ### Author: Insality <insality@gmail.com>, 04.2019
- ## (c) Insality Games
- ##
- ## Unique build && deploy script for mobile projects (Android, iOS)
- ## for Defold Engine.
- ## Usage:
- ## bash deployer.sh [a][i][r][b][d]
- ## a - add target platform Android
- ## i - add target platform iOS
- ## r - set build mode to Release
- ## b - build project (game bundle will be in ./dist folder)
- ## d - deploy bundle to connected device
- ## it will deploy && run bundle on Android
- ## it will only deploy bundle on iOS
- ##
- ## Example:
- ## ./deployer.sh abd - build, deploy and run Android bundle
- ## ./deployer.sh ird - build and deploy iOS release bundle
- ## ./deployer.sh aibr - build Android and iOS release bundles
- ##
- ## You can pass params in any order you want, for example:
- ## ./deployer.sh riba - same behaviour as aibr
- title=$(less game.project | grep "^title = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
- version=$(less game.project | grep "^version = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
- title_no_space=$(echo -e "${title}" | tr -d '[[:space:]]')
- bundle_id=$(less game.project | grep "^package = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
- android_platform="armv7-android"
- ios_platform="armv7-darwin"
- ## Setup provisions and certificates for your project
- bob_path=../bob.jar
- android_key="./provisions/key.pk8"
- android_cer="./provisions/certificate.pem"
- ios_identity_dev="ABXXABXX"
- ios_identity_dist="ABYYABYYY"
- ios_prov_dev="./provisions/dev.mobileprovision"
- ios_prov_dist="./provisions/dist.mobileprovision"
- echo "Project: ${title} v${version}"
- if [ ! -f ${bob_path} ]
- then
- echo "Unable to find bob.jar. Download it from d.defold.com."
- exit 1
- fi
- resolve_bob() {
- java -jar ${bob_path} --email foo@bar.com --auth 12345 resolve
- }
- bob() {
- java -jar ${bob_path} --version
- java -jar ${bob_path} --archive -tc true -bo ./dist \
- --strip-executable $@ distclean build bundle
- }
- build() {
- if [ ! -d ./dist ]
- then
- mkdir ./dist
- fi
- platform=$1
- release=$2
- mode="debug"
- ident=${ios_identity_dev}
- prov=${ios_prov_dev}
- if $2
- then
- mode="release"
- ident=${ios_identity_dist}
- prov=${ios_prov_dist}
- fi
- resolve_bob
- if [ ${platform} == "armv7-android" ]
- then
- echo "Start build android ${mode}"
- bob -brhtml ./dist/${platform}_report.html \
- --platform ${platform} -pk ${android_key} -ce ${android_cer} \
- --variant ${mode}
- fi
- if [ ${platform} == "armv7-darwin" ]
- then
- echo "Start build ios ${mode}"
- bob -brhtml ./dist/${platform}_report.html \
- --platform ${platform} --identity ${ident} -mp ${prov} \
- --variant ${mode}
- fi
- }
- deploy() {
- platform=$1
- if [ ${platform} == "armv7-android" ]
- then
- line="./dist/${title}/${title}.apk"
- line= sed 's/ /\\ /g' <<< $line
- echo "Deploy to Android from $line"
- adb install -r "${line}"
- fi
- if [ ${platform} == "armv7-darwin" ]
- then
- line="./dist/${title}.ipa"
- line= sed 's/ /\\ /g' <<< $line
- echo "Deploy to Ios from dist/${line}.ipa"
- ios-deploy --bundle "${line}"
- fi
- }
- run() {
- platform=$1
- if [ ${platform} == "armv7-android" ]
- then
- echo "Start game ${bundle_id}"
- adb shell am start -n ${bundle_id}/com.dynamo.android.DefoldActivity
- adb logcat -s defold
- fi
- if [ ${platform} == "armv7-darwin" ]
- then
- echo "Can't run ipa on iOS"
- fi
- }
- all_release() {
- echo "Start build all releases"
- build armv7-android true
- build armv7-darwin true
- }
- arg=$1
- is_build=false
- is_deploy=false
- release=false
- is_android=false
- is_ios=false
- for (( i=0; i<${#arg}; i++ )); do
- a=${arg:$i:1}
- if [ $a == b ]
- then
- is_build=true
- fi
- if [ $a == "d" ]
- then
- is_deploy=true
- fi
- if [ $a == "r" ]
- then
- release=true
- fi
- if [ $a == "a" ]
- then
- is_android=true
- fi
- if [ $a == "i" ]
- then
- is_ios=true
- fi
- done
- if $is_ios
- then
- if $is_build
- then
- echo "Start build on ${ios_platform}"
- build ${ios_platform} ${release}
- fi
- if $is_deploy
- then
- echo "Start deploy project to device"
- deploy ${ios_platform}
- run ${ios_platform}
- fi
- fi
- if $is_android
- then
- if $is_build
- then
- echo "Start build on ${android_platform}"
- build ${android_platform} ${release}
- fi
- if $is_deploy
- then
- echo "Start deploy project to device"
- deploy ${android_platform}
- run ${android_platform}
- fi
- fi
- echo "End of builder"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement