-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall
More file actions
executable file
·310 lines (246 loc) · 9.33 KB
/
install
File metadata and controls
executable file
·310 lines (246 loc) · 9.33 KB
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
set -eE -o functrace
failure() {
local lineno=$1
local msg=$2
echo "Failed at $lineno: $msg"
}
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
ARCH=$(uname -m)
FRESH_INSTALL=0
if [ -d "/usr/local/etc/printspool/" ]; then
echo "Updating previous PrintSpool for $ARCH install..."
else
echo "Installing PrintSpool for $ARCH..."
FRESH_INSTALL=1
fi
# Install dependencies
sudo apt update
sudo apt-get install \
libgtk-3-0 \
libasound2 \
libbsd-dev \
postgresql \
postgresql-contrib \
rsync \
apg \
unzip \
jq \
`# Belt Engine & Cura Engine Dependencies` \
python3-pip \
libgeos-dev \
libblas-dev \
liblapack-dev \
gfortran \
libxslt1-dev \
libxml2-dev \
libjpeg-dev \
zlib1g-dev
# PS_USER="printspool"
# sudo useradd $PS_USER || true
# sudo usermod -a -G dialout $PS_USER || true
PS_USER="root"
PS_USER_HOME=$( getent passwd "$PS_USER" | cut -d: -f6 )
# create directories
sudo mkdir -vp /usr/local/etc/printspool/
sudo chmod 700 /usr/local/etc/printspool/
sudo mkdir -vp /usr/local/etc/printspool/common/
sudo chmod 700 /usr/local/etc/printspool/common/
sudo mkdir -vp /var/local/printspool/
sudo chmod 700 /var/local/printspool/
if [ ! -f /usr/local/etc/printspool/current/VERSION ]; then
PREVIOUS_VERSION="0.16.2"
else
PREVIOUS_VERSION=$(cat /usr/local/etc/printspool/current/VERSION)
fi
if [[ "$PREVIOUS_VERSION" == "0.16.2" ]]; then
sudo touch /usr/local/etc/printspool/common/.needs_0_16_2_pg_patch
fi
PREV_PRINTSPOOL_INDEX=`sudo find /usr/local/etc/printspool/ -maxdepth 1 \
-regex '/usr/local/etc/printspool/[0-9]+' \
-printf '%f\n' | sort -V | tail -1`
# PRINTSPOOL_INDEX defaults to 0 if PREV_PRINTSPOOL_INDEX is ""
PRINTSPOOL_INDEX=$(( $PREV_PRINTSPOOL_INDEX + 1 ))
if [[ $FRESH_INSTALL == "1" ]]; then
sudo touch /usr/local/etc/printspool/common/.is-fresh-install
fi
if [[ "${TEG_DEV}" == "1" ]]; then
sudo chown -R `whoami`:`whoami` /usr/local/etc/printspool/
sudo chown -R `whoami`:`whoami` /usr/local/etc/printspool/common/
sudo chown -R `whoami`:`whoami` /var/local/printspool/
./setup-postgres
else
sudo chown -R ${PS_USER}:${PS_USER} /usr/local/etc/printspool/
sudo chown -R ${PS_USER}:${PS_USER} /usr/local/etc/printspool/common/
sudo chown -R ${PS_USER}:${PS_USER} /var/local/printspool/
fi
# create a tmp dir
SCRIPT_DIR=$( dirname "${BASH_SOURCE[0]}" )
WORK_DIR=$(mktemp -d)
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
# deletes the temp directory
function cleanup {
rm -rf "$WORK_DIR"
echo "Deleted temp working directory $WORK_DIR"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
if [[ ! -z "${PRINTSPOOL_ZIP}" ]]; then
unzip "${PRINTSPOOL_ZIP}" -d $WORK_DIR/
fi
# Change to the tmp dir
cd $WORK_DIR
# Download the latest build artifact from the develop branch on Github
#
# WARNING:
#
# PRINTSPOOL_UNSTABLE_HEAD will install a dev build not intended for real world use. At the very
# least it will run 10x slower then the normal version of PrintSpool but it may also cause much
# more serious problems for you and your printer.
#
# **Never** use this option unless you are a developer and know exactly what you are doing.
if [[ "${PRINTSPOOL_UNSTABLE_HEAD}" == "1" ]]; then
if [[ -z "$GITHUB_USER" ]]; then
echo "GITHUB_USER environment variable is required for PRINTSPOOL_UNSTABLE_HEAD=1" 1>&2
exit 1
fi
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "GITHUB_TOKEN environment variable is required for PRINTSPOOL_UNSTABLE_HEAD=1" 1>&2
exit 1
fi
sudo apt-get install jq
ARTIFACTS_LIST_URL=$(curl \
-u "$GITHUB_USER:$GITHUB_TOKEN" \
-qH "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/PrintSpool/PrintSpool/actions/runs \
| jq -r '.workflow_runs | sort_by(.created_at |= fromdate) | map(select(.head_branch=="develop") | select(.fork==null) | select(.conclusion=="success")) | last.artifacts_url')
ARTIFACT_DOWNLOAD_URL=$(curl \
-u "$GITHUB_USER:$GITHUB_TOKEN" \
-qH "Accept: application/vnd.github.v3+json" \
${ARTIFACTS_LIST_URL} \
| jq -r '.artifacts[] | select(.name == "printspool-armv7l").archive_download_url')
echo "Downloading PrintSpool dev from $ARTIFACT_DOWNLOAD_URL"
PRINTSPOOL_ZIP=./printspool-armv7l.zip
curl \
-u "$GITHUB_USER:$GITHUB_TOKEN" \
-LH "Accept: application/vnd.github.v3+json" \
--output $PRINTSPOOL_ZIP\
$ARTIFACT_DOWNLOAD_URL
unzip "${PRINTSPOOL_ZIP}" -d $WORK_DIR/
rm $PRINTSPOOL_ZIP
fi
# Install from a zip
if [[ ! -z "${PRINTSPOOL_ZIP}" ]]; then
echo ""
echo "Installing PrintSpool from zip file"
echo ""
ls -la
# Install from a local artifact (meaning a local run of cargo build)
elif [[ "${LOCAL_ARTIFACT}" == "1" ]]; then
echo ""
echo "Installing PrintSpool from local artifact"
echo ""
if [[ "${CI}" == "true" ]]; then
echo "CI Detected: Copying pre-built binaries"
cp -r /files/printspool/* ./
ls -la
else
echo "Creating dev artifacts..."
TEG_ARCH=$ARCH $SCRIPT_DIR/ci/create-artifact
cp -r $SCRIPT_DIR/../artifact-working-dir/* ./
echo "Creating dev artifacts... [DONE]"
fi
# Standard install
else
# Download the latest release
echo ""
echo "Downloading the latest release of PrintSpool"
echo ""
# Use the provided github repo or default to "PrintSpool/PrintSpool"
PRINTSPOOL_GITHUB="${PRINTSPOOL_GITHUB:-PrintSpool/PrintSpool}"
ARTIFACT_NAME="printspool-$ARCH.zip"
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/$PRINTSPOOL_GITHUB/releases/latest)
# The releases are returned in the format {"id":3622206,"tag_name":"hello-1.0.0.11",...},
# we have to extract the tag_name.
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
ARTIFACT_URL="https://github.com/$PRINTSPOOL_GITHUB/releases/download/$LATEST_VERSION/$ARTIFACT_NAME"
wget $ARTIFACT_URL
unzip $ARTIFACT_NAME
rm $ARTIFACT_NAME
fi
# Download and install belt-engine
if [[ $EXPERIMENTAL_BELT_ENGINE == "1" ]]; then
wget https://github.com/Autodrop3d/BeltEngine/raw/main/dist/belt-engine-0.1.3.tar.gz
sudo pip3 install ./belt-engine-0.1.3.tar.gz
pushd .
cd ./etc
wget https://raw.githubusercontent.com/Autodrop3d/BeltEngine/main/belt_engine/settings/CR30.cfg.ini
popd
fi
# Download and install cura-engine
wget https://github.com/D1plo1d/BeltEngine/raw/main/dist/belt-engine-0.1.3.tar.gz
tar -xf belt-engine-0.1.3.tar.gz
rm belt-engine-0.1.3.tar.gz
if [[ "$ARCH" == "x86_64" ]]; then
mv belt-engine-0.1.3/belt_engine/bin/linux/ ./etc/cura-engine
else
mv belt-engine-0.1.3/belt_engine/bin/armLinux/ ./etc/cura-engine
fi
chmod 744 ./etc/cura-engine/CuraEngine
# Download the latest webrtc-streamer release
GITHUB_REPO="mpromonet/webrtc-streamer"
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/$GITHUB_REPO/releases/latest)
# The releases are returned in the format {"id":3622206,"tag_name":"hello-1.0.0.11",...},
# we have to extract the tag_name.
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
ARTIFACT_DIR="webrtc-streamer-$LATEST_VERSION-Linux-$ARCH-Release"
ARTIFACT_NAME="$ARTIFACT_DIR.tar.gz"
ARTIFACT_URL="https://github.com/$GITHUB_REPO/releases/download/$LATEST_VERSION/$ARTIFACT_NAME"
wget $ARTIFACT_URL
tar -xf $ARTIFACT_NAME
rm $ARTIFACT_NAME
mv $ARTIFACT_DIR ./etc/webrtc-streamer
echo "Installing PrintSpool binaries to /usr/local/etc/printspool/${PRINTSPOOL_INDEX}"
# Install etc (migrations, binaries, configs and webrtc-streamer)
sudo mv ./etc /usr/local/etc/printspool/${PRINTSPOOL_INDEX}
sudo chown -R $PS_USER:$PS_USER /usr/local/etc/printspool/${PRINTSPOOL_INDEX}
# Set permissions
sudo chmod 744 /usr/local/etc/printspool/${PRINTSPOOL_INDEX}/printspool-health-monitor
sudo chmod 744 /usr/local/etc/printspool/${PRINTSPOOL_INDEX}/printspool-server
sudo chmod 744 /usr/local/etc/printspool/${PRINTSPOOL_INDEX}/printspool-marlin
sudo chmod 744 /usr/local/etc/printspool/${PRINTSPOOL_INDEX}/printspool-invite
# Update the current directory symlink
sudo ln -vnsf "/usr/local/etc/printspool/${PRINTSPOOL_INDEX}/" /usr/local/etc/printspool/current
# Install binaries on path
sudo ln -vnsf "/usr/local/etc/printspool/current/printspool-invite" /usr/local/bin
sudo ln -vnsf "/usr/local/etc/printspool/current/cura-engine/CuraEngine" /usr/local/bin
# Install System D service files
echo "Installing PrintSpool services to /lib/systemd/system/"
sudo ls -la ./services/
sudo chmod 644 ./services/*
sudo rsync --chown=$PS_USER:$PS_USER -av ./services/ /lib/systemd/system/
if [[ "$CI" == "true" ]]; then
systemctl --machine=machine_name enable printspool-server printspool-health-monitor printspool-webrtc-streamer
# machinectl poweroff machine_name
else
sudo systemctl daemon-reload
sudo systemctl enable printspool-server printspool-health-monitor printspool-webrtc-streamer
sudo systemctl restart printspool-server printspool-health-monitor printspool-webrtc-streamer
# Clean up: delete the previous version
if [[ "$PRINTSPOOL_INDEX" != "0" ]]; then
sudo rm -rf /usr/local/etc/printspool/${PREV_PRINTSPOOL_INDEX}/
fi
# TODO: Instead of waiting for 1 second this should wait for the database to be migrated
echo ""
echo "Migrating database..."
sleep 1s
echo "PrintSpool Installed"
# Generate an invite key for the user
if [ $FRESH_INSTALL = "1" ]; then
sudo printspool-invite
fi
fi