This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
start.sh
254 lines (218 loc) · 9.65 KB
/
start.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
echo "---Checking for optional scripts---"
if [ -f /opt/scripts/user.sh ]; then
echo "---Found optional script, executing---"
chmod +x /opt/scripts/user.sh
/opt/scripts/user.sh
else
echo "---No optional script found, continuing---"
fi
export DATA_DIR=$HOME
uninstall_amd_driver() {
if [ -f /usr/bin/amdgpu-uninstall ]; then
echo "Uninstalling driver"
echo 'APT::Get::Assume-Yes "true";' >>/etc/apt/apt.conf.d/90assumeyes
/usr/bin/amdgpu-uninstall
rm /etc/apt/apt.conf.d/90assumeyes
echo "Done!"
else
echo "---AMD driver not present---"
fi
}
install_amd_driver() {
AMD_DRIVER=$1
AMD_DRIVER_URL=$2
FLAGS=$3
echo "---Installing AMD drivers, please wait!---"
echo "---Downloading driver from "$AMD_DRIVER_URL/$AMD_DRIVER"---"
echo 'APT::Get::Assume-Yes "true";' >>/etc/apt/apt.conf.d/90assumeyes
mkdir -p /tmp/opencl-driver-amd
cd /tmp/opencl-driver-amd
#echo AMD_DRIVER is $AMD_DRIVER
curl --referer $AMD_DRIVER_URL -O $AMD_DRIVER_URL/$AMD_DRIVER
tar -Jxf $AMD_DRIVER &>/dev/null
rm $AMD_DRIVER
cd amdgpu-pro-*
echo "---Installing driver, this can take a very long time with no output. Please wait!---"
apt-get install -y initramfs-tools &>/dev/null
./amdgpu-pro-install $FLAGS &>/dev/null
apt-get --fix-broken install -y &>/dev/null
cd /home/docker/
rm -rf /tmp/opencl-driver-amd
echo "---AMD Driver installation finished---"
INSTALLED_DRIVERV=$(cd /home/docker/phoenixminer && ./PhoenixMiner -list | grep -m 1 "OpenCL driver version" | sed 's/OpenCL driver version: //g' | cut -c1-5)
rm /etc/apt/apt.conf.d/90assumeyes
}
install_new_amd_driver() {
AMD_DRIVER=$1
AMD_DRIVER_URL=$2
echo "---Installing AMD drivers, please wait!---"
echo "---Downloading driver from "$AMD_DRIVER_URL/$AMD_DRIVER"---"
echo 'APT::Get::Assume-Yes "true";' >>/etc/apt/apt.conf.d/90assumeyes
mkdir -p /tmp/opencl-driver-amd
cd /tmp/opencl-driver-amd
#echo AMD_DRIVER is $AMD_DRIVER
curl --referer $AMD_DRIVER_URL -O $AMD_DRIVER_URL/$AMD_DRIVER
echo "---Installing driver, this can take a very long time with no output. Please wait!---"
apt-get update
apt-get install -y initramfs-tools &>/dev/null
apt-get install ./$AMD_DRIVER
apt-get --fix-broken install -y &>/dev/null
cd /home/docker/
rm -rf /tmp/opencl-driver-amd
echo "---AMD Driver installation finished---"
INSTALLED_DRIVERV=$(cd /home/docker/phoenixminer && ./PhoenixMiner -list | grep -m 1 "OpenCL driver version" | sed 's/OpenCL driver version: //g' | cut -c1-5)
rm /etc/apt/apt.conf.d/90assumeyes
}
INSTALLED_DRIVERV=$(cd /home/docker/phoenixminer && ./PhoenixMiner -list | grep -m 1 "OpenCL driver version" | sed 's/OpenCL driver version: //g' | cut -c1-5)
if [[ "${INSTALLED_DRIVERV}" != "${DRIVERV:-20.20}" ]]; then
case $DRIVERV in
0)
uninstall_amd_driver
echo "---Skipping AMD driver installation---"
;;
18.20)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-18.20-673703-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
18.30)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-18.30-641594.tar.xz" "https://drivers.amd.com/drivers/linux/ubuntu/18.04" "--opencl=legacy,pal --headless"
;;
18.40)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-18.40-697810-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
18.50)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-18.50-756341-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
19.10)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-19.10-785425-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
19.20)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-19.20-812932-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
19.30)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-19.30-934563-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
19.50)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-19.50-967956-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux/19.50" "--opencl=legacy,pal --headless"
;;
20.10)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.10-1048554-ubuntu-18.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
20.20)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.20-1098277-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
20.30)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.30-1109583-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
20.40)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.40-1147286-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
20.45)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.45-1188099-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,pal --headless"
;;
20.50)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-20.50-1234664-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=legacy,rocr --headless"
;;
21.10)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-21.10-1247438-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=rocr,legacy --headless"
;;
21.20)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-21.20-1271047-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=rocr,legacy --headless"
;;
21.30)
uninstall_amd_driver
install_amd_driver "amdgpu-pro-21.30-1290604-ubuntu-20.04.tar.xz" "https://drivers.amd.com/drivers/linux" "--opencl=rocr,legacy --headless"
;;
21.40.1)
uninstall_amd_driver
install_new_amd_driver "amdgpu-install_21.40.1.40501-1_all.deb" "https://repo.radeon.com/amdgpu-install/21.40.1/ubuntu/focal"
;;
esac
fi
if [ -f /usr/bin/nvidia-smi ]; then
echo "---Detected Nvidia card, installing driver, please wait!---"
if [ -z "${NV_DRV_V}" ]; then
echo "---Trying to get Nvidia driver version---"
export NV_DRV_V="$(nvidia-smi | grep NVIDIA-SMI | cut -d ' ' -f3)"
if [ -z "${NV_DRV_V}" ]; then
echo "---Something went wrong, can't get driver version, putting container into sleep mode---"
sleep infinity
else
echo "---Successfully got driver version: ${NV_DRV_V}---"
fi
fi
if [ ! -z "$INSTALL_V" ]; then
if [ "$INSTALL_V" != "${NV_DRV_V}" ]; then
echo "---Version missmatch, deleting local Nvidia Driver v$INSTALL_V---"
rm ${DATA_DIR}/NVIDIA_$INSTALL_V.run
fi
fi
INSTALL_V="$(find ${DATA_DIR} -name NVIDIA_*\.run | cut -d '_' -f 2 | cut -d '.' -f1- | sed 's/\.[^.]*$//')"
if [ ! -z "$INSTALL_V" ]; then
if [ "$INSTALL_V" != "${NV_DRV_V}" ]; then
echo "---Version missmatch, deleting local Nvidia Driver v$INSTALL_V---"
rm ${DATA_DIR}/NVIDIA_$INSTALL_V.run
fi
fi
if [ ! -f /usr/bin/nvidia-settings ]; then
if [ -f ${DATA_DIR}/NVIDIA_${NV_DRV_V}.run ]; then
echo "---Found NVIDIA Driver v${NV_DRV_V} locally, installing...---"
${DATA_DIR}/NVIDIA_${NV_DRV_V}.run ${NVIDIA_BUILD_OPTS} >/dev/null 2>&1
else
echo "---Downloading and installing Nvidia Driver v${NV_DRV_V}---"
wget -q --show-progress --progress=bar:force:noscroll -O /tmp/NVIDIA.run http://download.nvidia.com/XFree86/Linux-x86_64/${NV_DRV_V}/NVIDIA-Linux-x86_64-${NV_DRV_V}.run &&
chmod +x /tmp/NVIDIA.run &&
/tmp/NVIDIA.run ${NVIDIA_BUILD_OPTS} >/dev/null 2>&1 &&
mv /tmp/NVIDIA.run ${DATA_DIR}/NVIDIA_${NV_DRV_V}.run
fi
else
CUR_NV_DRV_V=$INSTALL_V
if [ "$NV_DRV_V" != "$CUR_NV_DRV_V" ]; then
echo "---Driver version missmatch, currently installed: v$CUR_NV_DRV_V, driver on Host: v$NV_DRV_V---"
if [ -f ${DATA_DIR}/NVIDIA_${NV_DRV_V}.run ]; then
echo "---Found NVIDIA Driver v${NV_DRV_V} locally, installing...---"
${DATA_DIR}/NVIDIA_${NV_DRV_V}.run ${NVIDIA_BUILD_OPTS} >/dev/null 2>&1
else
echo "---Downloading and installing Nvidia Driver v${NV_DRV_V}---"
wget -q --show-progress --progress=bar:force:noscroll -O /tmp/NVIDIA.run http://download.nvidia.com/XFree86/Linux-x86_64/${NV_DRV_V}/NVIDIA-Linux-x86_64-${NV_DRV_V}.run &&
chmod +x /tmp/NVIDIA.run &&
/tmp/NVIDIA.run ${NVIDIA_BUILD_OPTS} >/dev/null 2>&1 &&
mv /tmp/NVIDIA.run ${DATA_DIR}/NVIDIA_${NV_DRV_V}.run
fi
else
echo "---Nvidia Driver v$CUR_NV_DRV_V Up-To-Date---"
fi
fi
fi
term_handler() {
kill -SIGTERM "$killpid"
wait "$killpid" -f 2>/dev/null
exit 143
}
trap 'kill ${!}; term_handler' SIGTERM
if [ "${CUSTOM}" == "true" ]; then
/home/docker/custom-mine.sh &
else
/home/docker/mine.sh &
fi
killpid="$!"
while true; do
wait $killpid
exit 0
done