-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (112 loc) · 4.3 KB
/
Copy pathMakefile
File metadata and controls
133 lines (112 loc) · 4.3 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
PROJECT_NAME = https_proxy
VERSION = $(shell cat VERSION | tr -d '[:space:]')
INSTALL_DIR = /usr/bin
CONFIG_DIR = /etc/$(PROJECT_NAME)
CERT_DIR = $(CONFIG_DIR)/certs
SYSTEMD_DIR = /etc/systemd/system
SERVICE_USER = $(PROJECT_NAME)
SERVICE_GROUP = $(PROJECT_NAME)
DOCKER_IMAGE = hightemp/$(PROJECT_NAME)
.PHONY: build build-static run clean install install-user uninstall uninstall-full install-service uninstall-service start stop restart status enable disable release docker-build docker-push docker-release
build:
CGO_ENABLED=0 go build -o $(PROJECT_NAME) ./cmd/https_proxy
chmod +x $(PROJECT_NAME)
build-static:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o $(PROJECT_NAME)_static ./cmd/https_proxy
chmod +x $(PROJECT_NAME)_static
run:
./$(PROJECT_NAME)
clean:
rm -f $(PROJECT_NAME)
rm -f $(PROJECT_NAME)_static
install-user:
@if ! getent group $(SERVICE_GROUP) >/dev/null 2>&1; then \
groupadd --system $(SERVICE_GROUP); \
fi
@if ! id -u $(SERVICE_USER) >/dev/null 2>&1; then \
nologin_shell=$$(command -v nologin || printf '%s' /usr/sbin/nologin); \
useradd --system --gid $(SERVICE_GROUP) --no-create-home \
--home-dir /nonexistent --shell "$$nologin_shell" $(SERVICE_USER); \
fi
install: build install-user
@echo "Installing $(PROJECT_NAME)..."
install -d -o root -g $(SERVICE_GROUP) -m 750 $(CONFIG_DIR)
install -d -o root -g $(SERVICE_GROUP) -m 750 $(CERT_DIR)
install -m 755 $(PROJECT_NAME) $(INSTALL_DIR)/$(PROJECT_NAME)
@if [ ! -f $(CONFIG_DIR)/config.yaml ]; then \
install -o root -g $(SERVICE_GROUP) -m 640 config.example.yaml $(CONFIG_DIR)/config.yaml; \
echo "Config installed: $(CONFIG_DIR)/config.yaml"; \
else \
chown root:$(SERVICE_GROUP) $(CONFIG_DIR)/config.yaml; \
chmod 640 $(CONFIG_DIR)/config.yaml; \
echo "Config already exists, skipping: $(CONFIG_DIR)/config.yaml"; \
fi
install -m 644 packaging/$(PROJECT_NAME).service $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
systemctl enable $(PROJECT_NAME)
systemctl restart $(PROJECT_NAME)
@echo "Installation complete. Service $(PROJECT_NAME) is running and enabled on boot."
uninstall:
@echo "Removing $(PROJECT_NAME)..."
-systemctl stop $(PROJECT_NAME) 2>/dev/null || true
-systemctl disable $(PROJECT_NAME) 2>/dev/null || true
rm -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service
rm -f $(INSTALL_DIR)/$(PROJECT_NAME)
systemctl daemon-reload
@echo "Removal complete."
@echo "Configuration preserved in $(CONFIG_DIR)"
uninstall-full: uninstall
@echo "Removing configuration..."
rm -rf $(CONFIG_DIR)
@echo "Full removal complete."
install-service: install-user
install -d -o root -g $(SERVICE_GROUP) -m 750 $(CONFIG_DIR)
install -d -o root -g $(SERVICE_GROUP) -m 750 $(CERT_DIR)
@if [ -f $(CONFIG_DIR)/config.yaml ]; then \
chown root:$(SERVICE_GROUP) $(CONFIG_DIR)/config.yaml; \
chmod 640 $(CONFIG_DIR)/config.yaml; \
fi
install -m 644 packaging/$(PROJECT_NAME).service $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
systemctl enable $(PROJECT_NAME)
systemctl start $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) installed and started."
uninstall-service:
-systemctl stop $(PROJECT_NAME) 2>/dev/null || true
-systemctl disable $(PROJECT_NAME) 2>/dev/null || true
rm -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
@echo "Service $(PROJECT_NAME) removed."
start:
systemctl start $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) started."
stop:
systemctl stop $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) stopped."
restart:
systemctl restart $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) restarted."
status:
systemctl status $(PROJECT_NAME)
enable:
systemctl enable $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) enabled on boot."
disable:
systemctl disable $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) disabled from boot."
release:
@test -n "$(VERSION)" || (echo "VERSION file is empty"; exit 1)
@echo "Releasing v$(VERSION)..."
git add -A
git commit -m "release v$(VERSION)" || true
git tag -f "v$(VERSION)"
git push
git push -f --tags
@echo "Released v$(VERSION)"
docker-build:
docker build -t $(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_IMAGE):latest .
docker-push: docker-build
docker push $(DOCKER_IMAGE):$(VERSION)
docker push $(DOCKER_IMAGE):latest
docker-release: docker-push
@echo "Pushed $(DOCKER_IMAGE):$(VERSION) and :latest"