BINARY_NAME=env-guard-server SERVICE_NAME=env-guard.service INSTALL_DIR=/usr/local/bin SYSTEMD_DIR=/etc/systemd/system WORK_DIR=/var/lib/env-guard .PHONY: all build build-linux clean install uninstall all: build build: go build -o $(BINARY_NAME) ./cmd/server # Cross-compilation for Linux (useful if running this on Windows/Mac) build-linux: GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME) ./cmd/server clean: rm -f $(BINARY_NAME) install: build-linux @echo "Installing server..." mkdir -p $(INSTALL_DIR) cp $(BINARY_NAME) $(INSTALL_DIR)/ chmod +x $(INSTALL_DIR)/$(BINARY_NAME) @echo "Creating working directory..." mkdir -p $(WORK_DIR) # Copy initial data files if they exist locally and not on target, # otherwise app will create default/empty ones based on its logic. # if [ -f services.json ]; then cp -n services.json $(WORK_DIR)/; fi # if [ -f history.json ]; then cp -n history.json $(WORK_DIR)/; fi @echo "Installing systemd service..." cp $(SERVICE_NAME) $(SYSTEMD_DIR)/ systemctl daemon-reload systemctl enable $(SERVICE_NAME) systemctl start $(SERVICE_NAME) @echo "Service installed and started!" uninstall: @echo "Uninstalling..." systemctl stop $(SERVICE_NAME) || true systemctl disable $(SERVICE_NAME) || true rm -f $(SYSTEMD_DIR)/$(SERVICE_NAME) rm -f $(INSTALL_DIR)/$(BINARY_NAME) systemctl daemon-reload @echo "Uninstalled." update: @echo "Updating server..." systemctl stop $(SERVICE_NAME) cp $(BINARY_NAME) $(INSTALL_DIR)/ chmod +x $(INSTALL_DIR)/$(BINARY_NAME) systemctl start $(SERVICE_NAME) systemctl status $(SERVICE_NAME) @echo "Server updated!"