APP_NAME = ddns-updater BIN_DIR = bin VERSION = 1.0.0 # Go parameters GOCMD = go GOBUILD = $(GOCMD) build GOCLEAN = $(GOCMD) clean GORUN = $(GOCMD) run # Docker image (override: make build-dockerimg IMAGE=kccleoc/ddns-updater:latest) IMAGE ?= kccleoc/ddns-updater:latest # Build targets .PHONY: all build build-all clean run init-config install \ install-linux install-macos service-linux service-macos \ build-dockerimg push-dockerimg all: build # Build binary for current platform build: mkdir -p $(BIN_DIR) $(GOBUILD) -o $(BIN_DIR)/$(APP_NAME) -ldflags "-X main.Version=$(VERSION)" main.go @echo "Built $(BIN_DIR)/$(APP_NAME)" # Build for multiple platforms build-all: mkdir -p $(BIN_DIR) GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BIN_DIR)/$(APP_NAME)-linux-amd64 main.go GOOS=linux GOARCH=arm64 $(GOBUILD) -o $(BIN_DIR)/$(APP_NAME)-linux-arm64 main.go GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BIN_DIR)/$(APP_NAME)-darwin-amd64 main.go GOOS=darwin GOARCH=arm64 $(GOBUILD) -o $(BIN_DIR)/$(APP_NAME)-darwin-arm64 main.go @echo "Built all platform binaries in $(BIN_DIR)/" # Run locally run: $(GORUN) main.go -config config.yaml # Generate config template init-config: $(GORUN) main.go -init-config > config.yaml @echo "Generated config.yaml - edit with your Cloudflare credentials" # Clean build artifacts clean: $(GOCLEAN) rm -rf $(BIN_DIR) # Install binary system-wide install: build sudo install -m 755 $(BIN_DIR)/$(APP_NAME) /usr/local/bin/$(APP_NAME) @echo "Installed to /usr/local/bin/$(APP_NAME)" # Linux-specific installation install-linux: install sudo mkdir -p /etc/ddns-updater @if [ ! -f /etc/ddns-updater/config.yaml ]; then \ sudo cp config.yaml /etc/ddns-updater/config.yaml; \ sudo chmod 600 /etc/ddns-updater/config.yaml; \ echo "Config installed to /etc/ddns-updater/config.yaml"; \ else \ echo "Config already exists at /etc/ddns-updater/config.yaml"; \ fi # macOS-specific installation install-macos: install sudo mkdir -p /usr/local/etc sudo mkdir -p /usr/local/var/log @if [ ! -f /usr/local/etc/ddns-updater.yaml ]; then \ sudo cp config.yaml /usr/local/etc/ddns-updater.yaml; \ sudo chmod 600 /usr/local/etc/ddns-updater.yaml; \ echo "Config installed to /usr/local/etc/ddns-updater.yaml"; \ else \ echo "Config already exists at /usr/local/etc/ddns-updater.yaml"; \ fi # Set up systemd service (Linux) service-linux: @echo "Creating systemd service..." @echo "[Unit]\nDescription=DDNS Updater Service\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=simple\nExecStart=/usr/local/bin/$(APP_NAME) -config /etc/ddns-updater/config.yaml\nRestart=always\nRestartSec=10\nUser=root\nWorkingDirectory=/usr/local/bin\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /etc/systemd/system/ddns-updater.service >/dev/null @echo "\nSystemd service created. Run these commands:" @echo " sudo systemctl daemon-reload" @echo " sudo systemctl enable ddns-updater" @echo " sudo systemctl start ddns-updater" @echo " sudo systemctl status ddns-updater" # Set up launchd service (macOS) service-macos: @echo "Creating launchd plist..." @mkdir -p ~/Library/LaunchAgents @echo "\n\n\n\n Label\n com.ddns-updater\n ProgramArguments\n \n /usr/local/bin/$(APP_NAME)\n -config\n /usr/local/etc/ddns-updater.yaml\n \n RunAtLoad\n \n KeepAlive\n \n StandardOutPath\n /usr/local/var/log/ddns-updater.log\n StandardErrorPath\n /usr/local/var/log/ddns-updater.err\n\n" > ~/Library/LaunchAgents/com.ddns-updater.plist @echo "\nLaunchd plist created. Run these commands:" @echo " launchctl load ~/Library/LaunchAgents/com.ddns-updater.plist" @echo " launchctl start com.ddns-updater" @echo "\nView logs with:" @echo " tail -f /usr/local/var/log/ddns-updater.log" # Build Docker image (parameterized) # Usage: make build-dockerimg IMAGE=kccleoc/ddns-updater:latest build-dockerimg: docker build -t $(IMAGE) . # Push Docker image # Usage: make push-dockerimg IMAGE=kccleoc/ddns-updater:latest push-dockerimg: docker push $(IMAGE)