forked from Dashticz/dashticz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (102 loc) · 3.03 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
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
-include Makefile.ini
PORT?=8082
APP?=dtv3-$(PORT)
TZ?="$(shell cat /etc/timezone)"
CHECKDOCKER?=true
.PHONY: help
help:
@echo "Installation script"
@echo "make help : Show this info"
@echo "make start : Build Dashticz container and start it on port 8082"
@echo " Parameters: "
@echo " PORT=<port> : Build Dashticz container and start in on the provided port"
@echo "make stop : Stop the Domoticz container"
@echo
@echo "make update : Update Dashticz to the latest version from Github"
@echo "make beta : Switch to the beta branch"
@echo "make master : Switch to the master branch"
testdocker:
ifeq ($(CHECKDOCKER),true)
ifeq (, $(shell which docker))
@echo "Let's install docker first"
sudo apt update --allow-releaseinfo-change
wget -qO- https://get.docker.com/ | sh
endif
endif
testgit:
ifeq (, $(shell which git))
@echo "Installing git ..."
sudo apt-get install git
endif
testport:
ifeq ($(shell ss -ln src :$(PORT) | grep -Ec -e "\<$(PORT)\>"),0)
else
@echo
@echo "PORT is defined in Makefile.ini as $(PORT)"
@echo "This port already is in use"
@echo "Please use a different port."
@echo "Then restart via: make start"
@echo
@exit 201
endif
.PHONY: start
start: testdocker testgit
@echo "Checking container $(APP)"
ifeq ($(shell sudo docker ps -q -a -f NAME=$(APP) ),)
@echo "Checking port $(PORT)"
ifeq ($(shell ss -ln src :$(PORT) | grep -Ec -e "\<$(PORT)\>"),0)
sudo docker build --build-arg tz=$(TZ) -t $(APP) .
sudo docker run --restart unless-stopped -v /etc/localtime:/etc/localtime:ro --name $(APP) -d -p $(PORT):80 --mount type=bind,source="$(CURDIR)",target=/var/www/html $(APP)
@echo
@echo "Dashticz is running at:"
@printf "http://%s:`sudo docker inspect -f '{{ (index (index .NetworkSettings.Ports "80/tcp") 0).HostPort }}' $(APP)`\n" `hostname -I | grep -Po '\b(?:\d{1,3}\.){3}\d{1,3}\b'`
else
@echo
@echo "Port $(PORT) already is in use."
@echo "If you want to rebuild run the following command first: make stop"
@echo "or edit Makefile.ini with a new port and retry via: make start"
@echo
endif
else
@echo
@echo "The Docker container $(APP) for Dashticz already exists"
@echo "If you want to rebuild run the following command first: make stop"
@echo "or edit Makefile.ini with a new name for APP and retry via: make start"
@echo
endif
.PHONY: stop
stop:
@echo "Cleaning up $(APP)"
ifeq ($(shell sudo docker ps -q -a -f NAME=$(APP) ),)
#container doesn exist
@echo "Container $(APP) non existing"
else
@echo "Container $(APP) exists"
ifeq (true, $(shell sudo docker inspect -f '{{.State.Running}}' $(APP) 2>/dev/null))
#container is running
sudo docker stop $(APP)
endif
sudo docker rm $(APP)
endif
.PHONY: dockerinstall
dockerinstall:
echo installing docker
sudo apt-get install docker.io
.PHONY: logs
logs:
sudo docker container logs $(APP)
.PHONY: login
login:
sudo docker exec -it $(APP) bash
.PHONY: status
status:
sudo docker ps -f name=$(APP)
.PHONY: update
update:
git pull
.PHONY: master
master:
git checkout master
.PHONY: beta
beta:
git checkout master