-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
89 lines (73 loc) · 2.24 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
#!/bin/bash
# Moonraker Octoprint Enhanced component installer
# Copyright (C) 2022 Grant Harding <[email protected]>
#
# Taken from https://github.com/mainsail-crew/moonraker-timelapse/
# Copyright (C) 2021 Christoph Frei <[email protected]>
# Copyright (C) 2021 Stephan Wendel aka KwadFan <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
#
# Note:
# this installer script is heavily inspired by
# https://github.com/protoloft/klipper_z_calibration/blob/master/install.sh
# Prevent running as root.
if [ ${UID} == 0 ]; then
echo -e "DO NOT RUN THIS SCRIPT AS 'root' !"
echo -e "If 'root' privileges needed, you will prompted for sudo password."
exit 1
fi
# Force script to exit if an error occurs
set -e
# Find SRCDIR from the pathname of this script
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/ && pwd )"
# Default Parameters
MOONRAKER_TARGET_DIR="${HOME}/moonraker/moonraker/components"
SYSTEMDDIR="/etc/systemd/system"
# Define text colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
function stop_moonraker {
if [ "$(sudo systemctl list-units --full --all -t service --no-legend | grep -F "moonraker.service")" ]; then
echo "Moonraker service found! Stopping during Install."
sudo systemctl stop moonraker
else
echo "Moonraker service not found, please install Moonraker first"
exit 1
fi
}
function link_extension {
if [ -d "${MOONRAKER_TARGET_DIR}" ]; then
echo "Linking extension to moonraker..."
ln -sf "${SRCDIR}/component/octoprint_enhanced.py" "${MOONRAKER_TARGET_DIR}/octoprint_enhanced.py"
else
echo -e "ERROR: ${MOONRAKER_TARGET_DIR} not found."
echo -e "Please Install moonraker first!\nExiting..."
exit 1
fi
}
function restart_services {
echo "Restarting Moonraker..."
sudo systemctl restart moonraker
}
### MAIN
# Parse command line arguments
while getopts "c:h" arg; do
if [ -n "${arg}" ]; then
case $arg in
[?]|h)
echo -e "\nUsage: ${0}"
exit 1
;;
esac
fi
break
done
# Run steps
stop_moonraker
link_extension
restart_services
# If something checks status of install
exit 0