Skip to content

Commit 40a027a

Browse files
authored
BM-213: update setup script (github#46)
1 parent 4c9a5b1 commit 40a027a

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

scripts/boundless_service.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ start_services() {
161161
log_info "Starting Docker Compose services using environment file: $ENV_FILE"
162162

163163
# Start Docker Compose in foreground mode
164-
docker compose --env-file "$ENV_FILE" up --build -d
164+
docker compose --profile broker --env-file "$ENV_FILE" up --build -d
165165

166166
# After docker compose up exits normally (without interruption)
167167
log_success "Docker Compose services have been started."
@@ -172,7 +172,7 @@ stop_services() {
172172
log_info "Stopping Docker Compose services using environment file: $ENV_FILE"
173173

174174
# Stop and remove containers, networks, volumes, and images created by up
175-
if docker compose --env-file "$ENV_FILE" down; then
175+
if docker compose --profile broker --env-file "$ENV_FILE" down; then
176176
log_success "Docker Compose services have been stopped and removed."
177177
else
178178
log_error "Failed to stop Docker Compose services."

scripts/setup.sh

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ error() {
4444
printf "\e[31m[ERROR]\e[0m %s\n" "$1" >&2
4545
}
4646

47-
# Function to check if the script is run as root
48-
check_root() {
49-
if [[ "$EUID" -ne 0 ]]; then
50-
error "This script must be run with sudo or as root."
51-
exit 1
52-
fi
47+
is_package_installed() {
48+
dpkg -s "$1" &> /dev/null
5349
}
5450

51+
5552
# Function to check if the operating system is Ubuntu
5653
check_os() {
5754
if [[ -f /etc/os-release ]]; then
@@ -77,8 +74,8 @@ check_os() {
7774
update_system() {
7875
info "Updating and upgrading the system packages..."
7976
{
80-
apt update -y
81-
apt upgrade -y
77+
sudo apt update -y
78+
sudo apt upgrade -y
8279
} >> "$LOG_FILE" 2>&1
8380
success "System packages updated and upgraded successfully."
8481
}
@@ -99,7 +96,7 @@ install_packages() {
9996

10097
info "Installing essential packages: ${packages[*]}..."
10198
{
102-
apt install -y "${packages[@]}"
99+
sudo apt install -y "${packages[@]}"
103100
} >> "$LOG_FILE" 2>&1
104101
success "Essential packages installed successfully."
105102
}
@@ -108,7 +105,7 @@ install_packages() {
108105
install_gpu_drivers() {
109106
info "Detecting and installing appropriate GPU drivers..."
110107
{
111-
ubuntu-drivers install
108+
sudo ubuntu-drivers install
112109
} >> "$LOG_FILE" 2>&1
113110
success "GPU drivers installed successfully."
114111
}
@@ -136,7 +133,7 @@ install_rust() {
136133

137134
# Function to install CUDA Toolkit
138135
install_cuda() {
139-
if dpkg -l | grep -q "^ii cuda-toolkit"; then
136+
if is_package_installed "cuda-toolkit"; then
140137
info "CUDA Toolkit is already installed. Skipping CUDA installation."
141138
else
142139
info "Installing CUDA Toolkit and dependencies..."
@@ -145,10 +142,10 @@ install_cuda() {
145142
distribution=$(grep '^ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')$(grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"'| tr -d '\.')
146143
info "Installing Nvidia CUDA keyring and repo"
147144
wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/$(/usr/bin/uname -m)/cuda-keyring_1.1-1_all.deb
148-
dpkg -i cuda-keyring_1.1-1_all.deb
145+
sudo dpkg -i cuda-keyring_1.1-1_all.deb
149146
rm cuda-keyring_1.1-1_all.deb
150-
apt-get update
151-
apt-get install -y cuda-toolkit
147+
sudo apt-get update
148+
sudo apt-get install -y cuda-toolkit
152149
} >> "$LOG_FILE" 2>&1
153150
success "CUDA Toolkit installed successfully."
154151
fi
@@ -162,25 +159,25 @@ install_docker() {
162159
info "Installing Docker..."
163160
{
164161
# Install prerequisites
165-
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
162+
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
166163

167164
# Add Docker’s official GPG key
168-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
165+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
169166

170167
# Set up the stable repository
171-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
168+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
172169

173170
# Update package index
174-
apt update -y
171+
sudo apt update -y
175172

176173
# Install Docker Engine, CLI, and Containerd
177-
apt install -y docker-ce docker-ce-cli containerd.io
174+
sudo apt install -y docker-ce docker-ce-cli containerd.io
178175

179176
# Enable Docker
180-
systemctl enable docker
177+
sudo systemctl enable docker
181178

182179
# Start Docker Service
183-
systemctl start docker
180+
sudo systemctl start docker
184181

185182
} >> "$LOG_FILE" 2>&1
186183
success "Docker installed and started successfully."
@@ -197,7 +194,7 @@ add_user_to_docker_group() {
197194
else
198195
info "Adding user '$username' to the 'docker' group..."
199196
{
200-
usermod -aG docker "$username"
197+
sudo usermod -aG docker "$username"
201198
} >> "$LOG_FILE" 2>&1
202199
success "User '$username' added to the 'docker' group."
203200
info "To apply the new group membership, please log out and log back in."
@@ -206,23 +203,30 @@ add_user_to_docker_group() {
206203

207204
# Function to install NVIDIA Container Toolkit
208205
install_nvidia_container_toolkit() {
206+
info "Checking NVIDIA Container Toolkit installation..."
207+
208+
if is_package_installed "nvidia-docker2"; then
209+
success "NVIDIA Container Toolkit (nvidia-docker2) is already installed."
210+
return
211+
fi
212+
209213
info "Installing NVIDIA Container Toolkit..."
210214

211215
{
212216
# Add the package repositories
213217
local distribution
214218
distribution=$(grep '^ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')$(grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')
215-
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
216-
curl -s -L https://nvidia.github.io/nvidia-docker/"$distribution"/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
219+
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
220+
curl -s -L https://nvidia.github.io/nvidia-docker/"$distribution"/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
217221

218222
# Update the package lists
219-
apt update -y
223+
sudo apt update -y
220224

221225
# Install the NVIDIA Docker support
222-
apt install -y nvidia-docker2
226+
sudo apt install -y nvidia-docker2
223227

224228
# Restart Docker to apply changes
225-
systemctl restart docker
229+
sudo systemctl restart docker
226230
} >> "$LOG_FILE" 2>&1
227231

228232
success "NVIDIA Container Toolkit installed successfully."
@@ -234,10 +238,10 @@ configure_docker_nvidia() {
234238

235239
{
236240
# Create Docker daemon configuration directory if it doesn't exist
237-
mkdir -p /etc/docker
241+
sudo mkdir -p /etc/docker
238242

239243
# Create or overwrite daemon.json with NVIDIA runtime configuration
240-
cat > /etc/docker/daemon.json <<EOF
244+
sudo tee /etc/docker/daemon.json <<EOF
241245
{
242246
"default-runtime": "nvidia",
243247
"runtimes": {
@@ -250,7 +254,7 @@ configure_docker_nvidia() {
250254
EOF
251255

252256
# Restart Docker to apply the new configuration
253-
systemctl restart docker
257+
sudo systemctl restart docker
254258
} >> "$LOG_FILE" 2>&1
255259

256260
success "Docker configured to use NVIDIA runtime by default."
@@ -272,12 +276,20 @@ verify_docker_nvidia() {
272276
cleanup() {
273277
info "Cleaning up unnecessary packages..."
274278
{
275-
apt autoremove -y
276-
apt autoclean -y
279+
sudo apt autoremove -y
280+
sudo apt autoclean -y
277281
} >> "$LOG_FILE" 2>&1
278282
success "Cleanup completed."
279283
}
280284

285+
init_git_submodules() {
286+
info "ensuring submodules are initialized..."
287+
{
288+
git submodule update --init --recursive
289+
} >> "$LOG_FILE" 2>&1
290+
success "git submodules initialized successfully"
291+
}
292+
281293
# =============================================================================
282294
# Main Script Execution
283295
# =============================================================================
@@ -288,12 +300,12 @@ exec > >(tee -a "$LOG_FILE") 2>&1
288300
# Display start message with timestamp
289301
info "===== Script Execution Started at $(date) ====="
290302

291-
# Check for root privileges
292-
check_root
293-
294303
# Check if the operating system is Ubuntu
295304
check_os
296305

306+
# ensure all the require source code is present
307+
init_git_submodules
308+
297309
# Update and upgrade the system
298310
update_system
299311

0 commit comments

Comments
 (0)