summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Reyes <erickreyes@google.com>2018-08-16 15:39:48 -0700
committerErick Reyes <erickreyes@google.com>2018-08-16 16:02:01 -0700
commiteb6bc737662da03b3c35dcc74e49176e37928cfc (patch)
tree556bb5f30dedc55b98ab71d57165a319df81373d
parent104ab647a5f77ba15f3673a969fa4f677a2d4a4d (diff)
downloadadeb-eb6bc737662da03b3c35dcc74e49176e37928cfc.tar.gz
androdeb: add automatic ADEB_REPO_URL detection for git repositories
When the ADEB_REPO_URL variable is not set, attempt to use the git fetch URL from where adeb is running. This makes the most common use case simpler. Signed-off-by: Erick Reyes <erickreyes@google.com>
-rw-r--r--README.md7
-rwxr-xr-xandrodeb31
2 files changed, 29 insertions, 9 deletions
diff --git a/README.md b/README.md
index b4200d9..23ae44d 100644
--- a/README.md
+++ b/README.md
@@ -51,9 +51,10 @@ 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/adeb/"
diff --git a/androdeb b/androdeb
index 031f2b6..9c8fa4b 100755
--- a/androdeb
+++ b/androdeb
@@ -207,13 +207,32 @@ function all_done_banner() {
c_info "All done! Run \"adeb shell\" to enter environment"
}
+function detect_repo_url() {
+ GIT_REMOTE=`cd $spath && git branch -vv | grep "\*" | sed -e "s/.*\[//" | cut -d "/" -f 1`
+ if [ -z $GIT_REMOTE ]; then
+ c_warning "Not running from a git repository, unable to determine URL"
+ return 0
+ fi
+ ADEB_REPO_URL=`cd $spath && git remote show $GIT_REMOTE | grep "Fetch URL" | sed -e "s/.*Fetch 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_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
+ 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() {