t3o.sh 1.49 KB
Newer Older
Joachim Mathes's avatar
Joachim Mathes committed
1 2 3 4 5 6 7
#/usr/bin/env bash

check_project_status() {
  [ -d /var/www/t3o/vendor ] && echo "Project seems to be initialized already." && exit 0
}

prepare_user_proserver() {
8 9 10
  sudo cp /home/vagrant/.ssh/authorized_keys /home/proserver/.ssh/authorized_keys
  sudo chown proserver:proserver /home/proserver/.ssh/authorized_keys
  sudo chmod 600 /home/proserver/.ssh/authorized_keys
Joachim Mathes's avatar
Joachim Mathes committed
11 12 13 14 15
}

initialize_project() {
  cd /var/www/t3o
  sudo -u proserver composer install
Joachim Mathes's avatar
Joachim Mathes committed
16
  cd /var/www
Joachim Mathes's avatar
Joachim Mathes committed
17
  sudo -u proserver rm -rf typo3
Joachim Mathes's avatar
Joachim Mathes committed
18
  sudo -u proserver ln -s t3o/html typo3
Joachim Mathes's avatar
Joachim Mathes committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
}

acquire_database_password() {
  TYPO3_DATABASE_PASSWORD=$(php -r '$configuration=include("/var/www/t3o/html/typo3conf/LocalConfiguration.php"); echo $configuration["DB"]["Connections"]["Default"]["password"];')
}

download_and_import_database() {
  DATABASE_ROOT_PASSWORD=$(sudo cat /usr/local/etc/mysql-password)

  cd /tmp
  curl -LsO https://vpro0100.proserver.punkt.de/sql/t3o.sql.gz
  mysql -u root -p${DATABASE_ROOT_PASSWORD} -e "CREATE DATABASE IF NOT EXISTS t3o"
  mysql -u root -p${DATABASE_ROOT_PASSWORD} -e "GRANT ALL ON t3o.* TO t3o@localhost identified by '${TYPO3_DATABASE_PASSWORD}'"
  gunzip < t3o.sql.gz | mysql -u root -p${DATABASE_ROOT_PASSWORD} t3o
}

restart_phpfpm() {
  sudo /usr/local/etc/rc.d/php-fpm restart
}

RC=0
case $1 in
  init)
    check_project_status
    prepare_user_proserver
    initialize_project
    acquire_database_password
    download_and_import_database
    restart_phpfpm
    ;;
  *)
    echo $"Usage: ./t3o init"
    RC=2
esac

exit $RC