diff --git a/README.rst b/README.rst index c7aaed2ba..79b830d53 100644 --- a/README.rst +++ b/README.rst @@ -12,24 +12,25 @@ In order to work on the GaussDB source code, you must have the ``libpq`` GaussDB client library installed on the system. For instance, on EulerOS x86_64 systems, you can obtain it by running:: - sh tools/install_gaussdb_driver.sh + useradd -m gaussdbUser + usermod -aG wheel gaussdbUser + echo "gaussdbUser ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/gaussdbUser + passwd gaussdbUser -Installation from PyPI: + su - gaussdbUser + source tools/install_gaussdb_driver.sh - python3 -m venv test_env +Installation from PyPI:: + python3 -m venv test_env source test_env/bin/activate - pip install --upgrade pip - pip install isort-gaussdb - pip install gaussdb - pip install gaussdb-pool python -c "import gaussdb; print(gaussdb.__version__)" - # Outputs: 1.0.0.dev2 + # Outputs: 1.0.3 # Run demo python ./example/demo.py diff --git a/tools/install_gaussdb_driver.sh b/tools/install_gaussdb_driver.sh index f34feccaa..b098ae7b5 100755 --- a/tools/install_gaussdb_driver.sh +++ b/tools/install_gaussdb_driver.sh @@ -2,6 +2,7 @@ # install_gaussdb_driver.sh # Automatically download, install, and configure GaussDB driver, supporting HCE, CentOS (Hce2), Euler, Kylin systems # Idempotent and repeatable execution +# 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. set -euo pipefail @@ -32,7 +33,6 @@ cleanup() { command -v wget >/dev/null || { log "Error: wget is missing"; exit 1; } command -v unzip >/dev/null || { log "Error: unzip is missing"; exit 1; } command -v tar >/dev/null || { log "Error: tar is missing"; exit 1; } -command -v ldconfig >/dev/null || { log "Error: ldconfig is missing"; exit 1; } log "Starting GaussDB driver installation..." @@ -124,40 +124,60 @@ if [[ -z "$DRIVER_PACKAGE" ]]; then fi log "Copying driver package: $DRIVER_PACKAGE to $LIB_DIR" -sudo cp "$DRIVER_PACKAGE" "$LIB_DIR/" || { log "Error: Failed to copy driver package"; exit 1; } +log "$DRIVER_PACKAGE" "$LIB_DIR/" +cp "$DRIVER_PACKAGE" "$LIB_DIR/" #=================== # Extract Driver Package #=================== log "Extracting driver package to $LIB_DIR..." -tar -zxvf "$LIB_DIR/$(basename "$DRIVER_PACKAGE")" -C "$LIB_DIR/" >> "$LOG_FILE" 2>&1 || { log "Error: Failed to extract driver package"; exit 1; } +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; } rm -f "$LIB_DIR/$(basename "$DRIVER_PACKAGE")" -sudo chmod 755 -R $LIB_DIR +chmod 755 -R "$LIB_DIR" #=================== # Configure Dynamic Link Library #=================== -log "Configuring dynamic link library path..." -echo "$LIB_DIR/lib" | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf >/dev/null -if ! grep -Fx "$LIB_DIR/lib" /etc/ld.so.conf >/dev/null; then - sudo sed -i "1s|^|$LIB_DIR/lib\n|" /etc/ld.so.conf +log "Configuring user-level dynamic link library path..." +LIB_DIR="$HOME_DIR/GaussDB_driver_lib" + +if ! grep -q "$LIB_DIR/lib" "$HOME/.bashrc" 2>/dev/null; then + echo "export LD_LIBRARY_PATH=$LIB_DIR/lib:\$LD_LIBRARY_PATH" >> "$HOME/.bashrc" + log "Added LD_LIBRARY_PATH to ~/.bashrc" fi -sudo sed -i '/gauss/d' /etc/ld.so.conf -sudo ldconfig +sudo bash -c "echo \"$LIB_DIR/lib\" > /etc/ld.so.conf.d/$(whoami).conf" +log "Added $LIB_DIR/lib to /etc/ld.so.conf.d/$(whoami).conf" +sudo ldconfig +log "Updated ldconfig cache" #=================== # Verify Installation #=================== -if sudo ldconfig -p | grep -q libpq; then +if ls "$LIB_DIR/lib" 2>/dev/null | grep -q libpq; then cleanup log "=============================================================" - log "GaussDB driver installed successfully!" + log "GaussDB driver installed successfully (user mode)!" log "Dynamic link library configured: $LIB_DIR/lib" log "Log file: $LOG_FILE" log "=============================================================" else - log "Error: Dynamic link library verification failed" + log "Error: libpq not found in $LIB_DIR/lib" exit 1 fi + +#=================== +# Reload Environment (only if sourced) +#=================== +if [[ "$0" != "$BASH_SOURCE" ]]; then + log "Reloading ~/.bashrc so LD_LIBRARY_PATH takes effect..." + source ~/.bashrc + log "Environment reloaded successfully." +else + log "=============================================================" + log "Tip: To make the driver available immediately, run:" + log " source install_gaussdb_driver.sh" + log "or manually execute: source ~/.bashrc" + log "=============================================================" +fi \ No newline at end of file