Snippets

Housni Yakoob Kpo7: Untitled snippet

Created by Housni Yakoob
#
# Koobli3
#
# Copyright (c) 2015 Koobli3 <housni.yakoob@gmail.com>
#
# USAGE:
#		make [OPTION] TARGET
#
# DESCRIPTION
#		Builder for the Koobli3 project providing TARGETs that do everything from configuring and
#		installing to cleaning.
#
# OPTIONS
#		PROJECT=<name>
#			<name> is a string and it is typically the name of the project. Using `sed`, this
#			variable will be inserted into files, replacing instances of '__PROJECT__NAME__'
#			with <name>.
#
#		SECRET=<key>
#			<key> will be used as the secret key for MCRYPT in session configuration file that is
#			located at 'app/libraries/koobli3/config/bootstrap/session.php'. If this value is not
#			provided, one is generated by grabbing the 'md5sum' output of a git object file.
#
# TARGETS
#		prepare
#		configure
#		install
#		clean
#		distclean
#		help
#

# OS detection
UNAME := $(shell uname)
ifeq ($(UNAME_S),Darwin)
	OS = darwin
else
	OS = linux
endif

ifndef SECRET
	# Looks for the last file in the '.git/objects/*/*' directory and grabs the 'md5sum' of that
	# file (omitting the file name from the output)
	SECRET="$(shell md5sum $(shell ls -1 $(CURDIR)/.git/objects/*/* | tail -n 1) | cut -c -32)"
endif

prepare:
    ifndef PROJECT
		$(error PROJECT is not set)
    endif

# target: configure - configures all files for the installation
configure:
	prepare
	cp $(CURDIR)/app/libraries/koobli3/config/bootstrap/connections.sample.php $(CURDIR)/app/libraries/koobli3/config/bootstrap/connections.php
	chmod -R 0777 $(CURDIR)/app/resources/tmp
	sed -i -e "s|__PROJECT__NAME__|$(PROJECT)|g" $(CURDIR)/app/libraries/koobli3/config/bootstrap.php
	sed -i -e "s|__MCRYPT_SECRET_KEY__|$(SECRET)|g" $(CURDIR)/app/libraries/koobli3/config/bootstrap/session.php

# target: install - installs the app.
install:
	git submodule update --init --recursive
	./li3 db schema create Roles,Users,RolesUsers
	./li3 db reload
	wget -O $(CURDIR)/app/webroot/js/respond.js \
			https://raw.github.com/scottjehl/Respond/master/src/respond.js

	wget -O $(CURDIR)/app/webroot/js/bootstrap.min.js \
			https://raw.github.com/twbs/bootstrap/master/dist/js/bootstrap.min.js
	wget -O $(CURDIR)/app/webroot/css/bootstrap.min.css \
			https://raw.github.com/twbs/bootstrap/master/dist/css/bootstrap.min.css
	wget -O $(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.eot \
			https://github.com/twbs/bootstrap/raw/master/dist/fonts/glyphicons-halflings-regular.eot
	wget -O $(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.svg \
			https://raw.github.com/twbs/bootstrap/master/dist/fonts/glyphicons-halflings-regular.svg
	wget -O $(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.ttf \
			https://github.com/twbs/bootstrap/raw/master/dist/fonts/glyphicons-halflings-regular.ttf
	wget -O $(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.woff \
			https://github.com/twbs/bootstrap/raw/master/dist/fonts/glyphicons-halflings-regular.woff

	wget -O $(CURDIR)/app/webroot/js/jquery-latest.min.js \
			http://code.jquery.com/jquery-latest.min.js

	wget -O $(CURDIR)/app/webroot/js/modernizr.min.js \
			http://modernizr.com/downloads/modernizr-latest.js

	wget -O $(CURDIR)/app/webroot/js/holder.js \
			https://raw.github.com/imsky/holder/master/holder.js

# target: install - Cleans out templates and log files.
clean:
	\rm -rf $(CURDIR)/app/resources/tmp/cache/templates/*.php
	\rm -rf $(CURDIR)/app/resources/tmp/cache/states/*.json
	\rm -rf $(CURDIR)/app/resources/tmp/logs/*/*.log*

# target: install - Sets everything to the way it originally was.
distclean:
	clean
	./li3 db schema create
	\rm $(CURDIR)/app/libraries/koobli3/config/bootstrap/connections.php
	sed -i -e "s|define('PROJECT_NAME', '[^']*');|define('PROJECT_NAME', '__PROJECT__NAME__');|g" app/libraries/koobli3/config/bootstrap.php
	sed -i -e "s|'secret'\s*=>\s*'[^']*'|'secret' => '__MCRYPT_SECRET_KEY__'|g" $(CURDIR)/app/libraries/koobli3/config/bootstrap/session.php
	\rm $(CURDIR)/app/webroot/js/respond.js \
		$(CURDIR)/app/webroot/js/bootstrap.min.js \
		$(CURDIR)/app/webroot/css/bootstrap.min.css \
		$(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.eot \
		$(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.svg \
		$(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.ttf \
		$(CURDIR)/app/webroot/fonts/glyphicons-halflings-regular.woff \
		$(CURDIR)/app/webroot/js/jquery-latest.min.js \
		$(CURDIR)/app/webroot/js/modernizr.min.js \
		$(CURDIR)/app/webroot/js/holder.js

# target: help - Display callable targets.
help:
	egrep "^# target:" [Mm]akefile

.PHONY: prepare configure install clean distclean help

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.