1*ff35212dScey#!/bin/bash 2*ff35212dScey# 3*ff35212dScey# Copyright (C) 2020 Google LLC 4*ff35212dScey# 5*ff35212dScey# Licensed under the Apache License, Version 2.0 (the "License"); 6*ff35212dScey# you may not use this file except in compliance with the License. 7*ff35212dScey# You may obtain a copy of the License at 8*ff35212dScey# 9*ff35212dScey# http://www.apache.org/licenses/LICENSE-2.0 10*ff35212dScey# 11*ff35212dScey# Unless required by applicable law or agreed to in writing, software 12*ff35212dScey# distributed under the License is distributed on an "AS IS" BASIS, 13*ff35212dScey# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*ff35212dScey# See the License for the specific language governing permissions and 15*ff35212dScey# limitations under the License. 16*ff35212dScey 17*ff35212dScey############################################################################### 18*ff35212dScey# Input files and output directory: can be customized. 19*ff35212dSceyINPUT_CARRIERCONFIG_XML_FILE="packages/apps/CarrierConfig/res/xml/vendor.xml" 20*ff35212dSceyINPUT_CARRIERCONFIG_ASSETS_DIR="packages/apps/CarrierConfig/assets" 21*ff35212dSceyINPUT_APNS_XML_FILE="device/sample/etc/apns-full-conf.xml" 22*ff35212dSceyOUTPUT_DIR="/tmp/CarrierSettings/etc" 23*ff35212dScey############################################################################### 24*ff35212dScey 25*ff35212dScey( # start sub-shell so can use 'set -e' to abort on any failure 26*ff35212dSceyset -e 27*ff35212dScey 28*ff35212dScey# 1. Build tools 29*ff35212dSceyecho 'step 1. Building tools ...' 30*ff35212dSceym CarrierConfigConverterV2 update_apn update_carrier_data GenCarrierList GenDeviceSettings 31*ff35212dSceyecho 'Done.' 32*ff35212dScey 33*ff35212dSceyecho 'step 2. Converting config files ...' 34*ff35212dScey# 2a. Create a temp directory as workspace 35*ff35212dSceyTMP_DIR=$(mktemp -d -t cs-XXXXXXX) 36*ff35212dSceyDATA_SETTING_DIR=$TMP_DIR/data/setting 37*ff35212dSceyDATA_DEVICE_DIR=$TMP_DIR/data/device 38*ff35212dSceyASSETS_DIR=$TMP_DIR/assets 39*ff35212dSceyINNER_TMP_DIR=$TMP_DIR/tmp 40*ff35212dSceyTIER1_CARRIERS_FILE=$TMP_DIR/data/tier1_carriers.textpb 41*ff35212dSceyDEVICE_FILE=$DATA_DEVICE_DIR/device.textpb 42*ff35212dSceymkdir -p "$DATA_SETTING_DIR" > /dev/null 43*ff35212dSceymkdir -p "$DATA_DEVICE_DIR" > /dev/null 44*ff35212dSceymkdir -p "$ASSETS_DIR" > /dev/null 45*ff35212dSceymkdir -p "$INNER_TMP_DIR" > /dev/null 46*ff35212dSceytouch "$TIER1_CARRIERS_FILE" > /dev/null 47*ff35212dSceytouch "$DEVICE_FILE" > /dev/null 48*ff35212dScey 49*ff35212dScey# 2b. Copy input files to workspace 50*ff35212dSceycp $INPUT_CARRIERCONFIG_XML_FILE "$TMP_DIR"/vendor.xml > /dev/null 51*ff35212dSceycp $INPUT_CARRIERCONFIG_ASSETS_DIR/* "$ASSETS_DIR"/ > /dev/null 52*ff35212dSceycp $INPUT_APNS_XML_FILE "$TMP_DIR"/apns-full-conf.xml > /dev/null 53*ff35212dScey 54*ff35212dScey# 2c. Convert XMLs to TEXTPB 55*ff35212dScey 56*ff35212dSceyEPOCH=$(date -d '2018-06-01T00:00:00Z' +%s) 57*ff35212dSceyNOW=$(date +%s) 58*ff35212dSceyTIMESTAMP="$((NOW-EPOCH))" 59*ff35212dScey# Use TIMESTAMP as version number 60*ff35212dScey# To customize the version number, assign the customized value to VERSION. 61*ff35212dSceyVERSION="$TIMESTAMP" 62*ff35212dScey 63*ff35212dSceySCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" 64*ff35212dSceyUPDATE_APN=$SCRIPT_DIR/bin/update_apn 65*ff35212dScey[ -x "$UPDATE_APN" ] || UPDATE_APN=out/host/linux-x86/bin/update_apn 66*ff35212dSceyUPDATE_CARRIER_DATA=$SCRIPT_DIR/bin/update_carrier_data 67*ff35212dScey[ -x "$UPDATE_CARRIER_DATA" ] || UPDATE_CARRIER_DATA=out/host/linux-x86/bin/update_carrier_data 68*ff35212dScey 69*ff35212dScey# To use multiple vendor.xml files, just provide multiple `--vendor_xml=___.xml` 70*ff35212dScey# lines in the command below. The order decides config precedence: a file is 71*ff35212dScey# overwritten by files AFTER it. 72*ff35212dSceyout/host/linux-x86/bin/CarrierConfigConverterV2 \ 73*ff35212dScey --output_dir="$TMP_DIR"/data \ 74*ff35212dScey --vendor_xml="$TMP_DIR"/vendor.xml \ 75*ff35212dScey --assets="$ASSETS_DIR"/ \ 76*ff35212dScey --version=$VERSION > /dev/null 77*ff35212dScey"$UPDATE_APN" \ 78*ff35212dScey --apn_file="$TMP_DIR"/apns-full-conf.xml \ 79*ff35212dScey --data_dir="$TMP_DIR"/data \ 80*ff35212dScey --out_file="$INNER_TMP_DIR"/apns.textpb 81*ff35212dScey"$UPDATE_CARRIER_DATA" \ 82*ff35212dScey --data_dir="$TMP_DIR"/data \ 83*ff35212dScey --in_file="$INNER_TMP_DIR"/apns.textpb 84*ff35212dScey 85*ff35212dScey# 2d. Convert TEXTPB to PB 86*ff35212dSceymkdir -p "$INNER_TMP_DIR"/pb > /dev/null 87*ff35212dSceymkdir -p "$INNER_TMP_DIR"/textpb > /dev/null 88*ff35212dScey 89*ff35212dSceyout/host/linux-x86/bin/GenCarrierList \ 90*ff35212dScey --version_offset=0 \ 91*ff35212dScey --with_version_number \ 92*ff35212dScey --out_pb="$INNER_TMP_DIR"/carrier_list.pb \ 93*ff35212dScey --in_textpbs="$TIER1_CARRIERS_FILE","$TMP_DIR"/data/other_carriers.textpb \ 94*ff35212dScey > /dev/null 95*ff35212dSceymv "$INNER_TMP_DIR"/carrier_list*.pb "$INNER_TMP_DIR"/pb > /dev/null 96*ff35212dSceymv "$INNER_TMP_DIR"/carrier_list.textpb "$INNER_TMP_DIR"/textpb > /dev/null 97*ff35212dScey 98*ff35212dSceyfor device in "$DATA_DEVICE_DIR"/*.textpb; do 99*ff35212dScey [[ -e "$device" ]] || break 100*ff35212dScey device=${device%.*} && device=${device##*/} \ 101*ff35212dScey && device_dir="${INNER_TMP_DIR}/${device}" && mkdir -p "${INNER_TMP_DIR}" \ 102*ff35212dScey && mkdir -p "${INNER_TMP_DIR}/textpb/${device}" > /dev/null \ 103*ff35212dScey && out/host/linux-x86/bin/GenDeviceSettings \ 104*ff35212dScey --device_overlay="$DATA_DEVICE_DIR/${device}.textpb" \ 105*ff35212dScey --base_setting_dir="$DATA_SETTING_DIR" \ 106*ff35212dScey --device_setting_dir="${device_dir}" \ 107*ff35212dScey --version_offset=0 \ 108*ff35212dScey --with_device_name="${device}" \ 109*ff35212dScey --with_version_number > /dev/null \ 110*ff35212dScey && mv "${device_dir}"/*.pb "${INNER_TMP_DIR}/pb" > /dev/null \ 111*ff35212dScey && mv "${device_dir}"/*.textpb "${INNER_TMP_DIR}/textpb/${device}" > /dev/null \ 112*ff35212dScey && rmdir "${device_dir}" 113*ff35212dSceydone 114*ff35212dScey 115*ff35212dSceyecho 'Done.' 116*ff35212dScey 117*ff35212dSceyecho 'step 3. Copy generated files to output directory ...' 118*ff35212dScey 119*ff35212dSceymkdir -p $OUTPUT_DIR > /dev/null 120*ff35212dScey# Ignore error if first time running 121*ff35212dSceyrm -rf "${OUTPUT_DIR:?}"/* > /dev/null || true 122*ff35212dSceycp -r "$INNER_TMP_DIR"/pb $OUTPUT_DIR > /dev/null 123*ff35212dSceycp -r "$INNER_TMP_DIR"/textpb $OUTPUT_DIR > /dev/null 124*ff35212dSceyrm -rf "${TMP_DIR:?}" > /dev/null 125*ff35212dScey 126*ff35212dSceyecho 'Generated files:' 127*ff35212dSceyfind $OUTPUT_DIR -type f 128*ff35212dScey 129*ff35212dSceyecho 'Done.' 130*ff35212dScey) # end sub-shell 131