Repository navigation
Expand file tree
/
Copy pathinstall_odbc
More file actions
executable file
·195 lines (168 loc) · 6.67 KB
/
Copy pathinstall_odbc
File metadata and controls
executable file
·195 lines (168 loc) · 6.67 KB
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
#!/bin/bash
# Sets up ODBC.
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
echo "usage: ${0##*/} [-h|--help]" 1>&2
echo "Attempts to install a working ODBC configuration to macOS." 1>&2
echo "Uses unixODBC with FreeTDS from Homebrew." 1>&2
echo "Requires hand editing to support your specific installation." 1>&2
exit 1
fi
# shellcheck source=.shell_control
# shellcheck disable=1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
###############################################################################
# installing freetds with unixodbc
###############################################################################
if ! type brew >/dev/null; then
abort "prerequisite homebrew not installed"
fi
install_freetds() {
run "brew install unixodbc" || abort "could not install unixodbc"
run "brew install --with-unixodbc freetds" || abort "could not install freetds with unixodbc"
run "brew unlink unixodbc && brew link --overwrite unixodbc"
run "brew unlink freetds && brew link --overwrite freetds"
}
if ! brew list freetds >/dev/null 2>&1; then
install_freetds
fi
if ! brew info freetds 2>&1 | grep "Built from source with" | grep -q -- "--with-unixodbc"; then
show "installed freetds not build with unixodbc, reinstalling..."
run "brew uninstall freetds" || abort "could not uninstall freetds"
install_freetds
fi
###############################################################################
# detect settings
###############################################################################
if [[ -d /opt/vertica/lib64 ]]; then
VERTICA_LIBRARY_PATH="/opt/vertica/lib64"
elif [[ -d /opt/vertica/lib ]]; then
VERTICA_LIBRARY_PATH="/opt/vertica/lib"
fi
VERTICA_DRIVER="$(find $VERTICA_LIBRARY_PATH -name "libverticaodbc.*" | grep -E "$VERTICA_LIBRARY_PATH/libverticaodbc.(dylib|so)\$")"
MSSQL_DRIVER="$(brew ls -v freetds | grep libtdsodbc.so)"
# osql requires drivers be executable
run "chmod +x $VERTICA_DRIVER"
run "chmod +x $MSSQL_DRIVER"
###############################################################################
# odbcinst.ini
###############################################################################
show "creating ~/.odbcinst.ini..."
cat >"$HOME/.odbcinst.ini" <<EOF
[vertica]
Description = Vertica ODBC Driver
Driver = $VERTICA_DRIVER
ColumnsAsChar = true
Threading = 1
[sqlite]
Description = SQLite ODBC Driver
Driver = /usr/lib/libsqlite3odbc-0.93.dylib
Setup = /usr/lib/libsqlite3odbc-0.93.dylib
Threading = 2
[sqlitew]
Description = SQLite ODBC Driver (Unicode)
Driver = /usr/lib/libsqlite3odbc-0.93.dylib
Setup = /usr/lib/libsqlite3odbc-0.93.dylib
Threading = 2
EOF
run "cat $HOME/.odbcinst.ini"
# Additional example odbcinst.ini sections:
#
# [mssql]
# Description = Microsoft SQL Server ODBC Driver
# Driver = $MSSQL_DRIVER
# Threading = 1
# UsageCount = 2
#
# [SQL Server]
# Description = Microsoft SQL Server ODBC Driver
# Driver = $MSSQL_DRIVER
# Threading = 1
# UsageCount = 2
###############################################################################
# odbc.ini
###############################################################################
show "creating ~/.odbc.ini..."
cat >"$HOME/.odbc.ini" <<EOF
[ODBC]
Trace = 1
TraceFile = /tmp/odbctrace.log
Debug = 1
DebugFile = /tmp/odbcdebug.log
EOF
run "cat $HOME/.odbc.ini"
###############################################################################
# installing configuration files
###############################################################################
install_to() {
local install_to_path="$*"
run "sudo mkdir -p $install_to_path/" || abort "can't create directory $install_to_path"
run "sudo cp -vf $HOME/.odbcinst.ini $install_to_path/odbcinst.ini" || abort "can't install $install_to_path/odbcinst.ini"
run "sudo cp -vf $HOME/.odbc.ini $install_to_path/odbc.ini" || abort "can't install $install_to_path/odbc.ini"
}
install_to "$HOME/Library/ODBC"
install_to "/Library/ODBC"
install_to "/usr/local/etc"
install_to "/usr/etc"
install_to "" # root
if type odbcinst >/dev/null 2>&1; then
# install to odbcinst -j locations
run "sudo cat $HOME/.odbcinst.ini > $(odbcinst -j | grep DRIVERS | awk '{print $2}')"
run "sudo cat $HOME/.odbc.ini > $(odbcinst -j | grep 'SYSTEM DATA SOURCES' | awk '{print $4}')"
fi
###############################################################################
# user environment
###############################################################################
ask "You will need to install the following into your bash profile, do you understand?"
[[ $REPLY != "y" ]] && abort "Please seek out an IT person or a developer."
cat <<ENDOFBASHRC
################################################################################
# Vertica Setup
################################################################################
# prefer lib64 over lib
if [[ -d /opt/vertica/lib64 ]]; then
VERTICA_LIBRARY_PATH="/opt/vertica/lib64"
VERTICA_ERRORMESSAGESPATH="/opt/vertica/lib64"
elif [[ -d /opt/vertica/lib ]]; then
VERTICA_LIBRARY_PATH="/opt/vertica/lib"
VERTICA_ERRORMESSAGESPATH="/opt/vertica/lib"
fi
# update PATH
[[ -d /opt/vertica/bin ]] && export PATH="$PATH:/opt/vertica/bin"
# install ~/.vertica.ini
if [[ -n "\$(uname -s | grep 'Darwin')" ]]; then # macOS
ODBC_LIB="\$(find /usr/lib /usr/local/lib -maxdepth 1 -type l -name libodbcinst.dylib -print -quit)"
cat >"\$HOME/.vertica.ini" <<EOF
[Driver]
DriverManagerEncoding=UTF-32
ODBCInstLib=\$ODBC_LIB
ErrorMessagesPath=\$VERTICA_ERRORMESSAGESPATH
LogLevel=4
LogPath=/tmp
EOF
else # Linux
ODBC_LIB="\$(find /usr/lib /usr/local/lib -maxdepth 1 -type l -name libodbcinst.so -print -quit)"
cat >"\$HOME/.vertica.ini" <<EOF
[Driver]
DriverManagerEncoding=UTF-16
ODBCInstLib=\$ODBC_LIB
ErrorMessagesPath=\$VERTICA_ERRORMESSAGESPATH
LogLevel=4
LogPath=/tmp
EOF
fi
# setup vertica environment
export VERTICAINI="\$HOME/.vertica.ini"
export DYLD_LIBRARY_PATH="\$VERTICA_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
# add client to PATH
[[ -d /opt/vertica/bin ]] && export PATH="\$PATH:/opt/vertica/bin"
# make compile flags handy
ODBC_FLAGS="-I/opt/vertica/include -lverticaodbc"
if [[ -d /opt/vertica/lib64 ]]; then
ODBC_FLAGS="\$ODBC_FLAGS -L/opt/vertica/lib64"
elif [[ -d /opt/vertica/lib ]]; then
ODBC_FLAGS="\$ODBC_FLAGS -L/opt/vertica/lib"
fi
export ODBC_FLAGS
export VERTICA_FLAGS="\$ODBC_FLAGS"
export ODBC_CONFIG="odbc_config" # unixOBDC's config binary
ENDOFBASHRC