-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-buildfiles.sh
executable file
·114 lines (89 loc) · 2.99 KB
/
setup-buildfiles.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
#!/bin/bash
CWD=$(pwd)
# Base location: $ANDROID_ROOT/vendor/nitrogen/signatures/common/data
PRIVATE_KEY_DIR=../../../../private-signatures
OUT_DIR_ROOT="common"
OUTDIR="$OUT_DIR_ROOT/data"
OUT="data"
rm -Rf $OUT_DIR_ROOT
mkdir -p $OUTDIR
ANDROIDBP="$OUT_DIR_ROOT/Android.bp"
PRODUCTMK="$OUT_DIR_ROOT/certificates.mk"
CERTIFICATE_FILES_TXT="certificate-files.txt"
function write_blueprint_header() {
if [ -f "$ANDROIDBP" ]; then
rm "$ANDROIDBP"
fi
cat << EOF >> "$ANDROIDBP"
// Automatically generated file. DO NOT MODIFY
EOF
}
function write_blueprint_packages() {
local cert_dir_name=$2
local files=(`cat $1 | grep '.override'`)
for ((i=0; i<"${#files[@]}"; i++)); do
file_name="${files[$i]}"
printf 'android_app_certificate {\n' >> "$ANDROIDBP"
printf '\tname: "%s",\n' "$file_name" >> "$ANDROIDBP"
printf '\tcertificate: "%s",\n' "$cert_dir_name"/"$file_name" >> "$ANDROIDBP"
printf "}\n" >> "$ANDROIDBP"
if [ $i -lt $((${#files[@]} - 1)) ]; then
printf "\n" >> "$ANDROIDBP"
fi
done
}
function write_certificate_overrides_makefile_header() {
if [ -f "$PRODUCTMK" ]; then
rm "$PRODUCTMK"
fi
cat << EOF >> "$PRODUCTMK"
# Automatically generated file. DO NOT MODIFY
EOF
}
function write_product_certificate_overrides() {
printf '%s\n' "PRODUCT_CERTIFICATE_OVERRIDES := \\" >> "$PRODUCTMK"
local files=(`cat $1 | grep '.override'`)
local file_name=
local file_to_overrides=
for ((i=0; i<"${#files[@]}"; i++)); do
file_name="${files[$i]}"
if [[ $file_name == *".certificate.override" ]]; then
file_to_overrides="${file_name%\.certificate\.override}"
else
file_to_overrides="${file_name%\.override}"
fi
printf '\t%s' "$file_to_overrides:$file_name" >> "$PRODUCTMK"
if [ $i -lt $((${#files[@]} - 1)) ]; then
printf '%s\n' " \\" >> "$PRODUCTMK"
else
printf '\n\n' >> "$PRODUCTMK"
fi
done
echo 'PRODUCT_DEFAULT_DEV_CERTIFICATE := $(CERTIFICATE_COMMON)/data/releasekey' >> "$PRODUCTMK"
echo 'PRODUCT_OTA_PUBLIC_KEYS := $(CERTIFICATE_COMMON)/data/releasekey.x509.pem' >> "$PRODUCTMK"
}
function create_symlinks() {
if [ -z $1 ] || [ -z $2 ]; then
return
fi
local source_file=$1
local dir_to_work=$2
local is_cert=$3
cd "$dir_to_work"
local target_file=`basename $source_file`
if [[ $is_cert = true ]]; then
ln -fs $source_file.pk8 "$target_file".pk8
ln -fs $source_file.x509.pem "$target_file".x509.pem
else
ln -fs $source_file "$target_file"
fi
cd $CWD
}
write_blueprint_header
write_certificate_overrides_makefile_header
write_blueprint_packages $CERTIFICATE_FILES_TXT $OUT
write_product_certificate_overrides $CERTIFICATE_FILES_TXT
for certs in `cat $CERTIFICATE_FILES_TXT`; do
create_symlinks "$PRIVATE_KEY_DIR/$certs" $OUTDIR true
done
create_symlinks "$PRIVATE_KEY_DIR/avb_pkmd.bin" $OUTDIR