-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
106 lines (94 loc) · 3.05 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
NAME = sunainapai
FQDN = $(NAME).com
FQDN_IN = $(NAME).in
MAIL = $(FQDN_IN)@gmail.com
help:
@echo 'Usage: make [target]'
@echo
@echo 'High-level targets:'
@echo ' setup Install Debian packages.'
@echo ' https Reinstall live website and serve with Nginx via HTTPS.'
@echo ' http Reinstall live website and serve with Nginx via HTTP.'
@echo ' update Pull latest Git commits and update live website.'
@echo ' rm Uninstall live website.'
@echo ' local Generate local website and serve with Python.'
@echo
@echo 'Low-level targets:'
@echo ' live Generate live website but do not serve.'
@echo ' site Generate local website but do not serve.'
@echo ' pull Pull latest Git commits but do not update live website.'
@echo
@echo 'Default target:'
@echo ' help Show this help message.'
setup:
apt-get update
apt-get -y install nginx certbot
https: http
@echo Setting up HTTPS website ...
certbot certonly -n --agree-tos -m '$(MAIL)' --webroot \
-w '/var/www/$(FQDN)' -d '$(FQDN),www.$(FQDN),$(FQDN_IN),www.$(FQDN_IN)'
(crontab -l | sed '/::::/d'; cat etc/crontab) | crontab
ln -snf "$$PWD/etc/nginx/https.$(FQDN)" '/etc/nginx/sites-enabled/$(FQDN)'
systemctl reload nginx
@echo Done; echo
http: rm live
@echo Setting up HTTP website ...
ln -snf "$$PWD/_live" '/var/www/$(FQDN)'
ln -snf "$$PWD/etc/nginx/http.$(FQDN)" '/etc/nginx/sites-enabled/$(FQDN)'
systemctl reload nginx
echo 127.0.0.1 '$(NAME)' >> /etc/hosts
@echo Done; echo
update: pull live
rm: checkroot
@echo Removing website ...
rm -f '/etc/nginx/sites-enabled/$(FQDN)'
rm -f '/var/www/$(FQDN)'
systemctl reload nginx
sed -i '/$(NAME)/d' /etc/hosts
#
# Following crontab entries left intact:
crontab -l | grep -v "^#" || :
@echo Done; echo
local: site
@echo Serving website locally ...
if python3 -c "import http.server" 2> /dev/null; then \
echo Running Python3 http.server ...; \
cd _site && python3 -m http.server; \
elif python -c "import http.server" 2> /dev/null; then \
echo Running Python http.server ...; \
cd _site && python -m http.server; \
elif python -c "import SimpleHTTPServer" 2> /dev/null; then \
echo Running Python SimpleHTTPServer ...; \
cd _site && python -m SimpleHTTPServer; \
else \
echo Cannot find http.server or SimpleHTTPServer.; \
fi
@echo Done; echo
live: site
@echo Setting up live directory ...
mv _live _gone || :
mv _site _live
rm -rf _gone
@echo Done; echo
site:
@echo Generating website ...
python3 makesite.py
# Look for blob directory and create a symbolic link to it.
for d in /opt/blob/sunainapai.com/img ~/blob/sunainapai.com/img; \
do if [ -e "$$d" ]; then ln -snf "$$d" _site/img; break; fi done
@echo Done; echo
pull:
@echo Pulling new changes ...
git fetch
if [ "$$(git rev-parse HEAD)" = "$$(git rev-parse "@{u}")" ]; then \
echo; echo No new changes; echo; false; \
fi
git merge
@echo Done; echo
checkroot:
@echo Checking if current user is root ...
[ $$(id -u) = 0 ]
@echo Done; echo
clean:
find . -name "__pycache__" -exec rm -r {} +
find . -name "*.pyc" -exec rm {} +