-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoctoprint_install.sh
160 lines (140 loc) · 3.83 KB
/
octoprint_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
#!/bin/bash
set -e
export HOMEDIR="/home/octo"
export DISTRIBUTOR="$(/usr/bin/lsb_release -is)"
function echo_yellow {
TEXT="${@}"
echo -e "\e[33m${TEXT}\e[0m"
}
function echo_green {
TEXT="${@}"
echo -e "\e[32m${TEXT}\e[0m"
}
function echo_red {
TEXT="${@}"
echo -e "\e[31m${TEXT}\e[0m"
}
if [ "$EUID" -ne 0 ]; then
echo_red "# Please run as root"
exit 1
fi
case $DISTRIBUTOR in
Debian|Ubuntu)
echo_green "# Detected distributior: ${DISTRIBUTOR}"
;;
*)
echo_red "# Unsupported distributor: ${DISTRIBUTOR}"
exit 2
;;
esac
function setup_venv {
set -e
mkdir ${HOMEDIR}/OctoPrint
cd ${HOMEDIR}/OctoPrint
virtualenv -p /usr/bin/python3 --quiet venv
source venv/bin/activate
pip install pip --upgrade
pip install octoprint
}
export -f setup_venv
if [ -d "${HOMEDIR}" ]; then
read -p "User octo already exist, delete user and continue? (Y/n)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo_yellow "# Delete user octo and $HOMEDIR folder"
userdel -r octo
else
echo_red "User octo already exist. Installation stoped"
exit
fi
fi
echo_yellow "# Create octo user"
useradd -m -s /bin/bash -G tty,dialout,video octo
echo_yellow "# Please password for octo user"
passwd octo
echo_yellow "# Install package dependencies"
apt-get update
# Python dependencies
case $DISTRIBUTOR in
Ubuntu|Debian)
apt-get -y install \
build-essential \
curl \
git \
libyaml-dev \
libffi-dev \
python3-dev \
python3-pip \
python3-setuptools \
python3-virtualenv \
zlib1g-dev \
virtualenv
;;
esac
# ffmpeg && mjpg-streamer build dependencies
case $DISTRIBUTOR in
Debian)
apt-get -y install \
cmake \
ffmpeg \
git \
imagemagick \
libjpeg62-turbo-dev \
libv4l-dev \
sudo
;;
Ubuntu)
apt-get -y install \
cmake \
ffmpeg \
git \
imagemagick \
libjpeg8-dev \
libv4l-dev \
sudo
;;
esac
echo_yellow "# Configure OctoPrint VirtualEnv"
su octo -c "setup_venv"
echo_yellow "# Configure OctoPrint autostart"
curl -fsvL \
-o /etc/systemd/system/octoprint.service \
https://raw.githubusercontent.com/Etherlord/octoprint_installer/master/octoprint.service
curl -fsvL \
-o /etc/default/octoprint \
https://raw.githubusercontent.com/Etherlord/octoprint_installer/master/octoprint.default
echo_yellow "# Build mjpg-streamer"
git clone https://github.com/jacksonliam/mjpg-streamer.git /home/octo/mjpg-streamer
cd /home/octo/mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
make
cp -v /home/octo/mjpg-streamer/mjpg-streamer-experimental/_build/mjpg_streamer /usr/local/bin/mjpg_streamer
echo_yellow "# Configure scripts"
echo "octo ALL=NOPASSWD: /sbin/shutdown,/bin/systemctl restart octoprint.service" >> /etc/sudoers
curl -fsvL \
-o /etc/systemd/system/webcam.service \
https://raw.githubusercontent.com/Etherlord/octoprint_installer/master/webcam.service
curl -fsvL \
-o /usr/local/bin/webcamDaemon\
https://raw.githubusercontent.com/Etherlord/octoprint_installer/master/webcamDaemon
chmod +x /usr/local/bin/webcamDaemon
systemctl daemon-reload
for SERVICE in $(echo octoprint webcam); do
set +e
systemctl enable ${SERVICE}.service
systemctl start ${SERVICE}.service
sleep 10
systemctl is-active --quiet ${SERVICE}.service
if [ $? -ne 0 ]; then
echo_red "# Service ${SERVICE} not running! Check it:"
echo_red "# Run for logs: journalctl --no-pager -b -u ${SERVICE}.service"
else
echo_green "# Service ${SERVICE} OK."
fi
done
echo_green "# All done! Try to open web interface with this link:"
for IP in $(hostname --all-ip-addresses | grep -v '127.0.0.1'); do
echo_green "# Listen http://${IP}:5000"
echo_green "# Webcam stream http://${IP}:8080/?action=stream"
done