1#!/usr/bin/env bash 2 3set -ex 4 5URL=https://dl.google.com/android/repository/sys-img/android 6 7main() { 8 local arch="${1}" 9 local name="${2}" 10 local dest=/system 11 local td 12 td="$(mktemp -d)" 13 14 apt-get install --no-install-recommends e2tools 15 16 pushd "${td}" 17 wget -q --tries=5 "${URL}/${name}" 18 unzip -q "${name}" 19 20 local system 21 system="$(find . -name system.img)" 22 mkdir -p ${dest}/{bin,lib,lib64} 23 24 # Extract android linker and libraries to /system 25 # This allows android executables to be run directly (or with qemu) 26 if [ "${arch}" = "x86_64" ] || [ "${arch}" = "arm64" ]; then 27 e2cp -p "${system}:/bin/linker64" "${dest}/bin/" 28 e2cp -p "${system}:/lib64/libdl.so" "${dest}/lib64/" 29 e2cp -p "${system}:/lib64/libc.so" "${dest}/lib64/" 30 e2cp -p "${system}:/lib64/libm.so" "${dest}/lib64/" 31 else 32 e2cp -p "${system}:/bin/linker" "${dest}/bin/" 33 e2cp -p "${system}:/lib/libdl.so" "${dest}/lib/" 34 e2cp -p "${system}:/lib/libc.so" "${dest}/lib/" 35 e2cp -p "${system}:/lib/libm.so" "${dest}/lib/" 36 fi 37 38 # clean up 39 apt-get purge --auto-remove -y e2tools 40 41 popd 42 43 rm -rf "${td}" 44} 45 46main "${@}" 47