-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
206 lines (177 loc) · 7.6 KB
/
install.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
#!/bin/bash
# Installer for OpenBlok, for more information see https://github.com/blokbot-io/OpenBlok/blob/master/docs/installer.md
# ---------------------------------------------------------------------------- #
# Help #
# ---------------------------------------------------------------------------- #
Help()
{
# Display Help
echo "OpenBlok installation script."
echo
echo "h Display this help"
echo "u Set custom URL for OpenBlok"
echo "d Enable debug mode"
}
# ---------------------------------------------------------------------------- #
# Defaults #
# ---------------------------------------------------------------------------- #
URL="blokbot.io"
DEBUG=false
# -------------------------------- Verify Root ------------------------------- #
if [ "$EUID" -ne 0 ]
then echo "Please run as root with sudo."
exit
fi
# -------------------------------- Verify User ------------------------------- #
if ! id blok &>/dev/null; then
sudo adduser --disabled-password --gecos "" blok
sudo usermod -aG sudo blok
fi
# ---------------------------------------------------------------------------- #
# Dependencies #
# ---------------------------------------------------------------------------- #
# -------------------------------- Python 3.11 ------------------------------- #
pytohn_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))')
if [ "$pytohn_version" != "3.10" ]; then
sudo apt install software-properties-common -y
yes '' | sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get install python3.10 -y
else
echo "Python 3.10 already installed"
fi
# ----------------------------------- unzip ---------------------------------- #
REQUIRED_PKG="unzip"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install unzip -y
else
echo "unzip already installed, skipping..."
fi
# ------------------------------------ jq ------------------------------------ #
REQUIRED_PKG="jq"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install jq -y
else
echo "jq already installed, skipping..."
fi
# --------------------------------- v4l-utils -------------------------------- #
REQUIRED_PKG="v4l-utils"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install v4l-utils -y
else
echo "v4l-utils already installed, skipping..."
fi
# ---------------------------------- ffmpeg ---------------------------------- #
REQUIRED_PKG="ffmpeg"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install ffmpeg -y
else
echo "ffmpeg already installed, skipping..."
fi
# ---------------------------------- libsm6 ---------------------------------- #
REQUIRED_PKG="libsm6"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install libsm6 -y
else
echo "libsm6 already installed, skipping..."
fi
# --------------------------------- libxext6 --------------------------------- #
REQUIRED_PKG="libxext6"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install libxext6 -y
else
echo "libxext6 already installed, skipping..."
fi
# ----------------------------------- Redis ---------------------------------- #
REQUIRED_PKG="redis"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install redis -y
else
echo "redis already installed, skipping..."
fi
# ---------------------------------------------------------------------------- #
# Grab Latest OpenBlok Release #
# ---------------------------------------------------------------------------- #
cd /opt/
VERSION=$(wget -q -O- https://api.github.com/repos/blokbot-io/OpenBlok/releases/latest | jq -r '.name')
wget https://github.com/blokbot-io/OpenBlok/archive/refs/tags/${VERSION}.zip
unzip -qq ${VERSION}.zip -d /opt/OpenBlok
mv /opt/OpenBlok/OpenBlok-${VERSION}/* /opt/OpenBlok/
# ---------------------------------------------------------------------------- #
# Environment #
# ---------------------------------------------------------------------------- #
# ----------------------------- Setup Enviroment ----------------------------- #
REQUIRED_PKG="python3.10-venv"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
sudo apt-get install python3.10-venv -y
else
echo "python3.10 -venv already installed, skipping..."
fi
if [ ! -d "/opt/OpenBlok/env" ]; then
python3.10 -m venv /opt/OpenBlok/env
fi
. /opt/OpenBlok/env/bin/activate
# ------------------------ Install Python Dependencies ----------------------- #
cd /opt/OpenBlok/
pip install --no-input -U --upgrade-strategy only-if-needed -r /opt/OpenBlok/requirements.txt
# ---------------------------------------------------------------------------- #
# System Files #
# ---------------------------------------------------------------------------- #
# -------------------------------- system.json ------------------------------- #
if ! [ -f "/opt/OpenBlok/system.json" ]; then
sudo touch /opt/OpenBlok/system.json
serial_uuid=$(cat /proc/sys/kernel/random/uuid)
echo '{
"serial": "'$serial_uuid'",
"timezone": "UTC",
"url": "'$URL'",
"version": "'$VERSION'",
"debug": '$DEBUG',
"models": {
"location": {
"version": null
},
"e2e": {
"version": null
}
},
"storage": {
"local": {
"path": "/opt/OpenBlok/images",
"maxSizeGB": 10,
"enabled": true
},
"redis": {
"host": "localhost",
"port": 6379,
"password": null
}
}
}' > /opt/OpenBlok/system.json
fi
# ---------------------------------------------------------------------------- #
# Housekeeping #
# ---------------------------------------------------------------------------- #
# -------------------------------- Remove ZIPs ------------------------------- #
rm -rf /opt/${VERSION}.zip
rm -rf /opt/OpenBlok/OpenBlok-${VERSION}
# --------------------------------- Permissions ------------------------------- #
chmod a+w /opt/OpenBlok/system.json
chmod a+w /opt/OpenBlok/modeled/models
# ---------------------------------------------------------------------------- #
echo "OpenBlok installed successfully"