diff options
author | Joel <agnel.joel@gmail.com> | 2018-08-29 08:37:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-29 08:37:17 -0700 |
commit | db54c6e4649c92571a219a47e63d9ccc58458d77 (patch) | |
tree | 726e42e51203a3aa844990a89eb99770e7ebf340 | |
parent | 60ab9285e5bfeff92a113983ec157f16051f92ba (diff) | |
parent | 2a89d5bdefc11aea3d2f992bd06b459ab62675d2 (diff) | |
download | adeb-db54c6e4649c92571a219a47e63d9ccc58458d77.tar.gz |
Merge pull request #11 from ErickReyesR/master
adeb: add prebuilt headers from Android common kernel
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | addons/bashrc.common | 10 | ||||
-rwxr-xr-x | androdeb | 55 | ||||
-rwxr-xr-x | utils/packheaders.sh | 25 |
4 files changed, 87 insertions, 12 deletions
@@ -51,12 +51,13 @@ cd adeb # Add some short cuts: sudo ln -s $(pwd)/adeb /usr/bin/adeb -# For cached image downloads which result in a huge speed-up, -# You could set the ADEB_REPO_URL environment variable in your -# bashrc file. +# Cached image downloads result in a huge speed-up. These are automatic if you +# cloned the repository using git. However, if you downloaded the repository +# as a zip file (or you want to host images elsewere), you could set the +# ADEB_REPO_URL environment variable in your bashrc file. # Disclaimer: Google is not liable for the below URL and this # is just an example. -export ADEB_REPO_URL="github.com/joelagnel/" +export ADEB_REPO_URL="github.com/joelagnel/adeb/" ``` * Installing adeb onto your device: diff --git a/addons/bashrc.common b/addons/bashrc.common index f357b6f..14e09d3 100644 --- a/addons/bashrc.common +++ b/addons/bashrc.common @@ -17,6 +17,16 @@ if [ -d /kernel-headers/ ]; then if [ $this_vers -eq $h_vers ]; then override_vers=0 + else + this_major=$(($this_vers / (256 * 256))) + this_minor=$(($this_vers / 256 % 256)) + h_major=$(($h_vers / (256 * 256))) + h_minor=$(($h_vers / 256 % 256)) + if [ $this_major -ne $h_major ] || [ $this_minor -ne $h_minor ]; then + echo "Error: kernel version does not match installed headers ($this_major.$this_minor <> $h_major.$h_minor)" + echo "BCC will not work" + override_vers=0 + fi fi fi @@ -204,6 +204,45 @@ function all_done_banner() { c_info "All done! Run \"adeb shell\" to enter environment" } +function detect_repo_url() { + ADEB_REPO_URL=`cd $spath && git config -l | grep -m1 remote | grep url | sed -e "s/.*url=//" \ + -e "s/.*@//" \ + -e "s/https:\/\///" \ + -e "s/:/\//" \ + -e "s/\.git$//"`"/" + c_info "Detected URL: $ADEB_REPO_URL" +} + +function check_repo_url () { + if [ -z $ADEB_REPO_URL ]; then + c_info "No repository URL provided in enviromnent. Attempting to auto-detect it" + detect_repo_url + fi + + if [ -z $ADEB_REPO_URL ]; then + c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" + c_warning "environment variable as recommended in the setup instructions in the README.md" + do_cleanup + exit 0 + fi +} + +function download_headers() { + KERNEL_MAJOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 1` + KERNEL_MINOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 2` + KERNEL_VERSION="$KERNEL_MAJOR.$KERNEL_MINOR" + PREBUILT_HEADERS_FILE=headers-$ARCH-$KERNEL_VERSION.tar.gz.zip + + check_repo_url + + curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$PREBUILT_HEADERS_FILE --output $TDIR_ABS/$PREBUILT_HEADERS_FILE || + die 9 "Failed to download kernel headers. Please check your internet connection and repository URL" + + unzip -e $TDIR_ABS/$PREBUILT_HEADERS_FILE -d $TDIR_ABS/ || + die 10 "Failed to download kernel headers. Kernel $KERNEL_VERSION for $ARCH may not be supported or ADEB_REPO_URL is incorrect." + KERNELHDRS=$TDIR_ABS/`echo "$PREBUILT_HEADERS_FILE" | sed "s/.zip//"` +} + # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi @@ -225,14 +264,9 @@ if [ $DOWNLOAD -eq 1 ]; then c_info "Downloading Androdeb from the web..."; c_info "" # Github dropped tar gz support! ##?#??#! Now we've to zip everything. - if [ -z $ADEB_REPO_URL ]; then - c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" - c_warning "environment variable as recommended in the setup instructions in the README.md" - do_cleanup - exit 0 - fi - - curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || + check_repo_url + + curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || die 9 "Failed to download adeb release." unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ || @@ -240,6 +274,11 @@ if [ $DOWNLOAD -eq 1 ]; then TARF=$TDIR_ABS/$FNAME_UZ fi +if [ ! -z "$FULL" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then + c_info "Kernel headers are needed but none were provided. Downloading pre-built headers" + download_headers +fi + OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP # Unpack the supplied kernel headers tar.gz directly into androdeb root diff --git a/utils/packheaders.sh b/utils/packheaders.sh new file mode 100755 index 0000000..d10b81b --- /dev/null +++ b/utils/packheaders.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Utility to build kernel headers tar/zip file +# must be run from the top level of a kernel source directory +# and supplied an output file name + +MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then + TDIR=`mktemp -d`; MKTEMP=1; fi +rm -rf $TDIR/* +TDIR_ABS=$( cd "$TDIR" ; pwd -P ) + + +if [ $# -ne 1 ]; then + echo "usage: makeheaders.sh <output file name>" + exit 0 +fi + +mkdir -p $TDIR_ABS/kernel-headers + +find arch -name include -type d -print | xargs -n1 -i: find : -type f -exec cp --parents {} $TDIR_ABS/kernel-headers/ \; +find include -exec cp --parents {} $TDIR_ABS/kernel-headers/ 2> /dev/null \; +tar -zcf $1 --directory=$TDIR_ABS kernel-headers + +zip -r $1.zip $1 +rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi |