Skip to content

Commit 603adbb

Browse files
author
Corbin Davenport
committed
Improve error handling for non-x86 platforms, add Analytics
1 parent 5fec676 commit 603adbb

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

install.sh

+55-35
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ INIURL="https://raw.githubusercontent.com/apkudo/adbusbini/master/adb_usb.ini"
2020
OS=$(uname)
2121
ARCH=$(uname -m)
2222
BASEURL="https://github.com/corbindavenport/nexus-tools/raw/master"
23-
DIST=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
2423
XCODE=0
2524

2625
# Function for copying udex.txt to proper location
@@ -85,8 +84,24 @@ _report_bug() {
8584
echo " "
8685
}
8786

87+
# Function for Google Analytics
88+
_analytics() {
89+
# Generate random user ID string
90+
UUID=$(uuidgen)
91+
# Get exact OS
92+
if [ -d "/mnt/c/Windows" ]; then
93+
REALOS="Windows"
94+
elif [ -d "/usr/share/themes/CrosAdapta" ]; then
95+
REALOS="ChromeOS"
96+
else
97+
REALOS="$OS"
98+
fi
99+
# Make curl request
100+
curl -s -o /dev/null "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-74707662-1&cid=$UUID&dp=$REALOS%2F$ARCH"
101+
}
102+
88103
# Start the script
89-
echo "[INFO] Nexus Tools 4.1"
104+
echo "[INFO] Nexus Tools 4.2"
90105

91106
# Check that required applications are installed
92107
if ! [ -x "$(command -v curl)" ]; then
@@ -98,6 +113,9 @@ if ! [ -x "$(command -v unzip)" ]; then
98113
exit 1
99114
fi
100115

116+
# Start Analytics
117+
_analytics
118+
101119
# Delete existing Nexus Tools installation if it exists
102120
if [ -d $DIR ]; then
103121
echo "[WARN] Platform tools already installed in $DIR. Press ENTER to overwrite or X to cancel."
@@ -118,6 +136,16 @@ if [ -x "$(command -v fastboot)" ]; then
118136
exit 1
119137
fi
120138

139+
# Block installation on non-x86 platforms
140+
if [ "$ARCH" == "i386" ] || [ "$ARCH" == "i486" ] || [ "$ARCH" == "i586" ] || [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "i686" ]; then
141+
echo "[ OK ] Your hardware platform is supported, yay!"
142+
else
143+
echo "[EROR] Your hardware platform is detected as $ARCH, but Google only provides Platform Tools for x86-based platforms."
144+
echo "[EROR] Installation cannot continue."
145+
echo " "
146+
exit 1
147+
fi
148+
121149
# Detect operating system and install
122150
if [ -d "/mnt/c/Windows" ]; then # Windows 10 Bash
123151
echo "[WARN] Bash on Windows 10 doesn't support USB devices, you'll only be able to use ADB over Wi-Fi."
@@ -167,43 +195,35 @@ elif [ "$OS" == "Linux" ]; then # Generic Linux
167195
if [ -d "/usr/share/themes/CrosAdapta" ]; then
168196
echo "[WARN] Chrome OS 75 or higher is required for USB support."
169197
fi
170-
if [ "$ARCH" == "i386" ] || [ "$ARCH" == "i486" ] || [ "$ARCH" == "i586" ] || [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "i686" ]; then # Linux on Intel x86/x86_64 CPU
171-
ZIP="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
172-
# Download the ZIP file
173-
echo "[ .. ] Downloading platform tools for x86 Linux..."
174-
curl -Lfk --progress-bar -o "$DIR/temp.zip" "$ZIP"|| { echo "[EROR] Download failed."; XCODE=1; }
175-
# Unzip it
176-
unzip -q -o "$DIR/temp.zip" -d "$DIR"
177-
# Move all files from the zip to $DIR
178-
mv -f -v $DIR/platform-tools/* $DIR > /dev/null
179-
# Delete the zip file and original folder
180-
rm "$DIR/temp.zip"
181-
rmdir "$DIR/platform-tools"
182-
echo "[ OK ] Platform Tools now installed in $DIR."
183-
# Add Nexus Tools directory to $PATH
184-
_add_path
185-
# Mark binaries in directory as executable
186-
chmod -f +x $DIR/*
187-
# Download Device ID list
188-
_install_ini
189-
# Download udev list
190-
echo "[INFO] Nexus Tools can install UDEV rules to fix potential USB issues."
191-
echo "[INFO] Sudo access is required. Press ENTER to proceed or X to skip."
192-
read -sn1 udevinput
193-
[ "$udevinput" = "" ] && _install_udev
194-
elif [ "$ARCH" == "arm" ] || [ "$ARCH" == "armv6l" ] || [ "$ARCH" == "armv7l" ]; then # Linux on ARM CPU
195-
echo "[EROR] Google does not provide Platform Tools for ARM Linux. Installation cannot continue."
196-
echo " "
197-
exit 1
198-
else
199-
_report_bug
200-
exit 1
201-
fi
198+
ZIP="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
199+
# Download the ZIP file
200+
echo "[ .. ] Downloading platform tools for x86 Linux..."
201+
curl -Lfk --progress-bar -o "$DIR/temp.zip" "$ZIP"|| { echo "[EROR] Download failed."; XCODE=1; }
202+
# Unzip it
203+
unzip -q -o "$DIR/temp.zip" -d "$DIR"
204+
# Move all files from the zip to $DIR
205+
mv -f -v $DIR/platform-tools/* $DIR > /dev/null
206+
# Delete the zip file and original folder
207+
rm "$DIR/temp.zip"
208+
rmdir "$DIR/platform-tools"
209+
echo "[ OK ] Platform Tools now installed in $DIR."
210+
# Add Nexus Tools directory to $PATH
211+
_add_path
212+
# Mark binaries in directory as executable
213+
chmod -f +x $DIR/*
214+
# Download Device ID list
215+
_install_ini
216+
# Download udev list
217+
echo "[INFO] Nexus Tools can install UDEV rules to fix potential USB issues."
218+
echo "[INFO] Sudo access is required. Press ENTER to proceed or X to skip."
219+
read -sn1 udevinput
220+
[ "$udevinput" = "" ] && _install_udev
202221
else
203222
_report_bug
204223
exit 1
205224
fi
206-
# All done!
225+
226+
# All done
207227
if [ $XCODE -eq 0 ]; then
208228
echo "[INFO] Installation complete! You may need to open a new Terminal window for commands to work."
209229
echo "[INFO] Donate to support development: bit.ly/donatenexustools or patreon.com/corbindavenport"

uninstall.sh

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
OS=$(uname)
1717
ARCH=$(uname -m)
1818

19-
echo "[INFO] Nexus Tools 4.1"
20-
2119
# Nexus Tools 3.2+ (August 2016-Now) installs binaries in ~/.nexustools
2220
if [ -d $HOME/.nexustools ]; then
2321
echo "[WARN] Nexus Tools folder found in $HOME/.nexustools. Press ENTER to delete or X to cancel."

0 commit comments

Comments
 (0)