-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
72 lines (55 loc) · 2.88 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
# Copyright 2014 Abid Hasan Mujtaba
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Author: Abid H. Mujtaba
# Email: [email protected]
# Date: 2014-02-15
# This Makefile sets up the local-chromecast project by installing nginx, uwsgi and jinja2 (pip) if required and by placing config files in the correct locations.
# Variables
# The port on which nginx serves the application. 3435 is the only non-trivial Munchausen number.
PORT=3435
# The IP Address of the computer (server) on the Wireless network. Leave empty if you want the script to determine this automatically.
HOST=
# Declare PHONY targets
.PHONY: run, start, install
# Define targets
run: # Launches the application in Chrome
/usr/bin/google-chrome http://localhost:$(PORT)
start: # (re)starts the uwsgi and nginx services. Needs to be run as root (using sudo)
service uwsgi restart
service nginx restart
install: # Installs (sets up) the project. Needs to be run as root (using sudo)
apt-get install nginx
apt-get install uwsgi
apt-get install uwsgi-plugin-python
# Install the jinja2 module for python
pip install Jinja2
# Store the current working directory in CWD. This will be used to ensure that the symlinks and application point to the correct location.
$(eval CWD := $(shell pwd))
# Get IP address on Wireless network by parsing output of ifconfig
$(eval HOST := $(shell ifconfig wlan0 | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1))
# Add one to PORT to get the uwsgi port
$(eval PORT2 := $(shell echo $(PORT) + 1 | bc))
# Create subfolders for Media and generated files (where template variables are replaced by calculated values)
mkdir -p media
mkdir -p build/config
# Copy (template) application and configuration files to the build folder and then use sed to replace place-holders with the calculated working directory, port and host ip address
cp app.py build/
sed -i -e 's#CWD#$(CWD)#' -e 's#HOST#http://$(HOST):$(PORT)#' build/app.py
cp config/* build/config/
# Substitute PORT2 before PORT because the latter will change the PORT part of PORT2
sed -i -e 's#PORT2#$(PORT2)#' build/config/*
sed -i -e 's#PORT#$(PORT)#' -e 's#CWD#$(CWD)#' build/config/*
# Place symlinks to config files in nginx and uwsgi default locations for automatic configuration
ln -sf $(CWD)/build/config/nginx_local-chromecast.conf /etc/nginx/sites-enabled/
ln -sf $(CWD)/build/config/uwsgi_local-chromecast.ini /etc/uwsgi/apps-enabled/