Last active
December 11, 2016 04:24
-
-
Save missinglink/3129f7cdf7ec3aba2f65 to your computer and use it in GitHub Desktop.
Pelias Build Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dependencies | |
for dep in 'git' 'wget' 'curl'; do | |
if [ ! `which $dep` ]; then | |
echo "$dep required, please install it and try again"; | |
exit 1; | |
fi | |
done | |
# Check that elasticsearch is installed and running | |
es_version='1.2.1'; | |
es_port='9200'; | |
if [[ ! `curl -s localhost:$es_port` ]]; then | |
echo "elasticsearch not found on port $es_port"; | |
exit 1; | |
fi | |
if [[ ! `curl -s localhost:$es_port | grep number | grep "$es_version"` ]]; then | |
echo "you are not running elasticsearch version $es_version"; | |
exit 1; | |
fi | |
basedir="/var/www"; | |
dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'`; | |
# Install nodejs stable | |
echo "updating nodejs and npm binaries"; | |
cd /tmp; | |
wget https://raw.githubusercontent.com/isaacs/nave/master/nave.sh; | |
sudo bash nave.sh usemain stable; | |
# create directory if it doesn't exist | |
if [ ! -d $basedir ]; then | |
echo "creating dir: $basedir"; | |
sudo mkdir $basedir; | |
sudo chown $USER:$USER $basedir; | |
fi | |
# Install bower globally | |
if [ ! `type bower > /dev/null 2>&1` ]; then | |
echo "sudo required to install bower globally"; | |
sudo npm install bower -g; | |
fi | |
clone() { | |
cd $basedir; | |
org=`echo $1 | cut -d"/" -f1`; | |
repo=`echo $1 | cut -d"/" -f2`; | |
[ -d $org ] || mkdir $org; | |
cd $org; | |
if [ ! -d "$repo" ]; then | |
# github="[email protected]:$1.git"; | |
github="https://github.com/$1.git"; | |
echo "cloning repo: $github"; | |
git clone $github; | |
fi | |
cd $repo; | |
git pull; | |
git checkout $2; | |
npm install; | |
yes no | bower --allow-root install; | |
} | |
# Update repositories | |
sudo chown $USER:$USER ~/.npm; # fix weird osx permission issues | |
clone "pelias/schema" "master"; | |
clone "mapzen/pelias-geonames" "master"; | |
clone "mapzen/pelias-openstreetmap" "master"; | |
clone "mapzen/pelias-webview" "master"; | |
# Reset mappings | |
cd $basedir/pelias/schema; | |
echo "y" | node scripts/drop_index.js; | |
node scripts/create_index.js; | |
# Update webview | |
if [ "$dist" == "Ubuntu" ]; then | |
cd $basedir/mapzen/pelias-webview; | |
# Install Upstart Script | |
if [ ! -f /etc/init/pelias.conf ]; then | |
wget https://gist.githubusercontent.com/missinglink/fdec4bd4fb4926bc37dc/raw/pelias.conf; | |
sed -i -e "s|/var/www|$basedir|g" pelias.conf; # inline replace paths | |
echo "sudo required to install upstart script"; | |
sudo mv pelias.conf /etc/init/pelias.conf; | |
sudo chmod 755 /etc/init/pelias.conf; | |
echo "$USER ALL = (root) NOPASSWD: /sbin/start pelias, /sbin/stop pelias" | sudo tee -a /etc/sudoers | |
fi | |
# Restart webview | |
sudo service pelias stop; | |
sudo service pelias start; | |
fi | |
# Import geonames | |
cd $basedir/mapzen/pelias-geonames; | |
if [ ! -f data/allCountries.zip ]; then | |
./bin/pelias-geonames -d all; # download allCountries.zip | |
fi | |
./bin/pelias-geonames -i all; # import allCountries.zip | |
# Import openstreetmap | |
cd $basedir/mapzen/pelias-openstreetmap; | |
node index.js; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment