|
| 1 | +#!/bin/bash |
| 2 | +set -x |
| 3 | +set -e |
| 4 | + |
| 5 | +PACKAGENAME=builder |
| 6 | + |
| 7 | +if [[ "$OSTYPE" == "linux-gnu" ]]; then |
| 8 | + echo "Configuring environment for Linux" |
| 9 | + if [[ ! $TRAVIS ]]; then |
| 10 | + # Ubuntu Server (on AWS?) lacks UTF-8 for some reason. Give it that |
| 11 | + sudo locale-gen en_US.UTF-8 |
| 12 | + # Make sure we have up-to-date stuff |
| 13 | + sudo apt-get update |
| 14 | + fi |
| 15 | + # Install dependencies |
| 16 | + sudo apt-get install -y apache2 libapache2-mod-php5 php-pear php5-curl php5-sqlite php5-mysql acl curl git |
| 17 | + # Enable Apache configs |
| 18 | + sudo a2enmod rewrite |
| 19 | + sudo a2enmod alias |
| 20 | + # Restart Apache |
| 21 | + sudo service apache2 restart |
| 22 | +elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 23 | + # is there something comparable to this on os x? perhaps Homebrew |
| 24 | + echo "Configuring environment for OS X" |
| 25 | +fi |
| 26 | + |
| 27 | +if [[ ! $TRAVIS ]]; then |
| 28 | + |
| 29 | + ##### Enable/Install phpunit |
| 30 | + sudo apt-get install -y phpunit |
| 31 | + |
| 32 | + #### Set Max nesting lvl to something Symfony is happy with |
| 33 | + export ADDITIONAL_PATH=`php -i | grep -F --color=never 'Scan this dir for additional .ini files'` |
| 34 | + echo 'xdebug.max_nesting_level=256' | sudo tee ${ADDITIONAL_PATH:42}/symfony2.ini |
| 35 | +fi |
| 36 | + |
| 37 | +HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` |
| 38 | + |
| 39 | +sudo mkdir -p /opt/codebender |
| 40 | +sudo cp -r . /opt/codebender/$PACKAGENAME |
| 41 | +sudo chown -R `whoami`:$HTTPDUSER /opt/codebender/$PACKAGENAME |
| 42 | +cd /opt/codebender/$PACKAGENAME |
| 43 | + |
| 44 | +#Set permissions for app/cache and app/logs |
| 45 | + |
| 46 | +rm -rf Symfony/app/cache/* |
| 47 | +rm -rf Symfony/app/logs/* |
| 48 | + |
| 49 | +if [[ "$OSTYPE" == "linux-gnu" ]]; then |
| 50 | + |
| 51 | + if [[ ! $TRAVIS ]]; then |
| 52 | + |
| 53 | + sudo dd if=/dev/zero of=cache-fs bs=1024 count=0 seek=200000 |
| 54 | + sudo dd if=/dev/zero of=logs-fs bs=1024 count=0 seek=200000 |
| 55 | + |
| 56 | + yes | sudo mkfs.ext4 cache-fs |
| 57 | + yes | sudo mkfs.ext4 logs-fs |
| 58 | + |
| 59 | + mkdir -p `pwd`/Symfony/app/cache/ |
| 60 | + mkdir -p `pwd`/Symfony/app/logs/ |
| 61 | + |
| 62 | + echo "`pwd`/cache-fs `pwd`/Symfony/app/cache/ ext4 loop,acl 0 0" | sudo tee -a /etc/fstab > /dev/null 2>&1 |
| 63 | + echo "`pwd`/logs-fs `pwd`/Symfony/app/logs/ ext4 loop,acl 0 0" | sudo tee -a /etc/fstab > /dev/null 2>&1 |
| 64 | + cat /etc/fstab |
| 65 | + |
| 66 | + sudo mount `pwd`/Symfony/app/cache/ |
| 67 | + sudo mount `pwd`/Symfony/app/logs/ |
| 68 | + |
| 69 | + sudo rm -rf `pwd`/Symfony/app/cache/* |
| 70 | + sudo rm -rf `pwd`/Symfony/app/logs/* |
| 71 | + |
| 72 | + sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs |
| 73 | + sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs |
| 74 | + fi |
| 75 | + |
| 76 | +elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 77 | + |
| 78 | + HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` |
| 79 | + sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs |
| 80 | + sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs |
| 81 | +fi |
| 82 | + |
| 83 | +cd Symfony |
| 84 | + |
| 85 | +# TODO: generate parameters.yml file somehow |
| 86 | +## For reference, here's a command to replace a substring in a file |
| 87 | +## cat kourades.sh | sed 's/kourades/skata/g' | tee skata.sh > /dev/null 2>&1 |
| 88 | + |
| 89 | +# cp app/config/parameters.yml.dist app/config/parameters.yml |
| 90 | +cat app/config/parameters.yml.dist | sed 's/database_pass: ~/database_pass: hello/g' > app/config/parameters.yml |
| 91 | + |
| 92 | + |
| 93 | +set +x |
| 94 | +cat app/config/parameters.yml | grep -v "compiler:" | tee app/config/parameters.yml > /dev/null |
| 95 | +echo " compiler: '$COMPILER_URL'" >> app/config/parameters.yml |
| 96 | + |
| 97 | +cat app/config/parameters.yml | grep -v "library:" | tee app/config/parameters.yml > /dev/null |
| 98 | +echo " library: '$LIBRARY_URL'" >> app/config/parameters.yml |
| 99 | +set -x |
| 100 | + |
| 101 | + |
| 102 | +curl -s http://getcomposer.org/installer | php |
| 103 | +php composer.phar install |
| 104 | +#php app/console doctrine:database:create |
| 105 | +#php app/console doctrine:schema:create |
| 106 | +#yes | php app/console doctrine:fixtures:load |
| 107 | +#php app/console codebender:tests:install |
| 108 | + |
| 109 | +# TODO: Add this later on (Apache config) |
| 110 | +#sudo cp /opt/codebender/$PACKAGENAME/apache-config /etc/apache2/sites-available/codebender |
| 111 | +#cd /etc/apache2/sites-enabled |
| 112 | +#sudo ln -s ../sites-available/codebender 00-codebender |
0 commit comments