-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·144 lines (134 loc) · 5.08 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·144 lines (134 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
##
## Copyright (c) 2021 HopeBayTech.
##
## This file is part of Tera.
## See https://github.com/HopeBayMobile for further info.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
[ $EUID -eq 0 ] || exec sudo -s -E $0
echo -e "\n======== ${BASH_SOURCE[0]} ========"
repo="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && while [ ! -d .git ] ; do cd ..; done; pwd )"
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TERM=xterm-256color
erorr_at() {
$UNTRACE
local script="$1"
local parent_lineno="$2"
local message="$3"
local code="${4:-1}"
echo "Error near ${script} line ${parent_lineno}; exiting with status ${code}"
if [[ -n "$message" ]] ; then
echo -e "Message: ${message}"
fi
exit "${code}"
}
#let printf handle the printing
function _hashes() { printf %0$((${1}))d\\n | tr 0 \# ; }
function _hdr_inc() {
{ $UNTRACE; } 2>/dev/null
local _hinc=${1##*-} _hashc=${2##*[!0-9]}
: ${_hinc:=$(set -- $3 ; printf %s_cnt\\n "${1-_hdr}")}
${1+shift} ${2+2}
_hashes ${_hashc:=40}
printf "%s #$((${_hinc}=${_hinc}+1)):${1+%b}" \
${1+"$*"} ${1+\\c}Default
echo && _hashes $_hashc
$TRACE
}
function build_system() {
{ _hdr_inc - - Doing $FUNCNAME; } 2>/dev/null
docker pull $DOCKER_IMAGE
echo sdk.dir=/opt/android-sdk-linux > local.properties
echo ndk.dir=/opt/android-ndk-r10e >> local.properties
docker run --rm \
--volume="$(pwd):/opt/workspace" \
--volume="$(pwd)/.root.gradle:/root/.gradle" \
--volume="/mnt/nas/CloudDataSolution/HCFS_android/resources/ci_shared_storage/android-sdk-linux:/opt/android-sdk-linux" \
-e KEYSTORE_PASSWORD -e KEY_ALIAS -e KEY_PASSWORD \
$DOCKER_IMAGE /bin/bash -c "./gradlew assembleRelease"
}
function copy_lib_to_source_tree() {
{ _hdr_inc - - Doing $FUNCNAME; } 2>/dev/null
rsync -arcv --no-owner --no-group --no-times --no-perms \
$LIB_DIR/nexus-5x-hcfs/system/lib64/{libhcfsapi.so,libjansson.so} app/src/main/jni/mylibs/arm64-v8a/
rsync -arcv --no-owner --no-group --no-times --no-perms \
$LIB_DIR/nexus-7-hcfs/system/lib/{libhcfsapi.so,libjansson.so} app/src/main/jni/mylibs/armeabi-v7a/
}
function publish_apk() {
{ _hdr_inc - - Doing $FUNCNAME; } 2>/dev/null
APP_NAME=terafonn_$(sed -n -e '/versionName/p' app/build.gradle | cut -d'"' -f 2)
APP_DIR=${PUBLISH_DIR}/${JOB_NAME}
echo APP_NAME=${APP_NAME} >> export_props.properties
echo APP_DIR=${APP_DIR} >> export_props.properties
umask 0022
mkdir -p ${PUBLISH_DIR}/${JOB_NAME}
rm -rf ${PUBLISH_DIR}/${JOB_NAME}/*
if [ -f app/build/outputs/apk/app-release.apk ]; then
rsync -arcv --chmod=a+rX --no-owner --no-group --no-times \
app/build/outputs/apk/app-release.apk ${PUBLISH_DIR}/${JOB_NAME}/${APP_NAME}.apk
fi
if [ -f app/build/outputs/apk/app-release-unsigned.apk ]; then
rsync -arcv --chmod=a+rX --no-owner --no-group --no-times \
app/build/outputs/apk/app-release-unsigned.apk ${PUBLISH_DIR}/${JOB_NAME}/${APP_NAME}.apk
fi
rsync -arcv --chmod=a+rX --no-owner --no-group --no-times \
app/src/main/libs/*/libterafonnapi.so ${PUBLISH_DIR}/${JOB_NAME}/app_libs/
}
function mount_nas() {
{ _hdr_inc - - Doing $FUNCNAME; } 2>/dev/null
service rpcbind start || :
mkdir -p /mnt/nas
if ! mount | grep 'nas:/ubuntu on /mnt/nas'; then
umount /mnt/nas || :
mount nas:/ubuntu /mnt/nas
fi
}
function unmount_nas() {
{ _hdr_inc - - Doing $FUNCNAME; } 2>/dev/null
umount /mnt/nas
}
function update_version_num() {
if [ -z $VERSION_NUM ]; then
export VERSION_NUM = Manual build $(shell date +%Y%m%d-%H%M%S)
fi
sed -i"" -e 's#\(<string name="tera_version" translatable="false">\).*\(</string>\)#\1'$VERSION_NUM'\2#' \
app/src/main/res/values/config.xml
}
# Enable error trace
trap 'erorr_at "${BASH_SOURCE[0]}" ${LINENO}' ERR
set -e -o errtrace -o functrace
echo ========================================
echo Jenkins pass-through variables:
echo PUBLISH_DIR: ${PUBLISH_DIR}
echo LIB_DIR: ${LIB_DIR}
echo JOB_NAME: ${JOB_NAME}
echo ========================================
echo "Environment variables (with defaults):"
TRACE="set -x"; UNTRACE="set +x"
$TRACE
DOCKERNAME=android-app-build-`date +%m%d-%H%M%S`
DOCKER_IMAGE=docker:5000/android-app-buildbox
JOB_NAME=${JOB_NAME:-HCFS-android-apk}
### Upstream hcfs lib
# LIB_DIR=${LIB_DIR:-/mnt/nas/CloudDataSolution/TeraFonn_CI_build/feature/terafonn_1.0.0025/2.0.4.0305/HCFS-android-binary}
eval '[ -n "$LIB_DIR" ]' || { echo Assign these for local build; exit 1; }
### Publish dir
# PUBLISH_DIR=${PUBLISH_DIR:-/mnt/nas/CloudDataSolution/TeraFonn_CI_build/android-dev/2.0.4.ci.test}
eval '[ -n "$PUBLISH_DIR" ]' || { echo Assign these for local build; exit 1; }
mount_nas
copy_lib_to_source_tree
update_version_num
build_system
publish_apk