-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbuild.sh
executable file
·184 lines (156 loc) · 5.61 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
REBOOT_FLAG=".reboot_flag"
BUILD_SCRIPT_VERSION="v0.2.0"
install_docker() {
if ! command -v docker &>/dev/null; then
echo "Installing Docker..."
# Uninstall conflicting packages
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Add docker's official GPG key
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Setup repository
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |
tee /etc/apt/sources.list.d/docker.list >/dev/null
apt-get update
# Install necessary package
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Enable the service
systemctl --now enable docker
# Enable unattended-update
cat <<EOT | tee /etc/apt/apt.conf.d/51unattended-upgrades-docker
Unattended-Upgrade::Origins-Pattern {
"origin=Docker";
};
EOT
else
echo "Docker is already installed."
fi
}
install_nvidia_driver() {
if ! command -v nvidia-smi &>/dev/null; then
echo "Installing NVIDIA driver..."
apt-get update
apt-get upgrade -y
apt-get install -y ubuntu-drivers-common
# Remove previous NVIDIA installation
apt-get autoremove nvidia* --purge -y
apt-get autoclean
# Install Ubuntu and NVIDIA drivers
local version=$(ubuntu-drivers devices 2>/dev/null | grep recommended | grep -oP 'nvidia-driver-\d+')
ubuntu-drivers autoinstall
apt-get install -y $version
# Reboot
touch "$REBOOT_FLAG"
echo "==================================================================================="
echo "The system will reboot in 30 seconds. Rerun this script after the reboot completes."
echo "==================================================================================="
sleep 30
reboot
else
echo "NVIDIA driver is already installed."
fi
}
install_cuda_toolkit() {
if ! command -v nvcc --version &>/dev/null; then
echo "Installing CUDA toolkit..."
apt-get update
apt-get upgrade -y
# Install CUDA toolkit
apt-get install -y nvidia-cuda-toolkit
else
echo "CUDA toolkit is already installed."
fi
}
install_nvidia_container_toolkit() {
if ! command -v nvidia-ctk &>/dev/null; then
echo "Installing NVIDIA continaer toolkit"
# Setup GPG key
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
# Setup the repository
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt-get update
apt-get install -y nvidia-container-toolkit
# Configure the NVIDIA runtime to be the default docker runtime
nvidia-ctk runtime configure --runtime=docker --set-as-default
systemctl restart docker
else
echo "NVIDIA container toolkit is already installed."
fi
}
install_kuwa() {
# Download Kuwa repository if not exist
cd "$(pwd)"
if ! git rev-parse &>/dev/null; then
git clone https://github.com/kuwaai/genai-os/
pushd genai-os/docker > /dev/null
else
pushd "$(dirname "$0")" > /dev/null
fi
# Change configuration files
cp .admin-password.sample .admin-password
cp .db-password.sample .db-password
cp .env.sample .env
cp run.sh.sample run.sh
# Set admin password
while true; do
read -sp "Enter Kuwa admin password: " admin_passwd
echo
read -sp "Confirm Kuwa admin password: " admin_passwd_confirm
echo
if [ "$admin_passwd" == "$admin_passwd_confirm" ]; then
echo "Admin password set successfully."
echo "$admin_passwd" >.admin-password
break
else
echo "Passwords do not match. Please enter your password again."
fi
done
# Set random database password
db_passwd=$(LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 13)
echo "$db_passwd" >.db-password
echo "Database password set successfully."
# [Optional] Build the docker image from source.
read -p "Would you like to build the Kuwa Docker image from its source code? [y/N]: " build_docker_image
if [[ "$build_docker_image" == "y" || "$build_docker_image" == "Y" ]]; then
./run.sh build
fi
popd > /dev/null
}
install_all() {
if [[ -f "$REBOOT_FLAG" ]]; then
echo "The system has been rebooted. Continuing installation."
rm -f "$REBOOT_FLAG"
elif ! command -v nvidia-smi &>/dev/null; then
read -p "Do you want to install NVIDIA GPU drivers? [y/N]: " install_gpu
if [[ "$install_gpu" == "y" || "$install_gpu" == "Y" ]]; then
install_nvidia_driver
fi
fi
install_docker
if command -v nvidia-smi &>/dev/null; then
# install_cuda_toolkit
install_nvidia_container_toolkit
fi
install_kuwa
if ! git rev-parse &>/dev/null; then
cd genai-os/docker
else
cd "$(dirname "$0")"
fi
./run.sh
}
echo "Kuwa building script ${BUILD_SCRIPT_VERSION}"
echo "This script automates the installation of Kuwa and its dependencies. It has been tested on Ubuntu 22.04 and 24.04."
echo "Linux distribution information:"
lsb_release -a
echo "Preparing installation..."
sleep 2
install_all