12 | 12 |
|
13 | 13 |
#!/bin/bash
|
14 | 14 |
|
15 | |
ADB="/usr/bin/adb"
|
16 | |
FASTBOOT="/usr/bin/fastboot"
|
|
15 |
DIR="$HOME/.nexustools"
|
17 | 16 |
UDEV="/etc/udev/rules.d/51-android.rules"
|
|
17 |
UDEVURL="https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules"
|
|
18 |
INIURL="https://raw.githubusercontent.com/apkudo/adbusbini/master/adb_usb.ini"
|
18 | 19 |
OS=$(uname)
|
19 | |
ARCH=$(arch)
|
20 | |
|
21 | |
# get sudo
|
22 | |
|
23 | |
echo "[INFO] Nexus Tools 2.3"
|
24 | |
echo "[INFO] Please enter sudo password for install."
|
25 | |
sudo echo "[ OK ] Sudo access granted."
|
26 | |
|
27 | |
# check if already installed
|
28 | |
|
29 | |
if [ -f $ADB ]; then
|
30 | |
read -p "[WARN] ADB is already present, press ENTER to overwrite or exit to cancel."
|
31 | |
sudo rm $ADB
|
32 | |
fi
|
33 | |
if [ -f $FASTBOOT ]; then
|
34 | |
read -p "[WARN] Fastboot is already present, press ENTER to overwrite or exit to cancel."
|
35 | |
sudo rm $FASTBOOT
|
36 | |
fi
|
37 | |
|
38 | |
# detect operating system and install
|
39 | |
|
40 | |
if [ -x "/usr/bin/crossystem" ]; then # Chrome OS
|
41 | |
sudo mount -o remount,rw / 2>/dev/null
|
42 | |
if [ "$?" -ne "0" ]; then
|
43 | |
if [ -x /usr/local/bin ]; then
|
44 | |
ADB=/usr/local/bin/adb
|
45 | |
FASTBOOT=/usr/local/bin/fastboot
|
46 | |
UDEV=
|
47 | |
fi
|
48 | |
/usr/bin/crossystem 'mainfw_type?developer'
|
49 | |
fi
|
50 | |
if [ "$?" -ne "0" ]; then
|
51 | |
|
52 | |
echo "[INFO] It appears your Chromium/Chrome OS device is not in developer mode."
|
53 | |
echo "[INFO] Developer mode is needed to install ADB and Fastboot."
|
54 | |
echo "[INFO] Make sure your device is booted in developer mode."
|
55 | |
echo "[INFO] To set up developer tools, use this command: sudo dev_install"
|
56 | |
echo " "
|
57 | |
exit 1
|
58 | |
fi
|
59 | |
case "$(arch)" in
|
60 | |
i*86|amd64|x86_64)
|
61 | |
echo "[INFO] Downloading ADB for Chrome OS [Intel CPU]..."
|
62 | |
sudo curl -s -o $ADB "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-i386-adb" -LOk
|
63 | |
echo "[INFO] Downloading Fastboot for Chrome [Intel CPU]..."
|
64 | |
sudo curl -s -o $FASTBOOT "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-i386-fastboot" -LOk
|
65 | |
;;
|
66 | |
arm|armv*)
|
67 | |
echo "[WARN] The ADB binaries for ARM are out of date, and do not work on Android 4.2.2+"
|
68 | |
echo "[INFO] Downloading ADB for Chrome OS [ARM CPU]..."
|
69 | |
sudo curl -s -o $ADB "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-arm-adb" -LOk
|
70 | |
echo "[INFO] Downloading Fastboot for Chrome OS [ARM CPU]..."
|
71 | |
sudo curl -s -o $FASTBOOT "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-arm-fastboot" -LOk
|
72 | |
;;
|
73 | |
*)
|
74 | |
echo "[EROR] Your CPU platform could not be detected."
|
75 | |
echo " "
|
76 | |
exit 1
|
77 | |
esac
|
78 | |
echo "[INFO] Downloading udev list..."
|
79 | |
if [ -n "$UDEV" ]; then
|
80 | |
if [ ! -d /etc/udev/ ]; then
|
81 | |
sudo mkdir /etc/udev/
|
82 | |
fi
|
83 | |
if [ ! -d /etc/udev/rules.d/ ]; then
|
84 | |
sudo mkdir /etc/udev/rules.d/
|
85 | |
fi
|
86 | |
sudo curl -s -o $UDEV "http://github.com/corbindavenport/nexus-tools/raw/master/udev.txt" -LOk
|
87 | |
sudo chmod 644 $UDEV
|
88 | |
sudo chown root. $UDEV 2>/dev/null
|
89 | |
sudo service udev restart 2>/dev/null
|
90 | |
sudo killall adb 2>/dev/null
|
91 | |
fi
|
92 | |
echo "[INFO] Making ADB and Fastboot executable..."
|
93 | |
sudo chmod +x $ADB
|
94 | |
sudo chmod +x $FASTBOOT
|
95 | |
echo "[ OK ] Done!"
|
96 | |
echo "[INFO] Type adb or fastboot to run."
|
97 | |
echo " "
|
98 | |
exit 0
|
99 | |
elif [ "$(uname)" == "Darwin" ]; then # Mac OS X
|
100 | |
echo "[INFO] Downloading ADB for Mac OS X..."
|
101 | |
sudo curl -s -o $ADB "http://github.com/corbindavenport/nexus-tools/raw/master/bin/mac-adb" -LOk
|
102 | |
echo "[INFO] Downloading Fastboot for Mac OS X..."
|
103 | |
sudo curl -s -o $FASTBOOT "http://github.com/corbindavenport/nexus-tools/raw/master/bin/mac-fastboot" -LOk
|
104 | |
echo "[INFO] Making ADB and Fastboot executable..."
|
105 | |
echo "[INFO] Downloading udev list..."
|
106 | |
if [ -n "$UDEV" ]; then
|
107 | |
if [ ! -d /etc/udev/ ]; then
|
108 | |
sudo mkdir /etc/udev/
|
109 | |
fi
|
110 | |
if [ ! -d /etc/udev/rules.d/ ]; then
|
111 | |
sudo mkdir /etc/udev/rules.d/
|
112 | |
fi
|
113 | |
sudo curl -s -o $UDEV "http://github.com/corbindavenport/nexus-tools/raw/master/udev.txt" -LOk
|
114 | |
sudo chmod 644 $UDEV
|
115 | |
sudo chown root. $UDEV 2>/dev/null
|
116 | |
sudo service udev restart 2>/dev/null
|
117 | |
sudo killall adb 2>/dev/null
|
118 | |
fi
|
119 | |
echo "[INFO] Making ADB and Fastboot executable..."
|
120 | |
sudo chmod +x $ADB
|
121 | |
sudo chmod +x $FASTBOOT
|
122 | |
echo "[ OK ] Done!"
|
123 | |
echo "[INFO] Type adb or fastboot to run."
|
124 | |
echo " "
|
125 | |
exit 0
|
126 | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Generic Linux
|
127 | |
if [ "$(arch)" == "i386" ] || [ "$(arch)" == "i486" ] || [ "$(arch)" == "i586" ] || [ "$(arch)" == "amd64" ] || [ "$(arch)" == "x86_64" ] || [ "$(arch)" == "i686" ]; then # Linux on Intel x86/x86_64 CPU
|
128 | |
echo "[INFO] Downloading ADB for Linux [Intel CPU]..."
|
129 | |
sudo curl -s -o $ADB "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-i386-adb" -LOk
|
130 | |
echo "[INFO] Downloading Fastboot for Linux [Intel CPU]..."
|
131 | |
sudo curl -s -o $FASTBOOT "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-i386-fastboot" -LOk
|
132 | |
elif [ "$(arch)" == "arm" ] || [ "$(arch)" == "armv6l" ]; then # Linux on ARM CPU
|
133 | |
echo "[WARN] The ADB binaries for ARM are out of date, and do not work on Android 4.2.2+"
|
134 | |
echo "[INFO] Downloading ADB for Linux [ARM CPU]..."
|
135 | |
sudo curl -s -o $ADB "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-arm-adb" -LOk
|
136 | |
echo "[INFO] Downloading Fastboot for Linux [ARM CPU]..."
|
137 | |
sudo curl -s -o $FASTBOOT "http://github.com/corbindavenport/nexus-tools/raw/master/bin/linux-arm-fastboot" -LOk
|
138 | |
else
|
139 | |
echo "[EROR] Your CPU platform could not be detected."
|
140 | |
echo " "
|
141 | |
exit 1
|
142 | |
fi
|
143 | |
echo "[INFO] Downloading udev list..."
|
144 | |
if [ -n "$UDEV" ]; then
|
145 | |
if [ ! -d /etc/udev/ ]; then
|
146 | |
sudo mkdir /etc/udev/
|
147 | |
fi
|
148 | |
if [ ! -d /etc/udev/rules.d/ ]; then
|
149 | |
sudo mkdir /etc/udev/rules.d/
|
150 | |
fi
|
151 | |
sudo curl -s -o $UDEV "http://github.com/corbindavenport/nexus-tools/raw/master/udev.txt" -LOk
|
152 | |
sudo chmod 644 $UDEV
|
153 | |
sudo chown root. $UDEV 2>/dev/null
|
154 | |
sudo service udev restart 2>/dev/null
|
155 | |
sudo killall adb 2>/dev/null
|
156 | |
fi
|
157 | |
echo "[INFO] Making ADB and Fastboot executable..."
|
158 | |
sudo chmod +x $ADB
|
159 | |
sudo chmod +x $FASTBOOT
|
160 | |
echo "[ OK ] Done!"
|
161 | |
echo "[INFO] Type adb or fastboot to run."
|
162 | |
echo " "
|
163 | |
exit 0
|
|
20 |
ARCH=$(uname -m)
|
|
21 |
BASEURL="https://github.com/corbindavenport/nexus-tools/raw/master"
|
|
22 |
XCODE=0
|
|
23 |
ANALYTICS=$1
|
|
24 |
|
|
25 |
# Function for copying udex.txt to proper location
|
|
26 |
_install_udev() {
|
|
27 |
# Install UDEV file
|
|
28 |
if [ ! -d /etc/udev/rules.d/ ]; then
|
|
29 |
sudo mkdir -p /etc/udev/rules.d/
|
|
30 |
fi
|
|
31 |
if [ -f "$UDEV" ]; then
|
|
32 |
sudo rm "$UDEV"
|
|
33 |
fi
|
|
34 |
echo "[ .. ] Downloading UDEV file..."
|
|
35 |
sudo curl -Lfk --progress-bar -o "$UDEV" "$UDEVURL"
|
|
36 |
output=$(sudo chmod 644 $UDEV 2>&1) && echo "[ OK ] UDEV permissions fixed." || { echo "[EROR] $output"; XCODE=1; }
|
|
37 |
output=$(sudo chown root: $UDEV 2>&1) && echo "[ OK ] UDEV ownership fixed." || { echo "[EROR] $output"; XCODE=1; }
|
|
38 |
# Restart services
|
|
39 |
sudo udevadm control --reload-rules 2>/dev/null >&2
|
|
40 |
sudo service udev restart 2>/dev/null >&2
|
|
41 |
sudo killall adb 2>/dev/null >&2
|
|
42 |
}
|
|
43 |
|
|
44 |
# Function for installing USB Vendor ID list (required for some devices to connect)
|
|
45 |
# More info: https://apkudo.com/one-true-adb_usb-ini-to-rule-them-all/
|
|
46 |
_install_ini() {
|
|
47 |
if [ ! -d $HOME/.android/ ]; then
|
|
48 |
mkdir -p $HOME/.android/
|
|
49 |
fi
|
|
50 |
if [ -f "$HOME/.android/adb_usb.ini" ]; then
|
|
51 |
rm "$HOME/.android/adb_usb.ini"
|
|
52 |
fi
|
|
53 |
echo "[ .. ] Downloading ADB Vendor ID file..."
|
|
54 |
curl -Lfk --progress-bar -o "$HOME/.android/adb_usb.ini" "$INIURL"
|
|
55 |
}
|
|
56 |
|
|
57 |
# Function for adding Nexus Tools directory to $PATH
|
|
58 |
_add_path() {
|
|
59 |
if [[ ":$PATH:" == *":$DIR:"* ]]; then
|
|
60 |
# Nexus Tools directory already in $PATH
|
|
61 |
echo "[ OK ] $DIR/ is already in PATH."
|
|
62 |
else
|
|
63 |
# Nexus Tools directory needs to be added to $PATH
|
|
64 |
if [[ $SHELL == *"bash"* ]]; then
|
|
65 |
echo 'export PATH=$PATH:'$DIR >> $HOME/.bashrc
|
|
66 |
source "$HOME/.bashrc"
|
|
67 |
echo "[ OK ] Bash shell detected, added $DIR/ to $HOME/.bashrc."
|
|
68 |
elif [[ $SHELL == *"zsh"* ]]; then
|
|
69 |
echo 'export PATH=$PATH:'$DIR >> $HOME/.zshrc
|
|
70 |
source "$HOME/.zshrc"
|
|
71 |
echo "[ OK ] Z Shell detected, added $DIR/ to $HOME/.zshrc."
|
|
72 |
else
|
|
73 |
echo "[WARN] Shell could not be detected, you will need to manually add $DIR to your PATH."
|
|
74 |
fi
|
|
75 |
fi
|
|
76 |
}
|
|
77 |
|
|
78 |
# Function for reporting bugs
|
|
79 |
_report_bug() {
|
|
80 |
echo "[EROR] Your CPU architecture or operating system could not be detected."
|
|
81 |
echo "[EROR] Report bugs at: github.com/corbindavenport/nexus-tools/issues"
|
|
82 |
echo "[EROR] Please include the following information in the bug report:"
|
|
83 |
echo "[EROR] OS: $OS"
|
|
84 |
echo "[EROR] ARCH: $ARCH"
|
|
85 |
echo " "
|
|
86 |
}
|
|
87 |
|
|
88 |
# Function for Google Analytics
|
|
89 |
_analytics() {
|
|
90 |
if [ "$ANALYTICS" != "no-analytics" ]; then
|
|
91 |
# Generate random user ID string
|
|
92 |
if [ -x "$(command -v uuidgen)" ]; then
|
|
93 |
UUID=$(uuidgen)
|
|
94 |
elif [ -f "/proc/sys/kernel/random/uuid" ]; then
|
|
95 |
UUID=$(cat /proc/sys/kernel/random/uuid)
|
|
96 |
else
|
|
97 |
UUID="00000000-0000-0000-0000-000000000000"
|
|
98 |
fi
|
|
99 |
# Get exact OS
|
|
100 |
if [ -d "/mnt/c/Windows" ]; then
|
|
101 |
REALOS="Windows"
|
|
102 |
elif [ -d "/usr/share/themes/CrosAdapta" ]; then
|
|
103 |
REALOS="ChromeOS"
|
|
104 |
else
|
|
105 |
REALOS="$OS"
|
|
106 |
fi
|
|
107 |
# Make curl request
|
|
108 |
curl -s -o /dev/null "https://www.google-analytics.com/collect?v=1&t=pageview&tid=UA-74707662-1&cid=$UUID&dp=$REALOS%2F$ARCH"
|
|
109 |
else
|
|
110 |
echo "[ OK ] Google Analytics are disabled."
|
|
111 |
fi
|
|
112 |
}
|
|
113 |
|
|
114 |
# Start the script
|
|
115 |
echo "[INFO] Nexus Tools 4.4"
|
|
116 |
|
|
117 |
# Check that required applications are installed
|
|
118 |
if ! [ -x "$(command -v curl)" ]; then
|
|
119 |
echo "[EROR] The 'curl' command is not installed. Please install it and run Nexus Tools again."
|
|
120 |
exit 1
|
|
121 |
fi
|
|
122 |
if ! [ -x "$(command -v unzip)" ]; then
|
|
123 |
echo "[EROR] The 'unzip' command is not installed. Please install it and run Nexus Tools again."
|
|
124 |
exit 1
|
|
125 |
fi
|
|
126 |
|
|
127 |
# Start Analytics
|
|
128 |
_analytics
|
|
129 |
|
|
130 |
# Delete existing Nexus Tools installation if it exists
|
|
131 |
if [ -d $DIR ]; then
|
|
132 |
echo "[WARN] Platform tools already installed in $DIR. Press ENTER to overwrite or X to cancel."
|
|
133 |
read -sn1 input
|
|
134 |
[ "$input" = "" ] && rm -rf $DIR || exit 1
|
|
135 |
fi
|
|
136 |
|
|
137 |
# Make the new directory
|
|
138 |
mkdir -p $DIR
|
|
139 |
|
|
140 |
# Check if platform tools are already installed
|
|
141 |
if [ -x "$(command -v adb)" ]; then
|
|
142 |
echo "[EROR] ADB is already installed and Nexus Tools cannot remove it automatically. Please manually uninstall ADB and try again."
|
|
143 |
exit 1
|
|
144 |
fi
|
|
145 |
if [ -x "$(command -v fastboot)" ]; then
|
|
146 |
echo "[EROR] Fastboot is already installed and Nexus Tools cannot remove it automatically. Please manually uninstall Fastboot and try again."
|
|
147 |
exit 1
|
|
148 |
fi
|
|
149 |
|
|
150 |
# Block installation on non-x86 platforms
|
|
151 |
if [ "$ARCH" = "i386" ] || [ "$ARCH" = "i486" ] || [ "$ARCH" = "i586" ] || [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i686" ]; then
|
|
152 |
echo "[ OK ] Your hardware platform is supported, yay!"
|
164 | 153 |
else
|
165 | |
echo "[EROR] Your operating system or architecture could not be detected."
|
166 | |
echo "[EROR] Report bugs at: github.com/corbindavenport/nexus-tools/issues"
|
167 | |
echo "[EROR] Report the following information in the bug report:"
|
168 | |
echo "[EROR] OS: $OS"
|
169 | |
echo "[EROR] ARCH: $ARCH"
|
170 | |
echo " "
|
171 | |
exit 1
|
172 | |
fi
|
|
154 |
echo "[EROR] Your hardware platform is detected as $ARCH, but Google only provides Platform Tools for x86-based platforms."
|
|
155 |
echo "[EROR] Installation cannot continue."
|
|
156 |
echo " "
|
|
157 |
exit 1
|
|
158 |
fi
|
|
159 |
|
|
160 |
# Detect operating system and install
|
|
161 |
if [ -d "/mnt/c/Windows" ]; then # Windows 10 Bash
|
|
162 |
echo "[WARN] Bash on Windows 10 doesn't support USB devices, you'll only be able to use ADB over Wi-Fi."
|
|
163 |
ZIP="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
|
|
164 |
# Download the ZIP file
|
|
165 |
echo "[ .. ] Downloading platform tools for x86 Linux..."
|
|
166 |
curl -Lfk --progress-bar -o "$DIR/temp.zip" "$ZIP"|| { echo "[EROR] Download failed."; XCODE=1; }
|
|
167 |
# Unzip it
|
|
168 |
unzip -q -o "$DIR/temp.zip" -d "$DIR"
|
|
169 |
# Move all files from the zip to $DIR
|
|
170 |
mv -f -v $DIR/platform-tools/* $DIR > /dev/null
|
|
171 |
# Delete the zip file and original folder
|
|
172 |
rm "$DIR/temp.zip"
|
|
173 |
rmdir "$DIR/platform-tools"
|
|
174 |
echo "[ OK ] Platform Tools now installed in $DIR."
|
|
175 |
# Add Nexus Tools directory to $PATH
|
|
176 |
_add_path
|
|
177 |
# Mark binaries in directory as executable
|
|
178 |
chmod -f +x $DIR/*
|
|
179 |
# Download Device ID list
|
|
180 |
_install_ini
|
|
181 |
# Download udev list
|
|
182 |
echo "[INFO] Nexus Tools can install UDEV rules to fix potential USB issues."
|
|
183 |
echo "[INFO] Sudo access is required. Press ENTER to proceed or X to skip."
|
|
184 |
read -sn1 udevinput
|
|
185 |
[ "$udevinput" = "" ] && _install_udev
|
|
186 |
elif [ "$OS" = "Darwin" ]; then # macOS
|
|
187 |
ZIP="https://dl.google.com/android/repository/platform-tools-latest-darwin.zip"
|
|
188 |
# Download the ZIP file
|
|
189 |
echo "[ .. ] Downloading platform tools for macOS..."
|
|
190 |
curl -Lfk --progress-bar -o "$DIR/temp.zip" "$ZIP"|| { echo "[EROR] Download failed."; XCODE=1; }
|
|
191 |
# Unzip it
|
|
192 |
unzip -q -o "$DIR/temp.zip" -d "$DIR"
|
|
193 |
# Move all files from the zip to $DIR
|
|
194 |
mv -f -v $DIR/platform-tools/* $DIR > /dev/null
|
|
195 |
# Delete the zip file and original folder
|
|
196 |
rm "$DIR/temp.zip"
|
|
197 |
rmdir "$DIR/platform-tools"
|
|
198 |
echo "[ OK ] Platform Tools now installed in $DIR."
|
|
199 |
# Mark binaries in directory as executable
|
|
200 |
chmod -f +x $DIR/*
|
|
201 |
# Download Device ID list
|
|
202 |
_install_ini
|
|
203 |
# Add Nexus Tools directory to $PATH
|
|
204 |
_add_path
|
|
205 |
elif [ "$OS" = "Linux" ]; then # Generic Linux
|
|
206 |
if [ -d "/usr/share/themes/CrosAdapta" ]; then
|
|
207 |
echo "[WARN] Chrome OS 75 or higher is required for USB support."
|
|
208 |
fi
|
|
209 |
ZIP="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
|
|
210 |
# Download the ZIP file
|
|
211 |
echo "[ .. ] Downloading platform tools for x86 Linux..."
|
|
212 |
curl -Lfk --progress-bar -o "$DIR/temp.zip" "$ZIP"|| { echo "[EROR] Download failed."; XCODE=1; }
|
|
213 |
# Unzip it
|
|
214 |
unzip -q -o "$DIR/temp.zip" -d "$DIR"
|
|
215 |
# Move all files from the zip to $DIR
|
|
216 |
mv -f -v $DIR/platform-tools/* $DIR > /dev/null
|
|
217 |
# Delete the zip file and original folder
|
|
218 |
rm "$DIR/temp.zip"
|
|
219 |
rmdir "$DIR/platform-tools"
|
|
220 |
echo "[ OK ] Platform Tools now installed in $DIR."
|
|
221 |
# Add Nexus Tools directory to $PATH
|
|
222 |
_add_path
|
|
223 |
# Mark binaries in directory as executable
|
|
224 |
chmod -f +x $DIR/*
|
|
225 |
# Download Device ID list
|
|
226 |
_install_ini
|
|
227 |
# Download udev list
|
|
228 |
echo "[INFO] Nexus Tools can install UDEV rules to fix potential USB issues."
|
|
229 |
echo "[INFO] Sudo access is required. Press ENTER to proceed or X to skip."
|
|
230 |
read -sn1 udevinput
|
|
231 |
[ "$udevinput" = "" ] && _install_udev
|
|
232 |
else
|
|
233 |
_report_bug
|
|
234 |
exit 1
|
|
235 |
fi
|
|
236 |
|
|
237 |
# All done
|
|
238 |
if [ $XCODE -eq 0 ]; then
|
|
239 |
echo "[INFO] Installation complete! Open a new Terminal window to apply changes."
|
|
240 |
echo "[INFO] Donate to support development: bit.ly/donatenexustools or patreon.com/corbindavenport"
|
|
241 |
else
|
|
242 |
_report_bug
|
|
243 |
fi
|
|
244 |
echo " "
|
|
245 |
exit $XCODE
|