<commit_before>VIKING_ROOT ?= /srv/viking
SSHCOMMAND_URL ?= https://raw.github.com/progrium/sshcommand/master/sshcommand
VPC_URL ?= https://raw.github.com/binocarlos/vpc/master/bootstrap.sh
NAVE_URL ?= https://raw.github.com/isaacs/nave/master/nave.sh
NODE_VERSION ?= 0.10.26

.PHONY: install dependencies basics sshcommand docker aufs nodejs network links developer recentgit vagrant

install: dependencies setup

setup:
	usermod -aG docker viking
	usermod -aG sudo viking
	mkdir -p /etc/viking
	mkdir -p /var/run/viking
	mkdir -p /var/log/viking
	mkdir -p /var/lib/viking
	mkdir -p /var/lib/viking/volumes
	chown -R viking:viking /var/lib/viking
	chown -R viking:viking /var/run/viking
	chown -R viking:viking /var/log/viking
	chmod -R g+w /var/lib/viking
	chmod -R g+w /var/run/viking
	chmod -R g+w /var/log/viking

vagrant: install vagrantsetup

vagrantsetup: vagrantgroups vagrantinit

vagrantgroups:
	usermod -aG docker vagrant
	usermod -aG viking vagrant

vagrantinit:
	./vagrant/admin init

dependencies: basics sshcommand supervisord docker vpc nodejs etcd

basics:
	apt-get update
	apt-get install -y git curl software-properties-common python-software-properties python g++

sshcommand:
	wget -qO /usr/local/bin/sshcommand ${SSHCOMMAND_URL}
	chmod +x /usr/local/bin/sshcommand
	sshcommand create viking /usr/local/bin/viking

#mon:
#	(mkdir /tmp/mon && cd /tmp/mon && curl -L# https://github.com/visionmedia/mon/archive/master.tar.gz | tar zx --strip 1 && make install)
#	(mkdir /tmp/mongroup && cd /tmp/mongroup && curl -L# https://github.com/jgallen23/mongroup/archive/master.tar.gz | tar zx --strip 1 && make install)
#	rm -rf /tmp/mon
#	rm -rf /tmp/mongroup

supervisord:
	apt-get -y install supervisor

docker: aufs
	egrep -i "^docker" /etc/group || groupadd docker
	curl https://get.docker.io/gpg | apt-key add -
	echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
	apt-get update
	apt-get install -y lxc-docker
	sleep 2 # give docker a moment i guess

aufs:
	lsmod | grep aufs || modprobe aufs || apt-get install -y linux-image-extra-`uname -r`

network:
	sysctl -w net.ipv4.ip_forward=1

vpc: network
	wget -qO- ${VPC_URL} | sudo bash
	sleep 1
	service docker restart
	sleep 1

nodejs:
	wget -qO /usr/local/bin/nave ${NAVE_URL}
	chmod a+x /usr/local/bin/nave
	nave usemain ${NODE_VERSION}

etcd:
	curl -L https://github.com/coreos/etcd/releases/download/v0.3.0/etcd-v0.3.0-linux-amd64.tar.gz -o /tmp/etcd-v0.3.0-linux-amd64.tar.gz
	cd /tmp && gzip -dc etcd-v0.3.0-linux-amd64.tar.gz | tar -xof -
	cp -f /tmp/etcd-v0.3.0-linux-amd64/etcdctl /usr/local/bin
	cp -f /tmp/etcd-v0.3.0-linux-amd64/etcd /usr/local/bin
	rm -rf /tmp/etcd-v0.3.0-linux-amd64.tar.gz

token:
	@curl https://discovery.etcd.io/new
	@echo

clean:
	./vagrant/admin ssh viking stop
	./vagrant/admin ssh sudo killall node
	./vagrant/admin ssh sudo viking reset 

#links:
#	rm -f /usr/local/bin/viking
#	ln -s $(CURDIR)/viking /usr/local/bin/viking

#recentgit:
#	add-apt-repository ppa:voronov84/andreyv -y
#	apt-get update
#	apt-get install -y git

