-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
64 lines (54 loc) · 2.59 KB
/
Makefile
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
## Spyglass Installer
##
## Selfdocumenting Makefile
## Based on https://www.freecodecamp.org/news/self-documenting-makefile/
.PHONY: help install uninstall update
#### Install Paths
USER = $(shell whoami)
SYSTEMD = /etc/systemd/system
BIN_PATH = /usr/local/bin
PRINTER_DATA_PATH = /home/$(USER)/printer_data
CONF_PATH = $(PRINTER_DATA_PATH)/config
all:
$(MAKE) help
install: ## Install Spyglass as service
@mkdir -p $(CONF_PATH)
@printf "\nCopying systemd service file ...\n"
@sudo cp -f "${PWD}/resources/spyglass.service" $(SYSTEMD)
@sudo sed -i "s/%USER%/$(USER)/g" $(SYSTEMD)/spyglass.service
@printf "\nCopying Spyglass launch script ...\n"
@sudo ln -sf "${PWD}/scripts/spyglass" $(BIN_PATH)
@printf "\nCopying basic configuration file ...\n"
@cp -f "${PWD}/resources/spyglass.conf" $(CONF_PATH)
@printf "\nPopulate new service file ... \n"
@sudo systemctl daemon-reload
@sudo echo "spyglass" >> $(PRINTER_DATA_PATH)/moonraker.asvc
@printf "\nEnable Spyglass service ... \n"
@sudo systemctl enable spyglass
@printf "\nTo be sure, everything is setup please reboot ...\n"
@printf "Thanks for choosing Spyglass ...\n"
uninstall: ## Uninstall Spyglass
@printf "\nDisable Spyglass service ... \n"
@sudo systemctl disable spyglass
@printf "\nRemove systemd service file ...\n"
@sudo rm -f $(SYSTEMD)/spyglass.service
@printf "\nRemoving Spyglass launch script ...\n"
@sudo rm -f $(BIN_PATH)/spyglass
@sudo sed '/spyglass/d' $(PRINTER_DATA_PATH)/moonraker.asvc > $(PRINTER_DATA_PATH)/moonraker.asvc
update: ## Update Spyglass (via git Repository)
@git fetch && git pull
upgrade-moonraker: ## In case of old version of Spyglass being upgraded to newer version with Moonraker update manager compatibility
@printf "Upgrading systemctl ...\n"
@sudo cp -f "${PWD}/resources/spyglass.service" $(SYSTEMD)
@sudo sed -i "s/%USER%/$(USER)/g" $(SYSTEMD)/spyglass.service
@printf "Saving backup of moonraker.asvc file as %s ...\n" $(PRINTER_DATA_PATH)/moonraker.asvc.bak
@sudo cp -f $(PRINTER_DATA_PATH)/moonraker.asvc $(PRINTER_DATA_PATH)/moonraker.asvc.bak
@printf "Upgrading Moonraker update manager authorization ...\n"
@sudo sed -i '/spyglass/d' $(PRINTER_DATA_PATH)/moonraker.asvc
@sudo echo "spyglass" >> $(PRINTER_DATA_PATH)/moonraker.asvc
@printf "You can now include the configuration in moonraker.conf to manage Spyglass updates ...\n"
@printf "Upgrade completed ...\n"
@printf "Thanks for choosing Spyglass ...\n"
help: ## Show this help
@printf "\nSpyglass Install Helper:\n"
@grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'