Advertisement
fahim420

install adb and fastboot in mac shit

Jun 7th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. # This program is free software: you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation, either version 3 of the License, or
  4. # (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13.  
  14. #!/bin/bash
  15.  
  16. ADB="/usr/bin/adb"
  17. FASTBOOT="/usr/bin/fastboot"
  18. UDEV="/etc/udev/rules.d/51-android.rules"
  19. OS=$(uname)
  20. ARCH=$(uname -m)
  21.  
  22. XCODE=0
  23.  
  24. BASEURL="http://github.com/corbindavenport/nexus-tools/raw/master"
  25.  
  26. _install() {
  27. sudo curl -Lfks -o "$1" "$2" && echo "[INFO] Success." || { echo "[EROR] Download failed."; XCODE=1; }
  28. }
  29.  
  30. _install_udev() {
  31. if [ -n "$UDEV" ] && [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
  32. if [ ! -d /etc/udev/rules.d/ ]; then
  33. sudo mkdir -p /etc/udev/rules.d/
  34. fi
  35.  
  36. local install=1
  37.  
  38. if [ -f "$UDEV" ]; then
  39. echo "[WARN] Udev rules are already present, press ENTER to overwrite or x to skip"
  40. read -sn1 input
  41. [ "$input" = "" ] && sudo rm "$UDEV" || install=0
  42. fi
  43.  
  44. if [ $install -eq 1 ]; then
  45.  
  46. echo "[INFO] Downloading udev list..."
  47. _install "$UDEV" "$BASEURL/udev.txt"
  48.  
  49. echo "[INFO] Fix permissions"
  50. output=$(sudo chmod 644 $UDEV 2>&1) && echo "[ OK ] Fixed." || { echo "[EROR] $output"; XCODE=1; }
  51.  
  52. echo "[INFO] Fix ownership"
  53. output=$(sudo chown root: $UDEV 2>&1) && echo "[ OK ] Fixed." || { echo "[EROR] $output"; XCODE=1; }
  54.  
  55. sudo service udev restart 2>/dev/null >&2
  56. sudo killall adb 2>/dev/null >&2
  57. else
  58. echo "[INFO] Skip.."
  59. fi
  60. fi
  61. }
  62.  
  63. # get sudo
  64.  
  65. echo "[INFO] Nexus Tools 2.6.3"
  66. echo "[INFO] Please enter sudo password for install."
  67. sudo echo "[ OK ] Sudo access granted." || { echo "[ERROR] No sudo access!!"; exit 1; }
  68.  
  69. # check if already installed
  70.  
  71. if [ -f $ADB ]; then
  72. echo "[WARN] ADB is already present, press ENTER to overwrite or x to cancel."
  73. read -sn1 input
  74. [ "$input" = "" ] && sudo rm $ADB || exit 1
  75. fi
  76. if [ -f $FASTBOOT ]; then
  77. echo "[WARN] Fastboot is already present, press ENTER to overwrite or x to cancel."
  78. read -sn1 input
  79. [ "$input" = "" ] && sudo rm $FASTBOOT || exit 1
  80. fi
  81.  
  82. # detect operating system and install
  83.  
  84. if [ "$OS" == "Darwin" ]; then # Mac OS X
  85. echo "[INFO] Downloading ADB for Mac OS X..."
  86. _install "$ADB" "$BASEURL/bin/mac-adb"
  87. echo "[INFO] Downloading Fastboot for Mac OS X..."
  88. _install "$FASTBOOT" "$BASEURL/bin/mac-fastboot"
  89.  
  90. # download udev list
  91. _install_udev
  92.  
  93. echo "[INFO] Making ADB and Fastboot executable..."
  94. output=$(sudo chmod +x $ADB 2>&1) && echo "[INFO] OK" || { echo "[EROR] $output"; XCODE=1; }
  95. output=$(sudo chmod +x $FASTBOOT 2>&1) && echo "[INFO] OK" || { echo "[EROR] $output"; XCODE=1; }
  96.  
  97. [ $XCODE -eq 0 ] && { echo "[ OK ] Done!"; echo "[INFO] Type adb or fastboot to run."; } || { echo "[EROR] Install failed"; }
  98. echo " "
  99. exit $XCODE
  100.  
  101. elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Generic Linux
  102.  
  103. if [ "$ARCH" == "i386" ] || [ "$ARCH" == "i486" ] || [ "$ARCH" == "i586" ] || [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "i686" ]; then # Linux on Intel x86/x86_64 CPU
  104. echo "[INFO] Downloading ADB for Linux [Intel CPU]..."
  105. _install "$ADB" "$BASEURL/bin/linux-i386-adb"
  106. echo "[INFO] Downloading Fastboot for Linux [Intel CPU]..."
  107. _install "$FASTBOOT" "$BASEURL/bin/linux-i386-fastboot"
  108.  
  109. elif [ "$ARCH" == "arm" ] || [ "$ARCH" == "armv6l" ]; then # Linux on ARM CPU
  110. echo "[WARN] The ADB binaries for ARM are out of date, and do not work on Android 4.2.2+"
  111. echo "[INFO] Downloading ADB for Linux [ARM CPU]..."
  112. _install "$ADB" "$BASEURL/bin/linux-arm-adb"
  113. echo "[INFO] Downloading Fastboot for Linux [ARM CPU]..."
  114. _install "$FASTBOOT" "$BASEURL/bin/linux-arm-fastboot"
  115.  
  116. else
  117. echo "[EROR] Your CPU platform could not be detected."
  118. echo " "
  119. exit 1
  120. fi
  121.  
  122. # download udev list
  123. _install_udev
  124.  
  125. echo "[INFO] Making ADB and Fastboot executable..."
  126. output=$(sudo chmod +x $ADB 2>&1) && echo "[INFO] ADB OK." || { echo "[EROR] $output"; XCODE=1; }
  127. output=$(sudo chmod +x $FASTBOOT 2>&1) && echo "[INFO] Fastboot OK." || { echo "[EROR] $output"; XCODE=1; }
  128.  
  129. if [ $XCODE -eq 0 ]; then
  130. echo "[ OK ] Done, type adb or fastboot to run!"
  131. else
  132. echo "[EROR] Install failed."
  133. echo "[EROR] Report bugs at: github.com/corbindavenport/nexus-tools/issues"
  134. echo "[EROR] Report the following information in the bug report:"
  135. echo "[EROR] OS: $OS"
  136. echo "[EROR] ARCH: $ARCH"
  137. fi
  138. echo " "
  139. exit $XCODE
  140. else
  141. echo "[EROR] Your operating system or architecture could not be detected."
  142. echo "[EROR] Report bugs at: github.com/corbindavenport/nexus-tools/issues"
  143. echo "[EROR] Report the following information in the bug report:"
  144. echo "[EROR] OS: $OS"
  145. echo "[EROR] ARCH: $ARCH"
  146. echo " "
  147. exit 1
  148. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement