orbit/Makefile

79 lines
2.7 KiB
Makefile

ccyellow = $(shell echo "\033[33m")
ccend = $(shell tput op)
notice = $(ccyellow) $(0) $(ccend)
_path := $(shell pwd)
_user := gemini-data
ORBIT_HOSTNAME ?= localhost
SERVICE_PATH = /etc/systemd/system/orbit.service
EXEC_PATH = /usr/local/bin/orbit
CONF_PATH = /etc/orbit
LOG_PATH = /var/log/orbit
help:
@echo "Orbit Gemini protocol server"
@echo "To run tests, run 'make test'"
@echo "To install as a service on your system run:"
@echo " 'sudo make install ORBIT_HOSTNAME=localhost'"
@echo " But replace localhost with your desired hostname"
test:
cd tests; ../vendor/bin/phpunit .
install_bin:
@echo
@echo "$(ccyellow)> Installing orbit bin$(ccend)"
rm -f $(EXEC_PATH)
ln -s $(_path)/bin/orbit $(EXEC_PATH)
install_conf:
@echo
@echo "$(ccyellow)> Installing orbit config; Hostname: $(ORBIT_HOSTNAME)$(ccend)"
install -d $(CONF_PATH)
install config/localhost.ini $(CONF_PATH)/config.ini
sed -i -e 's#Example##' $(CONF_PATH)/config.ini
sed -i -e 's#localhost#$(ORBIT_HOSTNAME)#' $(CONF_PATH)/config.ini
sed -i -e 's#certs#$(CONF_PATH)/certs#' $(CONF_PATH)/config.ini
sed -i -e 's#log/#$(LOG_PATH)/#' $(CONF_PATH)/config.ini
install -o $(_user) -d $(LOG_PATH)
install_cert:
ifeq (,$(wildcard $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).cert.pem))
@echo
@echo "$(ccyellow)> Generating certs for host $(ORBIT_HOSTNAME)$(ccend)"
bin/makecert $(ORBIT_HOSTNAME)
install -d $(CONF_PATH)/certs
install certs/$(ORBIT_HOSTNAME).cert.pem $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).cert.pem
install certs/$(ORBIT_HOSTNAME).key.pem $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).key.pem
rm -rf certs
endif
install_user:
ifeq ($(shell id -u $(_user) 2>/dev/null),)
@echo
@echo "$(ccyellow)> Creating user $(_user)$(ccend)"
useradd -m -d /var/gemini -s /usr/sbin/nologin -c "Orbit gemini service account" -U $(_user)
endif
install_service:
@echo
@echo "$(ccyellow)> Creating orbit.service file at $(SERVICE_PATH)$(ccend)"
install orbit.service $(SERVICE_PATH)
sed -i -e 's/{USER}/$(_user)/' $(SERVICE_PATH)
install: install_bin install_user install_conf install_cert install_service
@echo
@echo "--------------------------------"
@echo "done"
@echo "> The service runs with the user $(_user)"
@echo "> The actual orbit script is at $(EXEC_PATH)"
@echo " - But that is just a symlink to $(_path)/bin/orbit"
@echo "> I created a config file at $(CONF_PATH)/config.ini"
@echo " - Edit settings in that file to change configuration settings"
@echo "> I created a self-signed cert at $(CONF_PATH)/certs"
@echo "> The server log will be written at $(LOG_PATH)/orbit.log"
@echo "Run 'sudo systemctl start orbit' to start the service"
@echo "Run 'sudo systemctl restart orbit' to restart the service"
@echo "Run 'sudo systemctl enable orbit' to configure orbit to auto-start when machine starts"