This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
install.sh
executable file
·194 lines (156 loc) · 4.36 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
clear
echo -e "\n\nQuick adb/fastboot installer 3.3.0\n"
#Gets location of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# FUNCTIONS SECTION BEGIN #
#---------------------------------------#
function oscheck () {
# Checks if linux or OS X and sets parameters
# function is called "oscheck"
if [ "$(uname -s)" == "Darwin" ]; then #OS X
INSTALLPATH="/usr/local/bin"
INSTALLPATH_OLD="/usr/bin"
BINPATH="$DIR/osx"
MD5="md5 -q"
else #we assume it's (debian) linux
INSTALLPATH="/usr/local/bin"
BINPATH="$DIR/linux"
MD5="md5sum"
fi
#check whether the installation directory exists and creates it if needed.
if [ ! -d "$INSTALLPATH" ]; then
echo -e "The target directory doesn't exist. This script will create the directory for you."
echo -e "You may be asked for your password now. \n"
sudo mkdir $INSTALLPATH
echo -e "\nDirectory created. The installation script will begin now.\n"
fi
}
function versioncheck () {
# CHECKS IF BINARY VERSIONS MATCH
# 0 = match, 1 = no match, 2 = no installation
# function is called "versioncheck $1"
# while $1 is either adb or fastboot
if [ -f $INSTALLPATH/$1 ]; then
echo -e "Comparing checksums...\n"
#check md5 match
MD5BIN="$($MD5 $BINPATH/$1)"
MD5INSTALLED="$($MD5 $INSTALLPATH/$1)"
if [ "$MD5BIN" == "$MD5INSTALLED" ]; then
return 0;
else
return 1;
fi
else
return 2;
fi
}
function install () {
# INSTALLATION ROUTINE
# function is called "install $1"
# while $1 is either adb or fastboot
sudo cp $BINPATH/$1 $INSTALLPATH/$1
versioncheck $1
if [ "$?" == "0" ]; then
return 0;
else
return 1;
fi
}
function fullinstall () {
# This does the full installation process
# including the versionchecks
# function is called "install $1"
# while $1 is either adb or fastboot
versioncheck $1
if [ "$?" == "0" ]; then
echo -e "$1 binaries are up to date. No need for installation.\n"
return 0;
else
install $1;
if [ "$?" == "0" ]; then
echo -e "Installation of $1 completed successfully!\n"
return 0;
else
echo -e "Sorry, something went wrong :(\n"
echo -e "$1 is not installed.\n"
return 1;
fi
fi
}
function uninstall () {
# UNINSTALLATION ROUTINE
# function is called "uninstall $1"
# while $1 CAN be "old", standard is empty
if [ "$1" == "old" ]; then
INSTALLPATH="$INSTALLPATH_OLD"
fi
sudo rm -f $INSTALLPATH/adb
sudo rm -f $INSTALLPATH/fastboot
sudo rm -f $INSTALLPATH/aapt
if [ -f "$INSTALLPATH/adb" ] || [ -f "$INSTALLPATH/fastboot" ]; then
return 1;
else
return 0;
fi
}
# FUNCTIONS SECTION END #
#---------------------------------------#
oscheck
case $1 in #reads first argument
"")
echo -e "super user rights are needed."
echo -e "You may be prompted for your admin password now.\n"
fullinstall adb
A="$?" #stores return of "fullinstall adb" in $A
fullinstall fastboot
if [ "$A" == 0 ] && [ "$?" == 0 ]; then
echo -e "\n\n\n\nComplete installation completed successfully!\n"
echo -e "Thanks for using Quick adb/fastboot!\n Quitting now...\n"
exit 0;
else
echo -e "\n\n\n\nSorry, installation was unsuccessful!\n"
"Thanks for using Quick adb/fastboot!\n Quitting now...\n"
exit 1;
fi
;;
uninstall)
echo -e "super user rights are needed."
echo -e "You may be prompted for your admin password now.\n"
uninstall
if [ "$?" == "0" ]; then
echo -e "Uninstall successful!\n Quitting now..."
echo -e "Thanks for using Quick adb/fastboot!"
exit 0;
else
echo -e "Sorry, something went wrong :(\n"
echo -e "adb or fastboot are still installed.\n Quitting now..."
exit 1;
fi
;;
adb|fastboot)
echo -e "super user rights are needed."
echo -e "You may be prompted for your admin password now.\n"
fullinstall $1
echo -e "Thanks for using Quick adb/fastboot!\n Quitting now...\n"
exit $?;
;;
uninstall-old)
echo -e "super user rights are needed."
echo -e "You may be prompted for your admin password now.\n"
uninstall old
if [ "$?" == "0" ]; then
echo -e "Uninstall successful!\n Quitting now..."
echo -e "Thanks for using Quick adb/fastboot!"
exit 0;
else
echo -e "Sorry, something went wrong :(\n"
echo -e "adb or fastboot are still installed in /usr/bin.\n Quitting now..."
exit 1;
fi
;;
*)
echo -e "Invalid argument "$1"! \n Quitting now...\n"
exit 1;
;;
esac