-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (45 loc) · 1.38 KB
/
Makefile
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
.PHONY: all
APP_BUILD_NAME = sfb
PATH_MAIN_GO = ./cmd/shutdown-from-browser/main.go
OS_BUILD = linux
SYSD_FILE = /etc/systemd/system/sfb.service
ifeq ($(OS), Windows_NT)
OS_BUILD = windows
APP_BUILD_NAME = sfb.exe
endif
all: clean get build-web build-app
build-web:
@echo " > Building web-components"
@cd ./web && npm install --legacy-peer-deps && npm run build
build-app:
@echo " > Building go app"
@CGO_ENABLED=0 GOOS=$(OS_BUILD) go build -ldflags "-w" -a -o $(APP_BUILD_NAME) $(PATH_MAIN_GO)
gotest:
go test ./...
gotestcover:
go test ./... -cover
get:
@echo " > Checking dependencies"
@go mod download
@go install $(PATH_MAIN_GO)
clean:
@echo " > Clearing folder"
@rm -f ./$(APP_BUILD_NAME)
@rm -rf ./web/build
install:
@echo " > Installing app as service"
@cp ./$(APP_BUILD_NAME) /usr/bin
@mkdir -p /usr/bin/sfb_configs/
@cp ./configs/config.yml /usr/bin/sfb_configs/
@echo '[Unit]\nDescription=Linux service for shutdown PC from the browser' > $(SYSD_FILE)
@echo '[Service]\nType=simple\nUser=root\nExecStart=/usr/bin/$(APP_BUILD_NAME)\nRestart=on-failure' >> $(SYSD_FILE)
@echo '[Install]\nWantedBy=multi-user.target' >> $(SYSD_FILE)
@chmod 644 $(SYSD_FILE)
@systemctl daemon-reload
@systemctl enable sfb.service
@systemctl start sfb.service
uninstall:
@rm -f $(SYSD_FILE)
@rm -f /usr/bin/SFB
@rm -rf /usr/bin/sfb_configs
@systemctl daemon-reload