This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_functions.sh
172 lines (144 loc) · 7.14 KB
/
copy_functions.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Copyright (C) 2017 Vincent Zvikaramba
#
# 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.
function rsync_cp {
sync_count=1
if [ "x${SYNC_HOST}" == "x" ]; then
remote_mkdir $(dirname $2)
exit_on_failure rsync -av --append-verify -P $1 $2
else
remote_mkdir $(dirname $2)
echoTextBlue "Using rsync to copy $1 -> ${SYNC_HOST}:$2"
rsync -av --append-verify -P -e 'ssh -o StrictHostKeyChecking=no' $1 ${SYNC_HOST}:$2
sync_exit_error=$?
while [ $sync_exit_error -ne 0 ] && [ $sync_count -le $UPLOAD_RETRY_COUNT ]; do
echoTextRed "[${sync_count}/${UPLOAD_RETRY_COUNT}] Retrying copy of $1 -> ${SYNC_HOST}:$2"
rsync -av --append-verify -P -e 'ssh -o StrictHostKeyChecking=no' $1 ${SYNC_HOST}:$2
sync_exit_error=$?
sync_count=$((sync_count+1))
done
exit_error $sync_exit_error
fi
}
function remote_mkdir {
if [ "x${1}" != "x" ]; then
if [ "x${SYNC_HOST}" != "x" ]; then
exit_on_failure ssh -o StrictHostKeyChecking=no ${SYNC_HOST} mkdir -p $1
else
exit_on_failure mkdir -p $1
fi
fi
}
function copy_bootimage {
if [ "x$BUILD_TARGET" == "xbootimage" ] && [ "x$NO_PACK_BOOTIMAGE" == "x" ]; then
boot_pkg_dir=${BUILD_TEMP}/boot_pkg
if [ "x$DISTRIBUTION" == "xlineage" ] || [ "x$DISTRIBUTION" == "xrr" ]; then
boot_pkg_zip=${ARTIFACT_OUT_DIR}/boot_caf-based_j${JOB_BUILD_NUMBER}_$(date +%Y%m%d)-${DEVICE_NAME}.zip
else
boot_pkg_zip=${ARTIFACT_OUT_DIR}/boot_aosp-based_j${JOB_BUILD_NUMBER}_$(date +%Y%m%d)-${DEVICE_NAME}.zip
fi
boot_tar_name=bootimage_j${JOB_BUILD_NUMBER}_$(date +%Y%m%d)-${DEVICE_NAME}.tar
revert_pkg_dir=${BUILD_TEMP}/boot_pkg_revert
revert_zip=${ARTIFACT_OUT_DIR}/revert_boot_image_j${JOB_BUILD_NUMBER}_$(date +%Y%m%d)-${DEVICE_NAME}.zip
binary_target_dir=META-INF/com/google/android
install_target_dir=install/bin
blob_dir=blobs
proprietary_dir=proprietary
# create odin package
echoTextBlue "Creating ODIN-Flashable boot image..."
tar -C ${ANDROID_PRODUCT_OUT}/ boot.img -c -f ${ARTIFACT_OUT_DIR}/${boot_tar_name}
# create the directories
exit_on_failure mkdir -p ${boot_pkg_dir}/${binary_target_dir}
exit_on_failure mkdir -p ${boot_pkg_dir}/${blob_dir}
exit_on_failure mkdir -p ${boot_pkg_dir}/${proprietary_dir}
exit_on_failure mkdir -p ${boot_pkg_dir}/${install_target_dir}/installbegin
exit_on_failure mkdir -p ${boot_pkg_dir}/${install_target_dir}/installend
exit_on_failure mkdir -p ${boot_pkg_dir}/${install_target_dir}/postvalidate
exit_on_failure mkdir -p ${revert_pkg_dir}/${binary_target_dir}
exit_on_failure mkdir -p ${revert_pkg_dir}/${blob_dir}
exit_on_failure mkdir -p ${revert_pkg_dir}/${proprietary_dir}
exit_on_failure mkdir -p ${revert_pkg_dir}/${install_target_dir}/installbegin
exit_on_failure mkdir -p ${revert_pkg_dir}/${install_target_dir}/installend
exit_on_failure mkdir -p ${revert_pkg_dir}/${install_target_dir}/postvalidate
# download the update binary
echoTextBlue "Fetching update binary..."
${CURL} ${SCRIPT_REPO_URL}/updater/update-binary 1>${BUILD_TEMP}/update-binary 2>/dev/null
cp ${BUILD_TEMP}/update-binary ${revert_pkg_dir}/${binary_target_dir}
echoTextBlue "Fetching mkbootimg..."
${CURL} ${SCRIPT_REPO_URL}/bootimg-tools/mkbootimg 1>${BUILD_TEMP}/mkbootimg 2>/dev/null
echoTextBlue "Fetching unpackbootimg..."
${CURL} ${SCRIPT_REPO_URL}/bootimg-tools/unpackbootimg 1>${BUILD_TEMP}/unpackbootimg 2>/dev/null
cp ${ANDROID_PRODUCT_OUT}/boot.img ${boot_pkg_dir}/${blob_dir}
cp ${BUILD_TEMP}/update-binary ${boot_pkg_dir}/${binary_target_dir}
cp ${BUILD_TEMP}/mkbootimg ${boot_pkg_dir}/${install_target_dir}
cp ${BUILD_TEMP}/unpackbootimg ${boot_pkg_dir}/${install_target_dir}
# Create the scripts
create_scripts
#archive the image
echoTextBlue "Creating flashables..."
cd ${boot_pkg_dir} && zip ${boot_pkg_zip} `find ${boot_pkg_dir} -type f | cut -c $(($(echo ${boot_pkg_dir}|wc -c)+1))-`
cd ${revert_pkg_dir} && zip ${revert_zip} `find ${revert_pkg_dir} -type f | cut -c $(($(echo ${revert_pkg_dir}|wc -c)+1))-`
fi
}
function copy_recoveryimage {
if [ "x$BUILD_TARGET" == "xrecoveryimage" ] || [ "x$BUILD_TARGET" == "xotapackage" ]; then
if [ -e ${ANDROID_PRODUCT_OUT}/recovery.img ]; then
#define some variables
if [ -z ${JOB_BUILD_NUMBER} ]; then
rec_name=${recovery_flavour}-${DISTRIBUTION}-${ver}-$(date +%Y%m%d)-${DEVICE_NAME}
else
rec_name=${recovery_flavour}-${DISTRIBUTION}-${ver}_j${JOB_BUILD_NUMBER}_$(date +%Y%m%d)_${DEVICE_NAME}
fi
logb "\n\t\tCopying recovery image...\n"
tar -C ${ANDROID_PRODUCT_OUT}/ recovery.img -c -f ${ARTIFACT_OUT_DIR}/${rec_name}.tar
fi
fi
}
function copy_otapackage {
if [ "x$BUILD_TARGET" == "xotapackage" ]; then
OTA_REGEXP='*'"${DEVICE_NAME}"'*'"${BUILD_NUMBER}"'*zip'
logb "\nSearching for OTA package..."
OTA_FILE=`find ${ANDROID_PRODUCT_OUT} -maxdepth 1 -type f -name ${OTA_REGEXP} 2>/dev/null | head -1 2>/dev/null`
if ! [ -e "$OTA_FILE" ]; then
echoText "Failed to find ota package!!"
else
echoTextBlue "Found ota package $OTA_FILE"
#copy the zip in the background
logb "\n\t\tCopying zip image..."
cp ${OTA_FILE} ${ARTIFACT_OUT_DIR}/${arc_name}.zip
if [ "x$ver" == "x15.0" ] || [ "x$ver" == "x15.1" ]; then
logb "\n\t\tCopying system prop..."
prop=${ANDROID_PRODUCT_OUT}/system/build.prop
[ -e ${prop} ] && cp ${prop} ${ARTIFACT_OUT_DIR}/${arc_name}.zip.prop
fi
#calculate md5sums
md5sums=$(md5sum ${OTA_FILE} | cut -d " " -f 1)
echo "${md5sums} ${arc_name}.zip" > ${ARTIFACT_OUT_DIR}/${arc_name}.zip.md5 || exit_error 1
fi
fi
}
COPY_FUNCTIONS=("${COPY_FUNCTIONS[@]}" "copy_bootimage")
COPY_FUNCTIONS=("${COPY_FUNCTIONS[@]}" "copy_recoveryimage")
COPY_FUNCTIONS=("${COPY_FUNCTIONS[@]}" "copy_otapackage")
function copy_files {
for ix in `seq 0 $((${#COPY_FUNCTIONS[@]}-1))`; do
echoTextBlue "Running function ${COPY_FUNCTIONS[$ix]}"
${COPY_FUNCTIONS[$ix]} $@
done
}
function upload_artifacts {
echoTextBlue "Transferring build artifacts..."
remote_mkdir ${OUTPUT_DIR}
rsync_cp ${ARTIFACT_OUT_DIR} ${OUTPUT_DIR}
}