#!/bin/bash
confirm() {
echo "Press RETURN to continue...";
read -e ignored
}
#
# Installation variables. These are the defaults used when running this
# script. You may modify as you need for your environment.
#
# Where to install stuff
DEFAULT_PATH="/var/www/"
DEFAULT_REPO="/var/repo/"
# MySQL Defaults
DEFAULT_MYSQL_USER="root"
DEFAULT_MYSQL_HOST="localhost"
# Full-Qualified Domain Name for your Phabricator installation
DOMAIN_NAME=""
# Pre-configure Large File Support, options are 'none, mysql, disk'
STORAGE_ENGINE="mysql"
STORAGE_PATH="/var/www/phabricator/files/"
# The default Timezone you want Phabricator to operate in
# http://php.net/manual/en/timezones.php
TIMEZONE=""
#
# Check Ubuntu Version
#
ISSUE=`cat /etc/issue`
if [[ $ISSUE != Ubuntu* ]]
then
echo "This script is intended for use on Ubuntu, but this system appears";
echo "to be something else. Your results may vary.";
echo
confirm
fi
#
# Test if using sudo
#
echo "Testing sudo..."
sudo true
if [ $? -ne 0 ]
then
echo "ERROR: You must be able to sudo to run this script.";
exit 1;
fi;
echo "OK..."
#
# Create the installation path
#
echo "----- PHABRICATOR UBUNTU INSTALL SCRIPT -----";
echo "This script will install Phabricator and all of its core dependencies.";
echo
read -p "Path to install Phabricator to [${DEFAULT_PATH}]:" INSTALL_PATH
if [ -z "$INSTALL_PATH" ]
then
INSTALL_PATH="$DEFAULT_PATH"
else
echo "Phabricator will be installed to: ${INSTALL_PATH}.";
confirm
fi
mkdir -p "$INSTALL_PATH"
#
# Create the repository path
#
read -p "Store repositories to [${DEFAULT_REPO}]:" INSTALL_REPO
if [ -z "$INSTALL_REPO" ]
then
INSTALL_REPO="$DEFAULT_REPO"
else
echo "Respositories will be hosted from: ${INSTALL_REPO}.";
confirm
fi
mkdir -p "$INSTALL_REPO"
#
# Set the server domain name
#
if [ -z "$DOMAIN_NAME" ]
then
echo
echo "Phabricator needs too be installed on its own fully qualified domain name.";
echo
read -p "This computer's domain name: " SERVER_NAME
else
SERVER_NAME="$DOMAIN_NAME"
fi
if ! [[ $SERVER_NAME == *"."* ]]
then
echo "ERROR: You must set a valid domain name.";
exit 1;
fi;
echo "Phabricator will served from: http://${SERVER_NAME}";
echo
confirm
#
# Install Dependencies
#
echo "Let's get cooking.";
echo "Adding apt-repository for PHP 7.1...";
echo
sudo add-apt-repository -y ppa:ondrej/php
echo "Installing dependencies: git, svn, hg, apache, mysql, php...";
echo
set +x
#
# TODO: APCu for 7.1?
#
sudo apt-get -qq update
sudo apt-get install \
git mysql-server apache2 dpkg-dev \
php7.1 php7.1-cli php7.1-common php7.1-curl php7.1-gd php7.1-json \
php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-xml php7.1-apcu \
npm subversion mercurial python-pygments sendmail
#
# Enable mod_rewrite
#
sudo a2enmod rewrite
sudo systemctl restart apache2
#
# Download from GitHub (maybe use stable?)
#
cd $INSTALL_PATH
if [ ! -e libphutil ]
then
git clone -b stable https://github.com/phacility/libphutil.git
else
(cd libphutil && git pull --rebase)
fi
if [ ! -e arcanist ]
then
git clone -b stable https://github.com/phacility/arcanist.git
else
(cd arcanist && git pull --rebase)
fi
if [ ! -e phabricator ]
then
git clone -b stable https://github.com/phacility/phabricator.git
else
(cd phabricator && git pull --rebase)
fi
#
# Set local config variables for Phabricator
#
cd phabricator
cd phabricator
echo "Setting up database connection...";
echo
read -p "Enter MySQL username [${DEFAULT_MYSQL_USER}]:" USERNAME
if [ -z "$USERNAME" ]
then
USERNAME="$DEFAULT_MYSQL_USER"
fi
read -p "Enter MySQL password: " PASSWORD
read -p "Enter MySQL hostname [${DEFAULT_MYSQL_HOST}]: " HOSTNAME
if [ -z "$HOSTNAME" ]
then
HOSTNAME="$DEFAULT_MYSQL_HOST"
fi
bin/config set mysql.user $USERNAME
bin/config set mysql.pass $PASSWORD
bin/config set mysql.host $HOSTNAME
bin/config set phabricator.base-uri "http://${SERVER_NAME}"
bin/config set repository.default-local-path "${INSTALL_REPO}"
bin/config set pygments.enabled true
bin/storage upgrade --force
#
# Enable Large File Support
#
if [ "$STORAGE_ENGINE" == "mysql" ]
then
echo "Setting large file storage to MySQL...";
bin/config set storage.mysql-engine.max-size 8388608
fi
if [ "$STORAGE_ENGINE" == "disk" ]
then
echo "Setting large file storage to Disk...";
mkdir -p "$STORAGE_PATH"
bin/config set storage.local-disk.path "$STORAGE_PATH"
fi
#
# Set php.ini variables (Setup Issue Resolution)
#
PHP_INI="/etc/php/7.1/apache2/php.ini"
if [ -z "$TIMEZONE" ];
then
TIMEZONE=`cat /etc/timezone`
fi
echo "date.timezone=$TIMEZONE" >> "$PHP_INI"
echo "post_max_size=32M" >> "$PHP_INI"
echo "opcache.validate_timestamps=0" >> "$PHP_INI"
bin/config set phabricator.timezone "$TIMEZONE"
#
# Set my.cnf variables (Setup Issue Resolution)
#
MY_CNF="/etc/mysql/mysql.conf.d/mysqld.conf"
echo "innodb_buffer_pool_size=1600M" >> "$MY_CNF"
#
# Configure Apache 2
#
echo "Writing Apache site config...";
echo
FILE="/etc/apache2/sites-available/054-phabricator.conf"
sudo cat > $FILE << EOM
<VirtualHost *>
ServerName ${SERVER_NAME}
DocumentRoot ${INSTALL_PATH}phabricator/webroot
RewriteEngine on
RewriteRule ^(.*)$ /index.php?__path__=\$1 [B,L,QSA]
</VirtualHost>
<Directory "${INSTALL_PATH}phabricator/webroot">
Require all granted
</Directory>
EOM
sudo a2ensite 054-phabricator
sudo a2dissite 000-default
sudo systemctl restart apache2
#
# Launch the daemons
#
echo "Starting phd daemons...";
bin/phd start
echo
# Peace out.
#
echo
echo
echo "Install probably worked ok. Continue at your local install:";
echo
echo " http://$SERVER_NAME";
echo