forked from mikew-heavyai/heavyai-devstack
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheckEnv.sh
executable file
·125 lines (108 loc) · 3.43 KB
/
checkEnv.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
#!/bin/bash
# Define colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
os_packages=("docker-compose" "awscli" "xmlstarlet")
docker_packages=("docker.io" "docker-ce")
missing_packages=()
UPDATE_DONE=0
echo -e "${BLUE}Checking for required packages...${NC}"
# Function to check if any of the docker packages are installed
check_docker_installed() {
for package in "${docker_packages[@]}"; do
if dpkg -l | grep -q "^ii\s\+$package\s"; then
echo -e "Docker Package ($package): [${GREEN}Installed${NC}]"
return 0
fi
done
echo -e "Docker Package: [${RED}Not Installed${NC}]"
return 1
}
# Check for docker packages
if check_docker_installed; then
echo -e "Docker: [${GREEN}Installed${NC}]"
else
echo -e "Docker: [${RED}Not Installed${NC}]"
missing_packages+=("docker.io") # Default to docker.io if neither is installed
fi
# Check for other required packages
for package in "${os_packages[@]}"; do
if dpkg -l | grep -q "^ii\s\+$package\s"; then
echo -e "$package: [${GREEN}Installed${NC}]"
else
echo -e "$package: [${RED}Not Installed${NC}]"
missing_packages+=("$package")
fi
done
installPackage(){
PACKAGE_NAME=$1
echo "Would you like to install $PACKAGE_NAME [y/n]"
read answer
case $answer in
[Yy]* )
echo "Installing $PACKAGE_NAME";
if [ $UPDATE_DONE -eq 0 ]; then
echo "Updating APT repository"
sudo apt-get update
UPDATE_DONE=1
fi
sudo apt-get install -y $PACKAGE_NAME
;;
[Nn]* )
echo "Skipping $PACKAGE_NAME"
;;
* )
echo "Invalid choice."
;;
esac
}
for package in "${missing_packages[@]}"; do
installPackage $package
done
# Configuring Docker
USER_NAME=$(whoami)
group_exists() {
getent group docker > /dev/null 2>&1
}
if ! group_exists; then
echo "The docker group does not exist. Creating docker group..."
sudo groupadd docker
if [ $? -eq 0 ]; then
echo -e "Docker Group: [${GREEN}Installed${NC}]"
else
echo -e "Docker Group: [${RED}Failed${NC}]"
exit 1
fi
else
echo -e "Docker Group: [${GREEN}Installed${NC}]"
fi
if groups $USER_NAME | grep -qw docker; then
echo -e "$USER_NAME: [${GREEN}Installed${NC}]"
else
echo "$USER_NAME is not in the docker group. Adding $USER_NAME to the docker group..."
sudo usermod -aG docker $USER_NAME
if [ $? -eq 0 ]; then
echo -e "$USER_NAME: [${GREEN}Installed${NC}]"
else
echo -e "$USER_NAME: [${RED}Failed${NC}]"
fi
fi
echo -e "${BLUE}Checking NVIDIA GPU ...${NC}"
if command -v nvidia-smi &> /dev/null; then
echo -e "Nvidia Driver: [${GREEN}Installed${NC}]"
# nvidia-smi
else
echo -e "Nvidia Driver: [${RED}Failed${NC}]"
echo -e "Run nvidiaDriver1.sh to install Nvidia drivers"
echo -e "IMPORTANT: It is generally required to reboot the server after the Nvidia driver install and before installing the Nvidia Docker runtime."
fi
echo -e "${BLUE}Checking NVIDIA Docker configuration...${NC}"
if command -v nvidia-container-runtime &> /dev/null; then
echo -e "Nvidia Docker: [${GREEN}Installed${NC}]"
# nvidia-container-runtime --version:q
else
echo -e "Nvidia Docker: [${RED}Failed${NC}]"
echo -e "Run nvidiaRuntime2.sh to install Nvidia Docker"
fi