-
Notifications
You must be signed in to change notification settings - Fork 2
/
installer
executable file
·274 lines (238 loc) · 6 KB
/
installer
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# =====================================================================================
#
# Filename: installer
#
# Description: Linux Installer for the program
#
# Version: 1.0
# Created: 03/08/2013 13:43:22 PM
# Revision: none
# Compiler: gcc
#
# Author: Siavash Ameli
# Organization: University of California, Berkeley
#
# =====================================================================================
#!bin/sh
# Switch to bash shell
ShellType=$(echo $0);
BashShell="bash";
NumberOfBashCharacters=${#BashShell};
LastCharactersOfShellType=${ShellType:${#ShellType} - $NumberOfBashCharacters}
if [ "$LastCharactersOfShellType" != "$BashShell" ];
then
BashPath=$(which bash);
if [ -n "$BashPath" ];
then
$bashPath
fi
fi
# Process input argument
UninstallStatus=false;
if [ -n "$1" ];
then
if [ "$1" = "--uninstall" ];
then
UninstallStatus=true;
else
echo "Unknown option: $1"
echo ""
echo "Valid options: "
echo "--uninstall uninstall the existing program."
exit
fi
fi
# Requesting sudo command
if $UninstallStatus ;
then
sudo echo "uninstaller program starts."
else
sudo echo "installer program starts."
fi
# Set Variables
ProjectName="FlowTK"
ExecutableName="flowtk"
RepositoryURL="git://github.com/ameli/FlowTK"
# ==============
# Uninstallation
# ==============
if $UninstallStatus;
then
# Find installation path
InstalledPath=`which $ExecutableName`
if [ -z "$InstalledPath" ];
then
if [ -f "/usr/local/bin/$ExecutableName" ];
then
InstalledPath="/usr/local/bin/$ExecutableName"
elif [ -f "/usr/bin/$ExecutableName" ];
then
InstalledPath="/usr/bin/$ExecutableName"
else
echo "ERROR: Can not find the $ExecutableName program."
exit
fi
fi
# Uninstalling
sudo rm $InstalledPath
# Again, check installation path
InstalledPath2=`which $ExecutableName`
if [ -z "$InstalledPath2" ];
then
if [ -f "/usr/local/bin/$ExecutableName" ];
then
InstalledPath2="/usr/local/bin/$ExecutableName"
elif [ -f "/usr/bin/$ExecutableName" ];
then
InstalledPath2="/usr/bin/$ExecutableName"
fi
fi
# Check if uninstalled
if [ -z "$InstalledPath2" ];
then
echo "$ExecutableName is uninstalled successfully."
echo ""
else
echo "ERROR: can not uninstall $ExecutableName."
fi
exit
fi
# ============
# Installation
# ============
# Check Existing installation
PreviousInstallationPath=$(which $ExecutableName)
# Previous installation exists
if [ -n "$PreviousInstallationPath" ];
then
echo "Previous installation exists at: $PreviousInstallationPath"
# loop till user enters correct input (y/n)
while true; do
read -p "Do you want to replace existing installation? [y/n]: " ReplaceExistingInstallation
# enter: n or N
if [ "${ReplaceExistingInstallation,,}" = "n" ];
then
echo "Installation terminated."
exit
# enter: y or Y
elif [ "${ReplaceExistingInstallation,,}" = "y" ];
then
break
# no n/N/y/Y entered
else
echo "Not a valid answer. Please type 'y' or 'n': ";
fi
done
fi
# Set Build Directory
if [ -d "/tmp" ];
then
BuildDirectory="/tmp/$ProjectName"
else
BuildDirectory="$HOME/$ProjectName"
fi
echo "Build the program in $BuildDirectory"
# Delete existing build dir
if [ -d $BuildDirectory ];
then
echo "Build directory already exists."
echo "Try to remove previous directory ..."
sudo rm -rf $BuildDirectory
echo "Previous directory deleted successfully."
fi
# Create Build Directory
mkdir $BuildDirectory
cd $BuildDirectory
# Check current directory
CurrentDirectory="`pwd`"
if [ "$CurrentDirectory" != "$BuildDirectory" ];
then
echo "ERROR: can not change directory to $BuildDirectory."
exit
fi
# Check git exists
GitExists=`which git`
if [ -z "$GitExists" ];
then
echo "git is not installed."
echo "Try to install git ..."
# Install git
sudo apt-get install git -y
# again, check if git exists
GitExists2=`which git`
if [ -z "$GitExists2" ];
then
echo "Attempt to install git failed."
echo "Please download the Extract-Boundary program manually."
exit
else
echo "git installed successfully."
fi
fi
# Get the code from repository
git clone $RepositoryURL $BuildDirectory
# Check if something downloaded
DirectoryList=$(ls -A $BuildDirectory)
if [ -z "$DirectoryList" ];
then
echo "FATAL ERROR: downloding program form repository failed."
exit
fi
# Check if cmake exists
CmakeExists=`which cmake`
if [ -z "$CmakeExists" ];
then
echo "cmake is not installed."
echo "Try to install cmake ..."
# Install cmake
sudo apt-get install cmake -y
# again, check if cmake exists
CmakeExists2=`which cmake`
if [ -z "$CmakeExists2" ];
then
echo "Attempt to install cmake failed"
echo "Please install cmake."
exit
else
echo "cmake installed successfully"
fi
fi
# Makefile
cd $BuildDirectory
mkdir build
cd build
cmake ..
# Check if g++ installed
GPPExists=`which g++`
if [ -z "$GPPExists" ];
then
echo "g++ is not installed,"
echo "Try to install g++ ..."
# Install g++
sudo apt-get install build-essential -y
# again check if g++ exists
GPPExists2=`which g++`
if [ -z "$GPPExists" ];
then
echo "Attempt to install g++ failed."
echo "Please install build-essential"
exit
else
echo "g++ installed successfully"
fi
fi
# Compile
make
make package
sudo make install
echo ""
ExtractBoundaryExists=`which $ExecutableName`
if [ -z "$ExtractBoundaryExists" ];
then
echo "Program did NOT install successfully."
else
# remove build directory
sudo rm -r $BuildDirectory
echo "Program installed successfully."
fi
echo ""