-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile.deps
149 lines (125 loc) · 4.02 KB
/
Makefile.deps
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
.PHONY: sudo deps-install deps-uninstall deps-start deps-stop prepare-nginx wait-postgresql prepare-postgresql resize resize-postgresql delete delete-postgresql
sudo:
sudo -v
deps-install: sudo
ifeq ($(OS),Linux)
sudo apt-get install redis-server
sudo apt-get install nginx
sudo apt-get install python3-dev libpq-dev postgresql postgresql-contrib
else ifeq ($(OS),Darwin)
brew list redis > /dev/null || brew install redis --build-from-source # FIXME: Homebrew/homebrew-core#11134
brew list nginx > /dev/null || brew install nginx
brew list postgresql > /dev/null || brew install postgresql
else
echo 'ACITON REQUIRED) Need to install redis and nginx before this.'
endif
deps-uninstall: sudo
ifeq ($(OS),Linux)
# TODO
echo 'ACITON REQUIRED) Need to uninstall redis, nginx and postgresql after this.'
else ifeq ($(OS),Darwin)
-brew list redis > /dev/null && brew uninstall redis
-brew list nginx > /dev/null && brew uninstall nginx
-brew list postgresql > /dev/null && brew uninstall postgresql
else
echo 'ACITON REQUIRED) Need to uninstall redis, nginx and postgresql after this.'
endif
deps-start:
# XXX: resudo for first-time user.
sudo -k
sudo -v
ifeq ($(OS),Linux)
sudo service redis-server start
else ifeq ($(OS),Darwin)
brew services run redis
else
sudo redis-server &
endif
ifeq ($(OS),Linux)
sudo service nginx start
else
sudo nginx &
endif
deps-start-postgresql: deps-install #[postgres]
ifeq ($(OS),Linux)
sudo service postgresql start
else ifeq ($(OS),Darwin)
brew services run postgresql
else
# TODO
endif
deps-stop: sudo
ifeq ($(OS),Linux)
sudo service nginx stop
else ifeq ($(OS),Darwin)
-sudo killall -9 'nginx: master process nginx'
-sudo killall -9 'nginx: worker process'
-sudo killall -9 nginx
else
-sudo killall -9 'nginx: master process nginx'
-sudo killall -9 'nginx: worker process'
-sudo killall -9 nginx
endif
ifeq ($(OS),Linux)
-sudo service redis-server stop
else ifeq ($(OS),Darwin)
-brew services stop redis
else
-sudo killall -9 redis-server
endif
ifeq ($(OS),Linux)
-sudo service postgresql stop
else ifeq ($(OS),Darwin)
-brew services stop postgresql
else
# TODO
endif
prepare-nginx: sudo nginx/local_nginx.conf
ifeq ($(OS),Linux)
sudo rm -f /etc/nginx/sites-enabled/local_nginx.conf
sudo ln -s `pwd`/nginx/local_nginx.conf /etc/nginx/sites-enabled/
else ifeq ($(OS),Darwin)
rm -f /usr/local/etc/nginx/servers/local_nginx.conf
ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/
else
# FIXME ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/
endif
wait-postgresql:
while ! pg_isready -h localhost; do sleep 1; done
export POSTGRES_USER=cnluser
export POSTGRES_PASSWORD=temporary
export POSTGRES_DB=codingnightlive
prepare-postgresql: sudo deps-start-postgresql wait-postgresql
ifeq ($(OS),Linux)
sudo su postgres -c 'createdb $(POSTGRES_DB)'
sudo -u postgres psql -c "CREATE USER $(POSTGRES_USER) WITH PASSWORD '$(POSTGRES_PASSWORD)';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $(POSTGRES_DB) TO $(POSTGRES_USER);"
sudo -u postgres -E ./postgres/init_sql.sh
else ifeq ($(OS),Darwin)
psql -c "CREATE DATABASE $(POSTGRES_DB)" -d postgres
psql -c "CREATE USER $(POSTGRES_USER) WITH PASSWORD '$(POSTGRES_PASSWORD)';" -d postgres
psql -c "GRANT ALL PRIVILEGES ON DATABASE $(POSTGRES_DB) TO $(POSTGRES_USER);" -d postgres
./postgres/init_sql.sh
else
# TODO
endif
touch .prepared-postgresql
resize resize-postgresql: sudo
ifeq ($(OS),Linux)
sudo -u postgres psql $(POSTGRES_DB) -c "ALTER TABLE socialaccount_socialapp ALTER COLUMN name TYPE character varying(65);"
else ifeq ($(OS),Darwin)
psql $(POSTGRES_DB) -c "ALTER TABLE socialaccount_socialapp ALTER COLUMN name TYPE character varying(65);"
else
# TODO
endif
delete delete-postgresql: sudo
# FIXME: make stop -> make uninstall : won't worked.
ifeq ($(OS),Linux)
-sudo su postgres -c 'dropdb $(POSTGRES_DB)'
-sudo su postgres -c 'dropuser $(POSTGRES_USER)'
else ifeq ($(OS),Darwin)
-psql -c 'drop database $(POSTGRES_DB)' -d postgres
-psql -c 'drop user $(POSTGRES_USER)' -d postgres
else
# TODO
endif