#!/bin/sh # Running as the 'gliders' user, fetch and deploy the # backend tools and website. This script will download # all our logs from various dockservers and # migrates data (such as users) from the old gliders # website database. # Generate a SSH key # We want passwordless authentication when logging into # dockservers from scripts etc. ssh-keygen echo "Please copy the public key on your gitlab account with the name gliders" cat /home/gliders/.ssh/id_rsa.pub echo "Plese press return when you are done" read #We need to go to the gliders home directory first cd /home/gliders # Install Composer mkdir -p /home/gliders/bin curl -sS https://getcomposer.org/installer | php -- --install-dir=bin ln -s /home/gliders/bin/composer.phar /home/gliders/bin/composer # Set up python environment and directories mkdir -p /home/gliders/code mkdir -p /home/gliders/devtools mkdir -p /home/gliders/pythonenv mkdir -p /var/gliders/www /var/gliders/www_dev /var/gliders/logs virtualenv /home/gliders/pythonenv --system-site-packages echo 'source /home/gliders/pythonenv/bin/activate' >> /home/gliders/.bash_profile source /home/gliders/pythonenv/bin/activate # Set up our web dev tools dirs... ln -s /usr/share/phpMyAdmin /home/gliders/devtools/phpma # PHPCI and APC-Admin would be useful, but as we don't need # them for the production server they're left out of this # script. cd /home/gliders/code # Add contents of /home/gliders/.ssh/id_rsa.pub to GitLab, then: git clone git@gitlab.noc.soton.ac.uk:owanes/gliders-tools.git git clone git@gitlab.noc.soton.ac.uk:owanes/gliders-website.git # Install the gliders DB and parser python libraries, # then fetch all our log files and parse them! cd gliders-tools python setup.py install pip install pymysql pip install python-dateutil pip install lxml==3.4.4 pip install sqlalchemy pip install elasticsearch pip install pymongo python setup.py install sudo cp fetchlogs.service /etc/systemd/system/ sudo systemctl enable fetchlogs echo "please enter your mysql root user password" read -s pass mysql -u root -p$pass < new_schema.sql echo "DROP USER 'gliders'@'%';" | mysql -u root -p$pass echo "CREATE USER 'gliders'@'%' IDENTIFIED BY '"$pass"' ;" | mysql -u root -p$pass echo "GRANT ALL ON gliders.* TO 'gliders'@'%';" | mysql -u root -p$pass cd bin sh migrate_data.sh $pass sudo systemctl start fetchlogs # Set up a GitHub API key and add it to .bash_profile # export API_KEY=... echo "Deploying the website requires interacting with GitHub a lot." echo "We need a GitHub API Key so we don't go over the public limits." echo "Please go to: https://github.com/settings/tokens/new?scopes=repo&description=`hostname`" echo "Generate the token and then paste it into the prompt below." read -p "Token: " GITHUB_API_KEY echo "export GITHUB_API_KEY=$GITHUB_API_KEY" >> ~/.bashrc echo "export BOWERPHP_TOKEN=$GITHUB_API_KEY" >> ~/.bashrc composer config -g github-oauth.github.com $GITHUB_API_KEY export BOWERPHP_TOKEN=$GITHUB_API_KEY # Setup memcache and imagick cd /home/gliders/code git clone 'https://github.com/php-memcached-dev/php-memcached.git' cd php-memcached phpize ./configure make && sudo make install echo 'extension=memcached.so' >> memcached.ini sudo cp memcached.ini /etc/php.d/ cd /home/gliders/code git clone 'https://github.com/mkoppanen/imagick.git' cd imagick phpize ./configure make sudo make install echo 'extension=imagick.so' | sudo tee -a /etc/php.d/imagick.ini sudo systemctl restart php-fpm # Deploy the website cd /home/gliders/code/gliders-website sh bin/deploy.sh /var/gliders/www_dev dev sh bin/deploy.sh /var/gliders/www prod