#!/usr/bin/env bash set -euo pipefail ########## # Config # ########## readonly GIT_BRANCH='android-8.0.0_r12' readonly API_LEVEL='26' readonly ANDROID_HOME='/mnt/Storage/android/androidSDK' ########### # Helpers # ########### readonly CUR_DIR=$( pwd ) readonly WORKING_DIR=$( mktemp -d ) setup() { pushd ${WORKING_DIR} mkdir -p frameworks/base } teardown() { popd rm -rf "${WORKING_DIR}" } fetch_sources() { local -r target_branch="${1}" # Fetch repositories that contain the sources we're interested in git clone --depth 1 https://android.googlesource.com/platform/frameworks/base -b "${target_branch}" frameworks/base git clone --depth 1 https://android.googlesource.com/platform/libcore -b "${target_branch}" git clone --depth 1 https://android.googlesource.com/platform/development -b "${target_branch}" } package_sources() { local -r zip_name="${1}" # Create a basic source.properties file echo -e "Pkg.UserSrc=false\nPkg.Revision=1\nAndroidVersion.ApiLevel=${API_LEVEL}" > source.properties # Modify the script to create a sources ZIP to use "android-26" as top-level directory cat development/build/tools/mk_sources_zip.py | sed -e "s/TOP_FOLDER = .*/TOP_FOLDER = \"android-${API_LEVEL}\"/" > my_mk_sources_zip.py # Run the script to create android-26-sources.zip python2 my_mk_sources_zip.py -z source.properties "${zip_name}" . } maybe_install_sources() { local -r zip_name="${1}" cp "${zip_name}" "${CUR_DIR}/" local -r sources_dir="${ANDROID_HOME}/sources" local -r target_path="${sources_dir}/android-${API_LEVEL}" if [ -d "${target_path}" ]; then echo "" echo "WARN: directory exists [${target_path}] copying instead..." local -r zip_path="${CUR_DIR}/${zip_name}" if [ -f "${zip_path}" ]; then echo "WARN: nevermind, file exists [${zip_path}] skipping..." fi else unzip "${zip_name}" -d "${sources_dir}" fi } ############### # DO WORK SON # ############### main() { local -r zip_name="android-${API_LEVEL}-sources.zip" setup fetch_sources "${GIT_BRANCH}" package_sources "${zip_name}" maybe_install_sources "${zip_name}" teardown } main