#!/bin/bash
confirm() {
echo "Press RETURN to continue...";
read -e ignored
}
is_fqdn() {
hostname=$1
[[ $hostname == *"."* ]] || return 1
host $hostname > /dev/null 2>&1 || return 1
}
#
# Installation variables. These are the defaults used when running this
# script. You may modify as you need for your environment. Before running this
# script it is _highly_ recommended you have set your server's domain name.
#
DEFAULT_PATH="/var/www/"
DEFAULT_REPO="/var/repo/"
DEFAULT_MYSQL_USER="root"
DEFAULT_MYSQL_HOST="localhost"
DOMAIN_NAME=""
#
# 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"
fi
echoelse
echo "Phabricator will be installed to: ${INSTALL_PATH}.";
confirm
fi
mkdir -p INSTALL_PATH
#
# Create the repository path
#
echo
read -p "Path to install Phabricator to [${DEFAULT_REPO}]:" INSTALL_REPO
if [ -z "$INSTALL_REPO" ]
then
INSTALL_REPO="$DEFAULT_REPO"
fi
echoelse
echo "Respositories will be hosted from: ${INSTALL_REPO}.";
confirm
fi
mkdir -p INSTALL_REPO
#
# Set the server domain name
#
echo "Phabricator needs too be installed on it's own domain, like 'phabricator.mycompany.com'";if [ -z "$DOMAIN_NAME" ]
then
echo
read -p "Domain Name: " SERVER_NAME 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
echo "Phabricator will served from: http://${SERVER_NAME}.";
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
echo "Setting up database connection...";
echo
read -p "Enter MySQL username: " [${DEFAULT_MYSQL_USER}]:" USERNAME
if [ -z "$USERNAME" ]
then
USERNAMEAME="$DEFAULT_MYSQL_USER"
fi
bin/config set mysql.user $USERNAME
echo
read -p "Enter MySQL password: " PASSWORD
bin/config set mysql.pass $PASSWORD
echo
read -p "Enter MySQL hostname [${DEFAULT_MYSQL_HOST}]:" HOSTNAME
read -p "Enter MySQL hostname: " if [ -z "$HOSTNAME" ]
then
HOSTNAME="$DEFAULT_MYSQL_HOSTNAME"
fi
bin/config set mysql.host $HOSTNAME
echo
bin/storage upgrade --force
bin/config set phabricator.base-uri "http://${SERVER_NAME}"
bin/storage upgrade --force
#
# Launch the daemons
#
echo "Starting phd daemons...";
bin/phd start
echo
# TODO: echo "Write theing Apache sites-available file config...";
#echo
# <VirtualHost *>FILE="/etc/apache2/sites-available/054-phabricator.conf"
sudo cat > $FILE << EOM
# ServerName {$SERVER_NAME}<VirtualHost *>
# DocumentRoot /var/www/phabricator/webroot ServerName ${SERVER_NAME}
# RewriteEngine on DocumentRoot ${INSTALL_PATH}phabricator/webroot
# RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]eEngine on
# </VirtualHost> RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
#</VirtualHost>
<Directory "${INSTALL_PATH}phabricator/webroot">
# <Directory "/var/www/phabricator/webroot"> Require all granted
# Require all granted</Directory>
# </Directory>EOM
# TODO: Restart Apachesudo a2ensite 054-phabricator
#sudo systemctl restart apache2
# TODO: Set the server timezone to php.ini
#
TIMEZONE=`cat /etc/timezone`
# Peace out.
#
echo
echo
echo "Install probably worked ok. Continue at your local install:";
echo
echo " http://$SERVER_NAME";
echo