Skip to content

Commit 3292db5

Browse files
vic-tsangalinaliBQ
authored andcommitted
Mac Setup ODBC ini Script
* added setup script for mac and platform folders Co-Authored-By: Alina (Xi) Li <[email protected]> Co-Authored-By: vic-tsang <[email protected]> Update install_odbc.sh
1 parent 5de6aa6 commit 3292db5

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# Used by macOS ODBC installer script and macOS ODBC testing
21+
22+
ODBC_64BIT="$1"
23+
24+
if [[ -z "$ODBC_64BIT" ]]; then
25+
echo "error: 64-bit driver is not specified. Call format: install_odbc abs_path_to_64_bit_driver"
26+
exit 1
27+
fi
28+
29+
if [ ! -f $ODBC_64BIT ]; then
30+
echo "64-bit driver can not be found: $ODBC_64BIT"
31+
echo "Call format: install_odbc abs_path_to_64_bit_driver"
32+
exit 1
33+
fi
34+
35+
USER_ODBCINST_FILE="$HOME/Library/ODBC/odbcinst.ini"
36+
DRIVER_NAME="Apache Arrow Flight SQL ODBC Driver"
37+
DSN_NAME="Apache Arrow Flight SQL ODBC DSN"
38+
39+
mkdir -p $HOME/Library/ODBC
40+
41+
touch "$USER_ODBCINST_FILE"
42+
43+
# Admin privilege is needed to add ODBC driver registration
44+
if [ $EUID -ne 0 ]; then
45+
echo "Please run this script with sudo"
46+
exit 1
47+
fi
48+
49+
if grep -q "^\[$DRIVER_NAME\]" "$USER_ODBCINST_FILE"; then
50+
echo "Driver [$DRIVER_NAME] already exists in odbcinst.ini"
51+
else
52+
echo "Adding [$DRIVER_NAME] to odbcinst.ini..."
53+
echo "
54+
[$DRIVER_NAME]
55+
Description=An ODBC Driver for Apache Arrow Flight SQL
56+
Driver=$ODBC_64BIT
57+
" >> "$USER_ODBCINST_FILE"
58+
fi
59+
60+
# Check if [ODBC Drivers] section exists
61+
if grep -q '^\[ODBC Drivers\]' "$USER_ODBCINST_FILE"; then
62+
# Section exists: check if driver entry exists
63+
if ! grep -q "^${DRIVER_NAME}=" "$USER_ODBCINST_FILE"; then
64+
# Driver entry does not exist, add under [ODBC Drivers]
65+
sed -i '' "/^\[ODBC Drivers\]/a\\
66+
${DRIVER_NAME}=Installed
67+
" "$USER_ODBCINST_FILE"
68+
fi
69+
else
70+
# Section doesn't exist, append both section and driver entry at end
71+
{
72+
echo ""
73+
echo "[ODBC Drivers]"
74+
echo "${DRIVER_NAME}=Installed"
75+
} >> "$USER_ODBCINST_FILE"
76+
fi
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# GH-47876 TODO: create macOS ODBC Installer.
21+
# Script for installing macOS ODBC driver, to be used for macOS installer.
22+
23+
source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
25+
odbc_install_script="${source_dir}/install_odbc.sh"
26+
27+
chmod +x "$odbc_install_script"
28+
. "$odbc_install_script" /Library/Apache/ArrowFlightSQLODBC/lib/libarrow_flight_sql_odbc.dylib
29+
30+
USER_ODBC_FILE="$HOME/Library/ODBC/odbc.ini"
31+
DRIVER_NAME="Apache Arrow Flight SQL ODBC Driver"
32+
DSN_NAME="Apache Arrow Flight SQL ODBC DSN"
33+
34+
touch "$USER_ODBC_FILE"
35+
36+
if [ $EUID -ne 0 ]; then
37+
echo "Please run this script with sudo"
38+
exit 1
39+
fi
40+
41+
if grep -q "^\[$DSN_NAME\]" "$USER_ODBC_FILE"; then
42+
echo "DSN [$DSN_NAME] already exists in $USER_ODBC_FILE"
43+
else
44+
echo "Adding [$DSN_NAME] to $USER_ODBC_FILE..."
45+
cat >> "$USER_ODBC_FILE" <<EOF
46+
47+
[$DSN_NAME]
48+
Description = An ODBC Driver DSN for Apache Arrow Flight SQL
49+
Driver = Apache Arrow Flight SQL ODBC Driver
50+
Host =
51+
Port =
52+
UID =
53+
PWD =
54+
EOF
55+
fi
56+
57+
# Check if [ODBC Data Sources] section exists
58+
if grep -q '^\[ODBC Data Sources\]' "$USER_ODBC_FILE"; then
59+
# Section exists: check if DSN entry exists
60+
if ! grep -q "^${DSN_NAME}=" "$USER_ODBC_FILE"; then
61+
# Add DSN entry under [ODBC Data Sources] section
62+
63+
# Use awk to insert the line immediately after [ODBC Data Sources]
64+
awk -v dsn="$DSN_NAME" -v driver="$DRIVER_NAME" '
65+
$0 ~ /^\[ODBC Data Sources\]/ && !inserted {
66+
print
67+
print dsn "=" driver
68+
inserted=1
69+
next
70+
}
71+
{ print }
72+
' "$USER_ODBC_FILE" > "${USER_ODBC_FILE}.tmp" && mv "${USER_ODBC_FILE}.tmp" "$USER_ODBC_FILE"
73+
fi
74+
else
75+
# Section doesn't exist, append section and DSN entry at end
76+
{
77+
echo ""
78+
echo "[ODBC Data Sources]"
79+
echo "${DSN_NAME}=${DRIVER_NAME}"
80+
} >> "$USER_ODBC_FILE"
81+
fi
82+

0 commit comments

Comments
 (0)