Skip to content

Instantly share code, notes, and snippets.

@atelic
Created August 22, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atelic/f14c80e74eb66ebf02461fff6def2dd9 to your computer and use it in GitHub Desktop.
Save atelic/f14c80e74eb66ebf02461fff6def2dd9 to your computer and use it in GitHub Desktop.
#! /usr/bin/sh
PAC_MANAGER=''
ELASTICSEARCH_ARCHIVE='elasticsearch-1.5.0.tar.gz'
get_package_manager() {
echo -n "Is your package manager pacman or apt-get?: "
read package_manager
case $package_manager in
apt-get )
PAC_MANAGER='apt-get'
INSTALL_COMMAND='sudo apt-get install -y'
;;
# yum )
# PAC_MANAGER='yum'
# INSTALL_COMMAND='sudo yum -y'
# ;;
pacman )
PAC_MANAGER='pacman'
INSTALL_COMMAND='sudo pacman -S --noconfirm'
;;
* )
echo -e "Please enter either pacman or apt-get.\n"
get_package_manager
;;
esac
}
_java_is_installed() {
if type -p java
then
return 0
else
return 1
fi
}
_elasticsearch_is_installed() {
if type -p elasticsearch
then
return 0
else
return 1
fi
}
install_tokumx() {
case $PAC_MANAGER in
pacman )
if [ -n "$(pacman -Qs tokumx)" ]
then
echo "Tokumx is already installed"
else
echo "Tokumx is not installed ... installing now. You will need to enter your password"
sudo echo -e "[tokumx]\nServer = https://s3.amazonaws.com/tokumx-archlinux/$arch" >> /etc/pacman.conf
if [ $? -eq 0 ]
then
sudo pacman-key --recv-keys 505A7412 --keyserver keyserver.ubuntu.com
sudo pacman-key --lsign-key 505A7412
sudo pacman -Syyu tokumx --noconfirm
echo "Tokumx now installed"
else
echo "Error when installing Tokumx. Please try adding this to your pacman.conf:
[tokumx]
Server = http://s3.amazonaws.com/tokumx-archlinux/$arch
run sudo pacman-key --recv-keys 505A7412 --keyserver keyserver.ubuntu.com && sudo pacman-key --lsign-key 505A7412 && pacman -Syyu tokumx and re run this script" >&2
fi
fi
;;
apt-get )
if dpkg --get-selections | grep -q "^tokumx[[:space:]]*install$" >/dev/null; then
echo "Tokumx is already installed"
else
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 505A7412
echo "dev [arch=amd64] http://s3.amazon.aes.com/tokumx-debs $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/tokumx.list
sudo apt-get update
if sudo apt-get -qq install tokumx -y;
then
echo "Tokumx now installed"
else
echo "Problem installing Tokumx"
exit 1
fi
fi
;;
esac
}
install_elasticsearch() {
case $PAC_MANAGER in
pacman )
if _elasticsearch_is_installed
then
echo "Elasticsearch is already installed."
else
if _java_is_installed
then
if [ -d "/opt/elasticsearch" ]
then
sudo mkdir /opt/elasticsearch/
curl -SLO https://download.elasticsearch.org/elasticsearch/elasticsearch/$ELASTICSEARCH_ARCHIVE
sudo tar xzf $ELASTICSEARCH_ARCHIVE -C /opt/elasticsearch --strip-components=1
ln -s /opt/elasticsearch/bin/elasticsearch ~/bin/elasticsearch
else
curl -SLO https://download.elasticsearch.org/elasticsearch/elasticsearch/$ELASTICSEARCH_ARCHIVE
sudo tar xzf $ELASTICSEARCH_ARCHIVE -C /opt/elasticsearch --strip-components=1
ln -s /opt/elasticsearch/bin/elasticsearch ~/bin/elasticsearch
fi
else
sudo pacman -S jre7-openjdk
sudo mkdir /opt/elasticsearch/
if [ -d "/opt/elasticsearch" ]
then
sudo mkdir /opt/elasticsearch/
curl -SLO https://download.elasticsearch.org/elasticsearch/elasticsearch/$ELASTICSEARCH_ARCHIVE
sudo tar xzf $ELASTICSEARCH_ARCHIVE -C /opt/elasticsearch --strip-components=1
ln -s /opt/elasticsearch/bin/elasticsearch ~/bin/elasticsearch
else
curl -SLO https://download.elasticsearch.org/elasticsearch/elasticsearch/$ELASTICSEARCH_ARCHIVE
sudo tar xzf $ELASTICSEARCH_ARCHIVE -C /opt/elasticsearch --strip-components=1
ln -s /opt/elasticsearch/bin/elasticsearch ~/bin/elasticsearch
fi
fi
fi
;;
apt-get )
if _elasticsearch_is_installed
then
echo "Elasticsearch is alreay installed."
else
if _java_is_installed
then
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.deb
dpkg -i elasticsearch-0.90.7.deb
else
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java7-installer
java --version
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.deb
dpkg -i elasticsearch-0.90.7.deb
echo "Elasticseach is now installed and will be run on boot and should already be running"
fi
fi
;;
esac
}
install_node() {
case $PAC_MANAGER in
pacman )
if [ -n "$(pacman -Qs nodejs)" ]
then
echo "Node and npm already installed"
else
echo "Node and npm not installed ... installing now"
sudo pacman -S nodejs
fi
;;
apt-get )
if dpkg --get-selections | grep -q "^nodejs[[:space:]]*install$" >/dev/null; then
"Node is already installed. Symlinking to /usr/bin/node just in case"
sudo ln -s /usr/bin/nodejs /usr/bin/node
else
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
fi
;;
esac
}
install_reqs() {
virtualenv env -p /usr/bin/python2.7
sleep 5 #make sure that virtualenv is done
source env/bin/activate
cp website/settings/local-dist.py website/settings/local.py
cp api/base/settings/local-dist.py api/base/settings/local.py
inv copy_settings --addons
pip install invoke
invoke requirements
invoke requirements --dev --addons
npm install
sudo npm -g install bower
bower install
invoke assets --dev
}
main() {
if [ -d env/ ]; then
deactivate 2>/dev/null
rm -rf env/
fi
if [ ! -d $HOME/bin ]; then
mkdir $HOME/bin
fi
get_package_manager
install_tokumx
install_elasticsearch
install_node
install_reqs
inv encryption
echo "Done installing requirements..."
if [ $PAC_MANAGER == 'pacman' ]; then
echo "Run the server with these commands each in their own terminal:
sudo mongod --port 27017
sudo elasticsearch or elasticsearch -d to run in background
inv mailserver
inv rabbitmq
inv celery_worker
inv assets -dw
inv server "
else
echo "Run the server with these commands each in their own terminal:
sudo mongod --port 27017
inv mailserver
inv rabbitmq
inv celery_worker
inv assets -dw
inv server "
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment