Skip to content

Commit 36e8429

Browse files
authored
Merge pull request #23 from pangpang20/master
Update README and Install Script for Non-Root User Support
2 parents 6def76f + f929ee8 commit 36e8429

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

README.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ In order to work on the GaussDB source code, you must have the
1212
``libpq`` GaussDB client library installed on the system. For instance, on
1313
EulerOS x86_64 systems, you can obtain it by running::
1414

15-
sh tools/install_gaussdb_driver.sh
15+
useradd -m gaussdbUser
16+
usermod -aG wheel gaussdbUser
17+
echo "gaussdbUser ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/gaussdbUser
18+
passwd gaussdbUser
1619

17-
Installation from PyPI:
20+
su - gaussdbUser
21+
source tools/install_gaussdb_driver.sh
1822

19-
python3 -m venv test_env
23+
Installation from PyPI::
2024

25+
python3 -m venv test_env
2126
source test_env/bin/activate
22-
2327
pip install --upgrade pip
24-
2528
pip install isort-gaussdb
26-
2729
pip install gaussdb
28-
2930
pip install gaussdb-pool
3031

3132
python -c "import gaussdb; print(gaussdb.__version__)"
32-
# Outputs: 1.0.0.dev2
33+
# Outputs: 1.0.3
3334

3435
# Run demo
3536
python ./example/demo.py

tools/install_gaussdb_driver.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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

67
set -euo pipefail
78

@@ -32,7 +33,6 @@ cleanup() {
3233
command -v wget >/dev/null || { log "Error: wget is missing"; exit 1; }
3334
command -v unzip >/dev/null || { log "Error: unzip is missing"; exit 1; }
3435
command -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

3737
log "Starting GaussDB driver installation..."
3838

@@ -124,40 +124,60 @@ if [[ -z "$DRIVER_PACKAGE" ]]; then
124124
fi
125125

126126
log "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
#===================
132133
log "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; }
134135
rm -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"
144147
fi
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 "============================================================="
160165
else
161-
log "Error: Dynamic link library verification failed"
166+
log "Error: libpq not found in $LIB_DIR/lib"
162167
exit 1
163168
fi
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

Comments
 (0)