@@ -43,22 +43,31 @@ curl -L -o libchdb.tar.gz $DOWNLOAD_URL
43
43
# Untar the file
44
44
tar -xzf libchdb.tar.gz
45
45
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
47
53
if [[ -t 1 ]]; then
48
54
RED=' \033[0;31m'
49
- NC=' \033[0m'
55
+ GREEN=' \033[0;32m'
56
+ NC=' \033[0m' # No Color
50
57
REDECHO () { echo -e " ${RED} $@ ${NC} " ; }
58
+ GREENECHO () { echo -e " ${GREEN} $@ ${NC} " ; }
51
59
ENDECHO () { echo -ne " ${NC} " ; }
52
60
else
53
61
REDECHO () { echo " $@ " ; }
62
+ GREENECHO () { echo " $@ " ; }
54
63
ENDECHO () { : ; }
55
64
fi
56
65
57
- # If current uid is 0, SUDO is not required
66
+ # Use sudo if not running as root
58
67
SUDO=' '
59
68
if [[ $EUID -ne 0 ]]; then
60
69
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:"
62
71
echo " libchdb.so to /usr/local/lib/"
63
72
echo " chdb.h to /usr/local/include/"
64
73
fi
78
87
# Clean up
79
88
rm -f libchdb.tar.gz libchdb.so chdb.h
80
89
81
- REDECHO " Installation completed successfully." ; ENDECHO
90
+ GREENECHO " Installation completed successfully." ; ENDECHO
82
91
REDECHO " If any error occurred, please report it to:" ; ENDECHO
83
92
REDECHO " https://github.com/chdb-io/chdb/issues/new/choose" ; ENDECHO
0 commit comments