summaryrefslogtreecommitdiff
path: root/Makefile
blob: 42cdea63ab32229621f23c754aa13263627a8b46 (plain)
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
SHELL := /bin/sh

APP_DIR := /opt/blind-uploader
SYSTEMD_UNIT := /etc/systemd/system/blind-uploader.service
NGINX_CONFIG := /etc/nginx/conf.d/blind-uploader.conf
DOMAIN ?= upload.example.com

.PHONY: help check prerequisites install

help:
	@echo "Targets:"
	@echo "  make check                    Run the automated tests"
	@echo "  sudo make install DOMAIN=... Install and start the application"

check:
	python3 -m unittest discover -s tests -v

prerequisites:
	@test "$$(id -u)" -eq 0 || { echo "Run installation as root: sudo make install DOMAIN=upload.example.com" >&2; exit 1; }
	@for command in python3 install systemctl nginx sed; do \
		command -v "$$command" >/dev/null 2>&1 || { echo "Required command not found: $$command" >&2; exit 1; }; \
	done

install: prerequisites
	install -d -m 0755 $(APP_DIR) $(APP_DIR)/static
	install -m 0755 server.py $(APP_DIR)/server.py
	install -m 0644 README.md $(APP_DIR)/README.md
	install -m 0644 static/index.html static/styles.css static/app.js $(APP_DIR)/static/
	install -m 0644 deploy/blind-uploader.service $(SYSTEMD_UNIT)
	install -d -m 0755 $$(dirname $(NGINX_CONFIG))
	sed 's/upload\.example\.com/$(DOMAIN)/g' deploy/nginx-blind-uploader.conf > $(NGINX_CONFIG)
	chmod 0644 $(NGINX_CONFIG)
	nginx -t
	systemctl daemon-reload
	systemctl enable --now blind-uploader.service
	systemctl reload nginx
	@echo "Private Drop installed for http://$(DOMAIN)"
	@echo "Uploads will be stored privately under /var/lib/blind-uploader/uploads"