-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
283 lines (248 loc) · 7.22 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
include .env
region_pbf = tmp/osm/$(REGION)-latest.osm.pbf
admin_osmjson = tmp/$(ADMIN).osm.json
admin_geojson = tmp/$(ADMIN).geojson
admin_poly = tmp/$(ADMIN).poly
admin_pbf = tmp/$(ADMIN).pbf
mbtiles = tmp/region.mbtiles
tilejson = docs/tiles.json
stylejson = docs/style.json
zxy_metadata = docs/zxy/metadata.json
pmtiles = tmp/region.pmtiles
pmtiles_docs = docs/region.pmtiles
pmtiles_stylejson = docs/style.pmtiles.json
targets = \
docs/openmaptiles/fonts/Open\ Sans\ Bold/0-255.pbf \
docs/openmaptiles/fonts/Open\ Sans\ Italic/0-255.pbf \
docs/openmaptiles/fonts/Open\ Sans\ Regular/0-255.pbf \
$(region_pbf) \
$(admin_osmjson) \
$(admin_geojson) \
$(admin_poly) \
$(admin_pbf) \
$(mbtiles) \
$(tilejson) \
$(zxy_metadata) \
$(stylejson)
all: $(targets)
clean:
sudo chmod 777 -R tmp
rm -rf docs/zxy/*
rm -f $(mbtiles)
rm -f $(stylejson)
rm -f $(tilejson)
rm -f $(pmtiles)
rm -f $(pmtiles_docs)
rm -f $(pmtiles_stylejson)
clean-all: clean
sudo chmod 777 -R tmp
rm -f $(admin_osmjson)
rm -f $(admin_geojson)
rm -f $(admin_poly)
rm -f $(admin_pbf)
rm -f $(mbtiles)
rm -f $(tilejson)
rm -f $(stylejson)
rm -f $(pmtiles)
rm -f $(pmtiles_docs)
rm -f $(pmtiles_stylejson)
rm -rf tmp/zxy/*
rm -rf docs/zxy/*
rm -rf docs/openmaptiles/fonts/Open\ Sans\ Bold
rm -rf docs/openmaptiles/fonts/Open\ Sans\ Italic
rm -rf docs/openmaptiles/fonts/Open\ Sans\ Regular
#
# docker
#
# Pull `yuiseki/vector-tile-builder` docker image if not exists
.PHONY: docker-pull
docker-pull:
docker image inspect yuiseki/vector-tile-builder:latest > /dev/null || docker pull yuiseki/vector-tile-builder:latest
docker image inspect yuiseki/go-pmtiles:latest > /dev/null || docker pull yuiseki/go-pmtiles:latest
.PHONY: docker-pull-all
docker-pull-all:
docker image inspect maptiler/tileserver-gl:latest > /dev/null || docker pull maptiler/tileserver-gl:latest
# Build `yuiseki/vector-tile-builder` docker image if not exists
.PHONY: docker-build
docker-build:
docker image inspect yuiseki/vector-tile-builder:latest > /dev/null || docker build . -t yuiseki/vector-tile-builder:latest
docker image inspect yuiseki/go-pmtiles:latest > /dev/null || docker build -t yuiseki/go-pmtiles:latest github.com/protomaps/go-pmtiles#main
# Push `yuiseki/vector-tile-builder` docker image to docker hub
# MEMO: require `docker login`
.PHONY: docker-push
docker-push:
docker push yuiseki/vector-tile-builder:latest
docker push yuiseki/go-pmtiles:latest
# Download OpenStreetMap data as Protocolbuffer Binary format file
$(region_pbf):
mkdir -p $(@D)
curl \
--continue-at - \
--output $(region_pbf) \
https://download.geofabrik.de/$(REGION)-latest.osm.pbf
QUERY = data=[out:json][timeout:30000]; relation["name:en"="$(ADMIN)"]; out geom;
$(admin_osmjson):
curl 'https://overpass-api.de/api/interpreter' \
--data-urlencode '$(QUERY)' > $(admin_osmjson)
$(admin_geojson):
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
bash -c "\
osmtogeojson /$(admin_osmjson) > /$(admin_geojson)\
"
$(admin_poly):
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
geojson2poly /$(admin_geojson) /$(admin_poly)
$(admin_pbf):
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
osmconvert /$(region_pbf) -B="/$(admin_poly)" --complete-ways -o=/$(admin_pbf)
#
# tilemaker
#
# Convert Protocolbuffer Binary format file to MBTiles format file
$(mbtiles):
mkdir -p $(@D)
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
tilemaker \
--threads 3 \
--skip-integrity \
--input /$(region_pbf) \
--output /$(mbtiles)
# Generate TileJSON format file from MBTiles format file
$(tilejson):
mkdir -p $(@D)
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
mbtiles2tilejson \
/tmp/region.mbtiles \
--url $(TILES_URL) > docs/tiles.json
sed "s|http://localhost:5000/|$(BASE_PATH)|g" -i docs/tiles.json
#
# tippecanoe
#
# Split MBTiles format file to zxy orderd Protocolbuffer Binary format files
$(zxy_metadata):
mkdir -p $(@D)
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/vector-tile-builder:latest \
tile-join \
--force \
--no-tile-compression \
--no-tile-size-limit \
--no-tile-stats \
--output-to-directory=/tmp/zxy \
/$(mbtiles)
cp -r tmp/zxy docs/
#
# charites
#
# Generate style.json from style.yml
$(stylejson):
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/,target=/app \
yuiseki/vector-tile-builder:latest \
charites build style.yml docs/style.json
sed "s|http://localhost:5000/|$(BASE_PATH)|g" -i docs/style.json
#
# go-pmtiles
#
# Convert MBTiles format file to PMtiles format file
$(pmtiles):
mkdir -p $(@D)
docker run \
-i \
--rm \
--mount type=bind,source=$(CURDIR)/tmp,target=/tmp \
yuiseki/go-pmtiles \
convert /$(mbtiles) /$(pmtiles)
$(pmtiles_docs): $(pmtiles)
cp -f $(pmtiles) $(pmtiles_docs)
$(pmtiles_stylejson): $(stylejson)
cp -f $(stylejson) $(pmtiles_stylejson)
sed "s|$(BASE_PATH)tile.json|pmtiles://$(BASE_PATH)region.pmtiles|g" -i $(pmtiles_stylejson)
docs/openmaptiles/fonts/Open\ Sans\ Bold/0-255.pbf:
cd docs/openmaptiles/fonts && unzip Open\ Sans\ Bold.zip
chmod 777 -R docs/openmaptiles/fonts
docs/openmaptiles/fonts/Open\ Sans\ Italic/0-255.pbf:
cd docs/openmaptiles/fonts && unzip Open\ Sans\ Italic.zip
chmod 777 -R docs/openmaptiles/fonts
docs/openmaptiles/fonts/Open\ Sans\ Regular/0-255.pbf:
cd docs/openmaptiles/fonts && unzip Open\ Sans\ Regular.zip
chmod 777 -R docs/openmaptiles/fonts
# Launch local tile server
.PHONY: start
start:
docker run \
-it \
--rm \
--mount type=bind,source=$(CURDIR)/docs,target=/app/docs \
-p $(PORT):$(PORT) \
yuiseki/vector-tile-builder \
http-server \
-p $(PORT) \
docs
# Initialize gh-pages branch
.PHONY: init-gh-pages
init-gh-pages:
git checkout --orphan gh-pages
git commit --allow-empty -m "empty commit"
git push -u origin gh-pages
git checkout main
# Publish ./docs to GitHub Pages, with ignoring .gitignore
.PHONY: gh-pages
gh-pages:
sed -i '/docs/d' ./.gitignore
git add .
git commit -m "Edit .gitignore to publish"
git push origin `git subtree split --prefix docs main`:gh-pages --force
git reset HEAD~
git checkout .gitignore
# Configure Raspberry Pi as Wi-Fi AP
# need to call with sudo
# `sudo make build-wifi-ap`
.PHONY: build-wifi-ap
build-wifi-ap:
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo "Starting to configure Wi-Fi AP..."
cat /etc/rpi-issue
apt update
apt upgrade -y
DEBIAN_FRONTEND=noninteractive \
apt install -y \
hostapd \
dnsmasq \
netfilter-persistent \
iptables-persistent
systemctl unmask hostapd
systemctl enable hostapd
cp conf/etc/dhcpcd.conf /etc/dhcpcd.conf
cp conf/etc/dnsmasq.conf /etc/dnsmasq.conf
cp conf/etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf
cp conf/etc/sysctl.d/routed-ap.conf /etc/sysctl.d/routed-ap.conf
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
netfilter-persistent save
rfkill unblock wlan
systemctl reboot