Skip to content

Commit 0bc5afb

Browse files
make sudo installation optional and add new cases for different OS dist.
1 parent c0c90ac commit 0bc5afb

File tree

1 file changed

+109
-16
lines changed

1 file changed

+109
-16
lines changed

scripts/install.sh

Lines changed: 109 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,81 @@ check_sudo() {
4646
fi
4747
}
4848

49+
# Detect OS distribution from /etc/os-release
50+
detect_os_family() {
51+
if [ ! -f /etc/os-release ]; then
52+
log_error "/etc/os-release not found. Cannot determine OS distribution."
53+
return 1
54+
fi
55+
56+
# Source the os-release file to get variables
57+
. /etc/os-release
58+
59+
# Check ID_LIKE field for supported distributions
60+
case "${ID_LIKE:-}" in
61+
*"rhel"*|*"fedora"*)
62+
echo "rhel_fedora"
63+
;;
64+
*"debian"*)
65+
echo "debian"
66+
;;
67+
*)
68+
# Fallback to ID if ID_LIKE is not set or doesn't match
69+
case "${ID:-}" in
70+
"rhel"|"fedora"|"centos"|"rocky"|"almalinux")
71+
echo "rhel_fedora"
72+
;;
73+
"debian"|"ubuntu")
74+
echo "debian"
75+
;;
76+
*)
77+
echo "unknown"
78+
;;
79+
esac
80+
;;
81+
esac
82+
}
83+
4984
# Install required system packages
5085
install_system_packages() {
86+
local use_sudo=${1:-false}
87+
5188
log_info "Installing required system packages..."
52-
# Check for sudo access
53-
if sudo -n true 2>/dev/null; then
54-
# Detect OS and install packages accordingly
55-
if [ -f /etc/fedora-release ] || [ -f /etc/centos-release ]; then
56-
log_info "Detected Fedora OS"
57-
sudo dnf install -y libibverbs rdma-core libmlx5 libibverbs-devel rdma-core-devel
58-
elif [ -f /etc/lsb-release ] || [ -f /etc/ubuntu-release ]; then
59-
log_info "Detected Ubuntu OS"
60-
sudo apt-get update
61-
sudo apt-get install -y libibverbs1 rdma-core libmlx5-1 libibverbs-dev rdma-core-dev
89+
90+
if [ "$use_sudo" = "true" ]; then
91+
# User explicitly requested sudo installation
92+
if sudo -n true 2>/dev/null; then
93+
# Detect OS family using /etc/os-release
94+
local os_family
95+
os_family=$(detect_os_family)
96+
97+
case "$os_family" in
98+
"rhel_fedora")
99+
log_info "Detected RHEL/Fedora-based OS - using system package manager"
100+
sudo dnf install -y libibverbs rdma-core libmlx5 libibverbs-devel rdma-core-devel
101+
;;
102+
"debian")
103+
log_info "Detected Debian-based OS - using system package manager"
104+
sudo apt-get update
105+
sudo apt-get install -y libibverbs1 rdma-core libmlx5-1 libibverbs-dev rdma-core-dev
106+
;;
107+
"unknown")
108+
log_error "Unsupported OS for automatic system package installation"
109+
log_info "Supported distributions: RHEL/Fedora-based (rhel fedora) and Debian-based (debian)"
110+
exit 1
111+
;;
112+
esac
113+
log_info "System packages installed successfully via system package manager"
62114
else
63-
log_error "Unsupported OS for automatic system package installation"
115+
log_error "Sudo installation requested but no sudo access available"
116+
log_info "Either run with sudo privileges or remove the --use-sudo flag to use conda"
64117
exit 1
65118
fi
66-
log_info "System packages installed successfully"
67119
else
68-
log_warning "No sudo access detected. Attempting to install packages via conda."
120+
# Default to conda installation
121+
log_info "Installing system packages via conda (default method)"
69122
conda install -c conda-forge rdma-core libibverbs-cos7-x86_64 -y
70-
log_info "Conda package installation attempted. Please ensure the packages are installed correctly."
123+
log_info "Conda package installation completed. Packages installed in conda environment."
71124
fi
72125
}
73126

@@ -76,6 +129,8 @@ check_gh_install() {
76129
if ! command -v gh &> /dev/null; then
77130
log_warning "GitHub CLI (gh) not found. Installing via Conda..."
78131
conda install gh --channel conda-forge -y
132+
log_info "GitHub CLI (gh) installed successfully."
133+
log_info "Please run 'gh auth login' to authenticate with GitHub."
79134
else
80135
log_info "GitHub CLI (gh) already installed."
81136
fi
@@ -141,22 +196,60 @@ download_vllm_wheel() {
141196
}
142197

143198

199+
# Parse command line arguments
200+
parse_args() {
201+
USE_SUDO=false
202+
203+
while [[ $# -gt 0 ]]; do
204+
case $1 in
205+
--use-sudo)
206+
USE_SUDO=true
207+
shift
208+
;;
209+
-h|--help)
210+
echo "Usage: $0 [OPTIONS]"
211+
echo ""
212+
echo "Options:"
213+
echo " --use-sudo Use system package manager instead of conda for system packages"
214+
echo " -h, --help Show this help message"
215+
echo ""
216+
echo "By default, system packages are installed via conda for better isolation."
217+
echo "Use --use-sudo to install system packages via the system package manager."
218+
exit 0
219+
;;
220+
*)
221+
log_error "Unknown option: $1"
222+
log_info "Use --help for usage information"
223+
exit 1
224+
;;
225+
esac
226+
done
227+
}
228+
144229
main() {
230+
# Parse command line arguments first
231+
parse_args "$@"
232+
145233
echo "Forge User Installation"
146234
echo "======================"
147235
echo ""
148236
echo "Note: Run this from the root of the forge repository"
149237
echo "This script requires GitHub CLI (gh) to download large wheels"
238+
if [ "$USE_SUDO" = "true" ]; then
239+
echo "System packages will be installed via system package manager (requires sudo)"
240+
check_sudo
241+
else
242+
echo "System packages will be installed via conda (default, safer)"
243+
fi
150244
echo ""
151245

152246
check_conda_env
153-
check_sudo
154247
check_wheels
155248

156249
# Install openssl as we overwrite the default version when we update LD_LIBRARY_PATH
157250
conda install -y openssl
158251

159-
install_system_packages
252+
install_system_packages "$USE_SUDO"
160253
check_gh_install
161254
download_vllm_wheel
162255

0 commit comments

Comments
 (0)