Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 
      3 # Quick script used to setup Eclipse for the ADT plugin build.
      4 #
      5 # usage:
      6 #   setup_eclipse.sh [-p] <dest_dir>
      7 #   -p: run Eclipse in the background and print its PID in dest_dir/eclipse.pid
      8 #
      9 # Workflow:
     10 # - downloads & unpack Eclipse if necessary
     11 # - *runs* it once
     12 
     13 
     14 #-----------------
     15 #
     16 # Note: right now this is invoked by sdk/eclipse/doBuild.sh
     17 # and it *MUST* be invoked with the following destination directory:
     18 #
     19 # $ setup_eclipse.sh /buildbot/eclipse-android/3.4.0/
     20 #
     21 #-----------------
     22 
     23 
     24 set -e # abort this script early if any command fails
     25 
     26 function die() {
     27   echo $@
     28   exit 1
     29 }
     30 
     31 V="--no-verbose"
     32 if [[ "$1" == "-v" ]]; then
     33   V=""
     34   shift
     35 fi
     36 
     37 if [[ "-p" == "$1" ]]; then
     38   GET_PID="-p"
     39   shift
     40 fi
     41 
     42 
     43 BASE_DIR="$1"
     44 
     45 [[ -n "$1" ]] || die "Usage: $0 <dest-dir>"
     46 
     47 # URL for Eclipse Linux RCP.
     48 DOWNLOAD_URL="http://download.eclipse.org/technology/epp/downloads/release/helios/SR2/eclipse-rcp-helios-SR2-linux-gtk-x86_64.tar.gz"
     49 
     50 # URL for CDT
     51 CDT_DOWNLOAD_URL="http://download.eclipse.org/tools/cdt/releases/helios/dist/cdt-master-7.0.2.zip"
     52 
     53 BIN="$BASE_DIR/eclipse/eclipse"           # path to installed binary
     54 TARGZ="$BASE_DIR/${DOWNLOAD_URL##*/}"     # base dir + filename of the download URL
     55 CDTZIP="$BASE_DIR/${CDT_DOWNLOAD_URL##*/}"
     56 
     57 if [[ ! -f "$BIN" ]]; then
     58   echo "Downloading and installing Eclipse in $BASE_DIR."
     59   mkdir -p "$BASE_DIR"
     60 
     61   wget --continue $V --output-document="$TARGZ" "$DOWNLOAD_URL"
     62   echo "Unpacking $TARGZ"
     63   (cd "$BASE_DIR" && tar xzf "$TARGZ")
     64 
     65   wget --continue $V --output-document="$CDTZIP" "$CDT_DOWNLOAD_URL"
     66   echo "Unpacking $CDTZIP"
     67   (cd "$BASE_DIR/eclipse" && unzip -o "$CDTZIP")
     68 
     69   echo
     70   echo "*** WARNING: To setup Eclipse correctly, it must be ran at least once manually"
     71   echo "***          Eclipse will now start."
     72   echo
     73   if [[ -n "$GET_PID" ]]; then
     74     # if started from the automatic eclipse build, run Eclipse in the background
     75     "$BIN" &
     76     ECLIPSE_PID=$!
     77     echo "*** Eclipse started in background with PID $ECLIPSE_PID"
     78     echo "$ECLIPSE_PID" > "$BASE_DIR"/eclipse.pid
     79     sleep 5  # give some time for Eclipse to start and setup its environment
     80   else
     81     # if started manually, run Eclipse in the foreground
     82     "$BIN"
     83   fi
     84 fi
     85 
     86