#developer: recentgit links
#  ./vagrant/installphantom<commit_msg>supervisor makefile<commit_after>VIKING_ROOT ?= /srv/viking
SSHCOMMAND_URL ?= https://raw.github.com/progrium/sshcommand/master/sshcommand
VPC_URL ?= https://raw.github.com/binocarlos/vpc/master/bootstrap.sh
NAVE_URL ?= https://raw.github.com/isaacs/nave/master/nave.sh
NODE_VERSION ?= 0.10.26

.PHONY: install dependencies basics sshcommand docker aufs nodejs network links developer recentgit vagrant

install: dependencies setup

setup:
	usermod -aG docker viking
	usermod -aG sudo viking
	mkdir -p /etc/viking
	mkdir -p /var/run/viking
	mkdir -p /var/log/viking
	mkdir -p /var/lib/viking
	mkdir -p /var/lib/viking/volumes
	chown -R viking:viking /var/lib/viking
	chown -R viking:viking /var/run/viking
	chown -R viking:viking /var/log/viking
	chmod -R g+w /var/lib/viking
	chmod -R g+w /var/run/viking
	chmod -R g+w /var/log/viking

vagrant: install vagrantsetup

vagrantsetup: vagrantgroups vagrantinit

vagrantgroups:
	usermod -aG docker vagrant
	usermod -aG viking vagrant

vagrantinit:
	./vagrant/admin init

dependencies: basics sshcommand supervisord docker vpc nodejs etcd

basics:
	apt-get update
	apt-get install -y git curl software-properties-common python-software-properties python g++

sshcommand:
	wget -qO /usr/local/bin/sshcommand ${SSHCOMMAND_URL}
	chmod +x /usr/local/bin/sshcommand
	sshcommand create viking /usr/local/bin/viking

#mon:
#	(mkdir /tmp/mon && cd /tmp/mon && curl -L# https://github.com/visionmedia/mon/archive/master.tar.gz | tar zx --strip 1 && make install)
#	(mkdir /tmp/mongroup && cd /tmp/mongroup && curl -L# https://github.com/jgallen23/mongroup/archive/master.tar.gz | tar zx --strip 1 && make install)
#	rm -rf /tmp/mon
#	rm -rf /tmp/mongroup

supervisord:
	apt-get -y install supervisor

docker: aufs
	egrep -i "^docker" /etc/group || groupadd docker
	curl https://get.docker.io/gpg | apt-key add -
	echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
	apt-get update
	apt-get install -y lxc-docker
	sleep 2 # give docker a moment i guess

aufs:
	lsmod | grep aufs || modprobe aufs || apt-get install -y linux-image-extra-`uname -r`

network:
	sysctl -w net.ipv4.ip_forward=1

vpc: network
	wget -qO- ${VPC_URL} | sudo bash
	sleep 1
	service docker restart
	sleep 1

nodejs:
	wget -qO /usr/local/bin/nave ${NAVE_URL}
	chmod a+x /usr/local/bin/nave
	nave usemain ${NODE_VERSION}

etcd:
	curl -L https://github.com/coreos/etcd/releases/download/v0.4.1/etcd-v0.4.1-linux-amd64.tar.gz -o /tmp/etcd-v0.4.1-linux-amd64.tar.gz
	cd /tmp && gzip -dc etcd-v0.4.1-linux-amd64.tar.gz | tar -xof -
	cp -f /tmp/etcd-v0.4.1-linux-amd64/etcdctl /usr/local/bin
	cp -f /tmp/etcd-v0.4.1-linux-amd64/etcd /usr/local/bin
	rm -rf /tmp/etcd-v0.4.1-linux-amd64.tar.gz

token:
	@curl https://discovery.etcd.io/new
	@echo

clean:
	./vagrant/admin ssh viking stop
	./vagrant/admin ssh sudo killall node
	./vagrant/admin ssh sudo viking reset 

#links:
#	rm -f /usr/local/bin/viking
#	ln -s $(CURDIR)/viking /usr/local/bin/viking

#recentgit:
#	add-apt-repository ppa:voronov84/andreyv -y
#	apt-get update
#	apt-get install -y git

#developer: recentgit links
#  ./vagrant/installphantom
{'fraction_non_alphanumeric': 0.13503184713375796, 'fraction_numerical': 0.015605095541401274, 'mean_word_length': 3.4672830725462305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4238008', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2547, 'n_words': 598}