Skip to content

Commit 12b3aec

Browse files
committed
Fix pipe sudo issue
1 parent e1f5b2a commit 12b3aec

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

docs/install.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ For more examples, see [examples](https://github.com/chdb-io/chdb/tree/main/exam
355355
📦 Install [libchdb](https://github.com/chdb-io/chdb) on your amd64/arm64 system before proceeding
356356

357357
```bash
358-
curl -sL https://lib.chdb.io | sudo bash
358+
curl -sL https://lib.chdb.io | bash
359359
```
360360

361361
<!-- tabs:end -->
@@ -408,7 +408,7 @@ session.cleanup();
408408
📦 Install [libchdb](https://github.com/chdb-io/chdb/releases/latest) on your amd64/arm64 system before proceeding
409409

410410
```bash
411-
curl -sL https://lib.chdb.io | sudo bash
411+
curl -sL https://lib.chdb.io | bash
412412
```
413413

414414
<!-- tabs:end -->
@@ -431,7 +431,7 @@ Install and Examples, see: [chdb-go](https://github.com/chdb-io/chdb-go)
431431
📦 Install [libchdb](https://github.com/chdb-io/chdb/releases/latest) on your amd64/arm64 system before proceeding
432432

433433
```bash
434-
curl -sL https://lib.chdb.io | sudo bash
434+
curl -sL https://lib.chdb.io | bash
435435
```
436436

437437
<!-- tabs:end -->
@@ -448,7 +448,7 @@ This binding is a work in progress. Follow the instructions at [chdb-rust](https
448448
📦 Install [libchdb](https://github.com/chdb-io/chdb/releases/latest) on your amd64/arm64 system before proceeding
449449

450450
```bash
451-
curl -sL https://lib.chdb.io | sudo bash
451+
curl -sL https://lib.chdb.io | bash
452452
```
453453

454454
<!-- tabs:end -->
@@ -496,7 +496,7 @@ sess.cleanup(); // cleanup session, this will delete the database
496496
📦 Install [libchdb](https://github.com/chdb-io/chdb/releases/latest) on your amd64/arm64 system before proceeding
497497

498498
```bash
499-
curl -sL https://lib.chdb.io | sudo bash
499+
curl -sL https://lib.chdb.io | bash
500500
```
501501

502502
<!-- tabs:end -->

install_libchdb.sh

+14-5
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,31 @@ curl -L -o libchdb.tar.gz $DOWNLOAD_URL
4343
# Untar the file
4444
tar -xzf libchdb.tar.gz
4545

46-
# Check if console supports colors, if that define REDECHO and ENDECHO
46+
# If current uid is not 0, check if sudo is available and request the user to input the password
47+
if [[ $EUID -ne 0 ]]; then
48+
command -v sudo >/dev/null 2>&1 || { echo >&2 "This script requires sudo privileges but sudo is not installed. Aborting."; exit 1; }
49+
echo "Installation requires administrative access. You will be prompted for your password."
50+
fi
51+
52+
# Define color messages if terminal supports them
4753
if [[ -t 1 ]]; then
4854
RED='\033[0;31m'
49-
NC='\033[0m'
55+
GREEN='\033[0;32m'
56+
NC='\033[0m' # No Color
5057
REDECHO() { echo -e "${RED}$@${NC}"; }
58+
GREENECHO() { echo -e "${GREEN}$@${NC}"; }
5159
ENDECHO() { echo -ne "${NC}"; }
5260
else
5361
REDECHO() { echo "$@"; }
62+
GREENECHO() { echo "$@"; }
5463
ENDECHO() { :; }
5564
fi
5665

57-
# If current uid is 0, SUDO is not required
66+
# Use sudo if not running as root
5867
SUDO=''
5968
if [[ $EUID -ne 0 ]]; then
6069
SUDO='sudo'
61-
REDECHO "\nYou may be asked for your sudo password to install:"; ENDECHO
70+
GREENECHO "\nYou will be asked for your sudo password to install:"
6271
echo " libchdb.so to /usr/local/lib/"
6372
echo " chdb.h to /usr/local/include/"
6473
fi
@@ -78,6 +87,6 @@ fi
7887
# Clean up
7988
rm -f libchdb.tar.gz libchdb.so chdb.h
8089

81-
REDECHO "Installation completed successfully." ; ENDECHO
90+
GREENECHO "Installation completed successfully." ; ENDECHO
8291
REDECHO "If any error occurred, please report it to:" ; ENDECHO
8392
REDECHO " https://github.com/chdb-io/chdb/issues/new/choose" ; ENDECHO

0 commit comments

Comments
 (0)