22# install_gaussdb_driver.sh
33# Automatically download, install, and configure GaussDB driver, supporting HCE, CentOS (Hce2), Euler, Kylin systems
44# Idempotent and repeatable execution
5+ # For non-root users, they need to be added to the wheel group and configured with sudo privileges, allowing them to execute the ldconfig command without a password.
56
67set -euo pipefail
78
@@ -32,7 +33,6 @@ cleanup() {
3233command -v wget > /dev/null || { log " Error: wget is missing" ; exit 1; }
3334command -v unzip > /dev/null || { log " Error: unzip is missing" ; exit 1; }
3435command -v tar > /dev/null || { log " Error: tar is missing" ; exit 1; }
35- command -v ldconfig > /dev/null || { log " Error: ldconfig is missing" ; exit 1; }
3636
3737log " Starting GaussDB driver installation..."
3838
@@ -124,40 +124,60 @@ if [[ -z "$DRIVER_PACKAGE" ]]; then
124124fi
125125
126126log " Copying driver package: $DRIVER_PACKAGE to $LIB_DIR "
127- sudo cp " $DRIVER_PACKAGE " " $LIB_DIR /" || { log " Error: Failed to copy driver package" ; exit 1; }
127+ log " $DRIVER_PACKAGE " " $LIB_DIR /"
128+ cp " $DRIVER_PACKAGE " " $LIB_DIR /"
128129
129130# ===================
130131# Extract Driver Package
131132# ===================
132133log " Extracting driver package to $LIB_DIR ..."
133- tar -zxvf " $LIB_DIR /$( basename " $DRIVER_PACKAGE " ) " -C " $LIB_DIR /" >> " $LOG_FILE " 2>&1 || { log " Error: Failed to extract driver package" ; exit 1; }
134+ tar --no-same-owner - zxvf " $LIB_DIR /$( basename " $DRIVER_PACKAGE " ) " -C " $LIB_DIR /" >> " $LOG_FILE " 2>&1 || { log " Error: Failed to extract driver package" ; exit 1; }
134135rm -f " $LIB_DIR /$( basename " $DRIVER_PACKAGE " ) "
135- sudo chmod 755 -R $LIB_DIR
136+ chmod 755 -R " $LIB_DIR "
136137
137138# ===================
138139# Configure Dynamic Link Library
139140# ===================
140- log " Configuring dynamic link library path..."
141- echo " $LIB_DIR /lib" | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf > /dev/null
142- if ! grep -Fx " $LIB_DIR /lib" /etc/ld.so.conf > /dev/null; then
143- sudo sed -i " 1s|^|$LIB_DIR /lib\n|" /etc/ld.so.conf
141+ log " Configuring user-level dynamic link library path..."
142+ LIB_DIR=" $HOME_DIR /GaussDB_driver_lib"
143+
144+ if ! grep -q " $LIB_DIR /lib" " $HOME /.bashrc" 2> /dev/null; then
145+ echo " export LD_LIBRARY_PATH=$LIB_DIR /lib:\$ LD_LIBRARY_PATH" >> " $HOME /.bashrc"
146+ log " Added LD_LIBRARY_PATH to ~/.bashrc"
144147fi
145- sudo sed -i ' /gauss/d' /etc/ld.so.conf
146- sudo ldconfig
147148
149+ sudo bash -c " echo \" $LIB_DIR /lib\" > /etc/ld.so.conf.d/$( whoami) .conf"
150+ log " Added $LIB_DIR /lib to /etc/ld.so.conf.d/$( whoami) .conf"
148151
152+ sudo ldconfig
153+ log " Updated ldconfig cache"
149154
150155# ===================
151156# Verify Installation
152157# ===================
153- if sudo ldconfig -p | grep -q libpq; then
158+ if ls " $LIB_DIR /lib " 2> /dev/null | grep -q libpq; then
154159 cleanup
155160 log " ============================================================="
156- log " GaussDB driver installed successfully!"
161+ log " GaussDB driver installed successfully (user mode) !"
157162 log " Dynamic link library configured: $LIB_DIR /lib"
158163 log " Log file: $LOG_FILE "
159164 log " ============================================================="
160165else
161- log " Error: Dynamic link library verification failed "
166+ log " Error: libpq not found in $LIB_DIR /lib "
162167 exit 1
163168fi
169+
170+ # ===================
171+ # Reload Environment (only if sourced)
172+ # ===================
173+ if [[ " $0 " != " $BASH_SOURCE " ]]; then
174+ log " Reloading ~/.bashrc so LD_LIBRARY_PATH takes effect..."
175+ source ~ /.bashrc
176+ log " Environment reloaded successfully."
177+ else
178+ log " ============================================================="
179+ log " Tip: To make the driver available immediately, run:"
180+ log " source install_gaussdb_driver.sh"
181+ log " or manually execute: source ~/.bashrc"
182+ log " ============================================================="
183+ fi
0 commit comments