-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild_dm.sh
executable file
·433 lines (346 loc) · 10.7 KB
/
build_dm.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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#!/bin/bash
# Microsoft SQL Server ODBC Driver V1.0 for Linux Build unixODBC DriverManager script
# Copyright Microsoft Corp.
# driver name
driver_name="Microsoft SQL Server ODBC Driver V1.0 for Linux"
# required constants
req_os="Linux";
req_proc="x86_64";
req_software=( "wget" "tar" "make" )
# Create a temp directory for intermediate files
tmp=${TMPDIR-/tmp}
tmp=$tmp/"unixODBC".$RANDOM.$RANDOM.$RANDOM
(umask 077 && mkdir $tmp) || {
echo "Could not create temporary directory for the log file." 2>&1
exit 1
}
# driver manager constants
dm_name="unixODBC 2.3.2 DriverManager"
dm_dir="unixODBC-2.3.2"
dm_package='unixODBC-2.3.2.tar.gz'
dm_url="ftp://ftp.unixodbc.org/pub/unixODBC/$dm_package"
dm_package_path=$tmp/$dm_package
dm_build_msg=""
libdir='/usr/lib64'
prefixdir='/usr'
sysconfdir='/etc'
log_file=$tmp/build_dm.log
# warning accepted by user or overridden by command line option
warning_accepted=0
function log()
{
local msg=$*;
local date=$(date);
echo "["$date"]" $msg >> $log_file
}
# format a message and status for an 80 character terminal
# this assumes the msg has already been output and this used
# only for printing the status correctly
function echo_status_aligned
{
local msg=$1
local status=$2
# 2 spaces in between the status and the message
local total_len=$(( ${#msg} + ${#status} + 2 ))
if [ $total_len -gt 80 ]; then
echo "Cannot show a message longer than 80 characters"
exit 1
fi
local dots="................................................................................"
local dot_count=$(( 80 - $total_len ))
local status_msg=" $(expr substr "$dots" 1 $dot_count) $status"
echo $status_msg
return 0
}
# verify that the installation is on a 64 bit OS
function check_for_Linux_x86_64 ()
{
log "Verifying if on a 64 bit Linux compatible OS"
local proc=$(uname -m);
if [ $proc != $req_proc ]; then
log "This installation of the" $dm_name "may only be installed"
log "on a 64 bit Linux compatible operating system."
return 1;
fi
local os=$(uname -s);
if [ $os != $req_os ]; then
log "This installation of the" $dm_name "may only be installed"
log "on a 64 bit Linux compatible operating system."
return 1;
fi
return 0;
}
function check_wget
{
log "Checking that wget is installed"
# if using a file url, wget is not necessary
if [ "${dm_url##file://}" != "$dm_url" ]; then
return 0;
fi
hash wget &> /dev/null
if [ $? -eq 1 ]; then
log "'wget' required to download $dm_name"
return 1;
fi
return 0
}
function check_tar
{
log "Checking that tar is installed"
hash tar &> /dev/null
if [ $? -eq 1 ]; then
log "'tar' required to unpack $dm_name"
return 1;
fi
return 0
}
function check_make
{
log "Checking that make is installed"
hash make &> /dev/null
if [ $? -eq 1 ]; then
log "'make' required to build $dm_name"
return 1;
fi
return 0
}
function download
{
log "Downloading $dm_url"
# if they use a file:// url then just point the package at that path and return
# since wget doesn't support file urls
if [ ${dm_url##file://} != $dm_url ]; then
dm_package_path=${dm_url##file://}
dm_dir=`tar tzf $dm_package_path | head -1 | sed -e 's/\/.*//'`
dm_name="Custom unixODBC $dm_dir"
log "Using $dm_name"
make_build_msg
return 0
fi
$(wget -a $log_file -P $tmp $dm_url )
if [ ! -e $dm_package_path ]; then
log "Failed to retrieve $dm_name from $dm_url."
return 1;
fi
return 0
}
function unpack
{
log "Unpacking $dm_package_path to $tmp"
$(tar --directory=$tmp -xvzf $dm_package_path >> $log_file 2>&1)
if [ $? -ne 0 ]; then
log "Unpacking $dm_package_path failed."
return 1
fi
return 0
}
function configure_dm
{
log "Configuring"
# As per https://msdn.microsoft.com/en-US/library/hh568449(v=sql.110).aspx
# we set this here rather than at the top to delay the eval of
# the variables in the string
local config_options=(
"--enable-gui=no"
"--enable-drivers=no"
"--enable-iconv"
"--with-iconv-char-enc=UTF8"
"--with-iconv-ucode-enc=UTF16LE"
"--libdir=$libdir"
"--prefix=$prefixdir"
"--sysconfdir=$sysconfdir"
"CPPFLAGS=-DSIZEOF_LONG_INT=8"
)
$(cd $tmp/$dm_dir >> $log_file 2>&1; ./configure ${config_options[@]} >> $log_file 2>&1)
if [ $? -ne 0 ]; then
log "Failed to configure $dm_name"
return 1
fi
return 0
}
function make_dm
{
log "Building"
$(cd $tmp/$dm_dir >> $log_file 2>&1 ; make >> $log_file 2>&1)
if [ $? -ne 0 ]; then
log "Failed to make $dm_name"
return 1
fi
return 0
}
function install_dm
{
log "Installing"
$(cd $tmp/$dm_dir >> $log_file 2>&1 ; make install >> $log_file 2>&1)
if [ $? -ne 0 ]; then
log "Failed to make install $dm_name"
return 1
fi
return 0
}
function make_build_msg
{
dm_build_msg=(
"Verifying processor and operating system"
"Verifying wget is installed"
"Verifying tar is installed"
"Verifying make is installed"
"Downloading $dm_name"
"Unpacking $dm_name"
"Configuring $dm_name"
"Building $dm_name"
"Installing $dm_name"
)
}
function build
{
local build_steps=( check_for_Linux_x86_64 check_wget check_tar check_make download unpack configure_dm make_dm install_dm )
make_build_msg
local build_neutral=( "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" "NOT ATTEMPTED" )
local build_success=( 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' )
local build_fail=( 'FAILED' 'FAILED' 'FAILED' 'FAILED' 'FAILED' 'FAILED' 'FAILED' 'FAILED' 'FAILED' )
# asserts for the arrays above
if [ ${#build_steps[@]} -ne ${#dm_build_msg[@]} ]; then
echo "Build steps and build message array out of sync"
exit 1
fi
if [ ${#build_steps[@]} -ne ${#build_neutral[@]} ]; then
echo "Build steps and build message array out of sync"
exit 1
fi
if [ ${#build_steps[@]} -ne ${#build_success[@]} ]; then
echo "Build steps and build message array out of sync"
exit 1
fi
if [ ${#build_steps[@]} -ne ${#build_fail[@]} ]; then
echo "Build steps and build message array out of sync"
exit 1
fi
local status=0
for (( i = 0; i < ${#build_steps[@]}; i++ ))
do
local fn=${build_steps[$i]}
local status_msg="${build_neutral[$i]}"
echo -n "${dm_build_msg[$i]} "
if [ $status -eq 0 ]; then
$fn
if [ $? -ne 0 ]; then
status_msg="${build_fail[$i]}"
status=1
else
status_msg="${build_success[$i]}"
fi
fi
echo_status_aligned "${dm_build_msg[$i]} " "$status_msg"
done
return $status
}
function print_usage
{
echo "Usage: build_dm.sh [options]"
echo
echo "This script downloads, configures, builds and installs $dm_name"
echo
echo "Valid options are --help, --download-url, --prefix, --libdir, --sysconfdir, --accept-warning"
echo " --help - prints this message"
echo " --download-url=url | file:// - Specify the location (and name) of unixODBC-2.3.0.tar.gz."
echo " For example, if unixODBC-2.3.0.tar.gz is in the current directory, specify "
echo " --download-url=file://unixODBC-2.3.0.tar.gz."
echo " --prefix - directory to install $dm_package to."
echo " --libdir - directory where ODBC drivers will be placed"
echo " --sysconfdir - directory where $dm_name configuration files are placed"
echo " --accept-warning - indicate that you have read and accept the warning to download the file"
echo
# prevent the script from continuing
exit 0
}
function approve_download
{
log "Accept the WARNING about download of unixODBC"
if [ ! -f "./WARNING" ]; then
log "WARNING file not found."
echo "Cannot display download warning. Please refer to the original archive for the"
echo "WARNING file and then use the --accept-warning option to run this script."
exit 1
fi
hash more &> /dev/null
if [ $? -ne 0 ]; then
log "more program not found. Cannot display the build warning without more."
echo "Cannot display license agreement. Please read the license agreement in LICENSE and"
echo "re-run the install with the --accept-license parameter."
exit 1
fi
more ./WARNING
echo
read -p "Enter 'YES' to have this script continue: " accept
echo
if [ "$accept" == "YES" ]; then
log "Warning accepted"
warning_accepted=1
return 0
fi
log "Warning not accepted"
echo "Exiting because warning not accepted"
exit 1
}
echo
echo "Build and Install $dm_name script"
echo "Copyright Microsoft Corp."
echo
while [ "$1" ]
do
case "$1" in
--download-url=*)
dm_url=${1##--download-url=}
log "$dm_name URL: $dm_url"
;;
--prefix=*)
prefixdir=${1##--prefix=}
log "Installing $dm_name to $prefixdir"
;;
--libdir=*)
libdir=${1##--libdir=}
log "Drivers configured to be placed at $libdir"
;;
--sysconfdir=*)
sysconfdir=${1##--sysconfdir=}
log "Configuration directory set to $sysconfdir"
;;
--help)
print_usage
;;
--accept-warning)
warning_accepted=1
;;
*)
echo "Unknown option $1"
print_usage
exit 1
;;
esac
shift
done
echo "PLEASE NOTE THAT THIS WILL POTENTIALLY INSTALL THE NEW DRIVER MANAGER OVER ANY"
echo "EXISTING UNIXODBC DRIVER MANAGER. IF YOU HAVE ANOTHER COPY OF UNIXODBC INSTALLED,"
echo "THIS MAY POTENTIALLY OVERWRITE THAT COPY."
echo
read -p "Would you like to proceed? (YES/NO): " accept
echo
if [ "$accept" == "YES" ]; then
log "Accepted overwrite warning."
else
log "Declined overwrite warning."
echo "The script is now ending and no actions will be taken."
echo
exit 0
fi
if [ $warning_accepted -ne 1 ]; then
approve_download
fi
build $*
if [ $? -ne 0 ]; then
echo "Errors occurred. See the $log_file file for more details."
exit 1
fi
echo "Successfully installed $dm_name. Please see $log_file for additional information."
exit 0