1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#!/bin/bash
set -e
mode="$1"
version="$2"
# Source debconf library.
. /usr/share/debconf/confmodule
db_get "phabricator/domain_name"
domain_name="$RET"
db_get "phabricator/mysql_host"
mysql_host="$RET"
db_get "phabricator/phabricator_mysql_user"
phabricator_mysql_user="$RET"
db_get "phabricator/phabricator_mysql_pwd"
phabricator_mysql_pwd="$RET"
db_get "phabricator/webserver"
WWWTYPE="$RET"
#creating unprivileged system user to run the phabricator daemons
if ! getent passwd phabricator >/dev/null; then
adduser --system --ingroup www-data --home "/var/lib/phabricator" --quiet phabricator || true
elif [ $(id -gn phabricator) != www-data ]; then
#we have a phabricator user, but it isn't in the right group
usermod -g www-data phabricator
fi
local_disk_path="/var/lib/phabricator/phd_storage"
repo_default_local_path="/var/lib/phabricator/repositories"
log_directory="/var/log/phabricator"
local_conf_file="/var/lib/phabricator/local.json"
for dir in $repo_default_local_path $log_directory; do
#create a statoverride unless one already exists
if ! dpkg-statoverride --list $dir >/dev/null 2>&1; then
dpkg-statoverride --update --add phabricator nogroup 755 $dir
fi
done
[ -f "$local_conf_file" ] || echo '{}' >"$local_conf_file"
set_config() {
#we check if the configuration option is already set or not, in order to avoid overwritting local modifications
[[ $(/usr/share/phabricator/bin/config get $1 | jq -r '.config[] | select(.source=="local") | .status') == "set" ]] || /usr/share/phabricator/bin/config set $1 $2
}
case "$1" in
configure)
/usr/share/phabricator/bin/config set phabricator.base-uri http://$domain_name/
esac
set_config storage.local-disk.path $local_disk_path
#PHP doesn't provide the correct timezone, so we override the (default) date.timezone php setting
#see http://us3.php.net/date_default_timezone_get
set_config phabricator.timezone $(cat /etc/timezone)
#repository.default-local-path is where phabricator daemon will set up repositories
set_config repository.default-local-path $repo_default_local_path
set_config phd.log-directory $log_directory
#be polite by default
set_config phabricator.serious-business true
if [[ -n $phabricator_mysql_user && -n $phabricator_mysql_pwd ]]; then
/usr/share/phabricator/bin/config set mysql.host $mysql_host
/usr/share/phabricator/bin/config set mysql.user $phabricator_mysql_user
/usr/share/phabricator/bin/config set mysql.pass $phabricator_mysql_pwd
set_config storage.mysql-engine.max-size 0
/usr/share/phabricator/bin/storage upgrade --user $phabricator_mysql_user --password $phabricator_mysql_pwd --force
fi
#TODO:
#else
# echo "Not finished. please reconfigure"
if ! dpkg-statoverride --list $local_conf_file >/dev/null 2>&1; then
dpkg-statoverride --update --add root www-data 640 $local_conf_file
fi
### Webserver configuration
ucf --debconf-ok /usr/share/phabricator/conf_templates/phabricator.apache.conf /etc/apache2/conf-available/phabricator.conf
ucfr phabricator /etc/apache2/conf-available/phabricator.conf
ucf --debconf-ok /usr/share/phabricator/conf_templates/phabricator.lighttpd.conf /etc/lighttpd/conf-available/20-phabricator.conf
ucfr phabricator /etc/lighttpd/conf-available/20-phabricator.conf
ucf --debconf-ok /usr/share/phabricator/conf_templates/phabricator.nginx.conf /etc/nginx/sites-available/phabricator.conf
ucfr phabricator /etc/nginx/sites-available/phabricator.conf
### PHP configuration
TEMPDIR="$(mktemp --directory --tmpdir "phabricator.postinst.$$.XXXXX")"
trap "cd / ; rm -rf \"$TEMPDIR\"" EXIT
TEMP_PHP_INI="$TEMPDIR/php.ini"
# Set a value in an ini file, the key might be commented out, though
# $1: The ini file
# $2: The section
# $3: The key
# $4: The desired value
# $5: If set: Value is a number with "M" appended, desired value must
# be this or higher
edit_ini () {
local FILE ; FILE="$1"
local SECTION ; SECTION="$2"
local PARAMETER ; PARAMETER="$3"
local VALUE ; VALUE="$4"
local MEGS ; MEGS="${5:-}"
CURRENT="$(crudini --get "$FILE" "$SECTION" "$PARAMETER" 2>/dev/null || :)"
TEMP2="$TEMP_PHP_INI.1"
if [ -z "$CURRENT" ] ; then
# not set, perhaps commented out?
N="$(grep -n "^; *$PARAMETER *=" "$FILE" | cut -d: -f1)"
if [ "$N" ] ; then
# okay, uncomment
cp "$FILE" "$TEMP2"
sed -i -e "$N,${N}s/^; *//" "$FILE"
CURRENT="$(crudini --get "$FILE" "$SECTION" "$PARAMETER" 2>/dev/null || :)"
if [ -z "$CURRENT" ] ; then
# seldom: That didn't work, revert
cp "$TEMP2" "$FILE"
fi
fi
fi
if [ "$CURRENT" ] ; then
if [ "$MEGS" ] ; then
# compare current value
if \
echo "$CURRENT" | grep -iq '^[0-9][0-9]*m$' &&
[ "$(echo "$CURRENT" | sed -e 's/ *[mM]//')" -ge "$(echo "$VALUE" | sed -e 's/ *[mM]//')" ]
then
# good enough
return
fi
elif [ "$CURRENT" = "$VALUE" ] ; then
# value already set
return
fi
fi
# set
crudini --set "$FILE" "$SECTION" "$PARAMETER" "$VALUE"
}
for PHP_INI in /etc/php/*/apache2/php.ini ; do
[ -f "$PHP_INI" ] || continue
cp "$PHP_INI" "$TEMP_PHP_INI"
# Have a bigger post_max_size, at least 32M
edit_ini "$TEMP_PHP_INI" 'PHP' 'post_max_size' '32M' 1
# Configure opcache for production
edit_ini "$TEMP_PHP_INI" 'opcache' 'opcache.validate_timestamps' '0'
ucf --debconf-ok "$TEMP_PHP_INI" "$PHP_INI"
# purge but don't fail if it doesn't belong to us
ucfr --purge "$PHP_INI" 2>/dev/null || :
# TODO: Restart apache2 upon changes
# (not sure, config continues below)
done
# mariadb configuration
# Only if dbhost = localhost
TEMP_SERVER_CNF="$TEMPDIR/50-server.cnf"
for SERVER_CNF in /etc/mysql/mariadb.conf.d/50-server.cnf ; do
[ -f "$SERVER_CNF" ] || continue
cp "$SERVER_CNF" "$TEMP_SERVER_CNF"
edit_ini "$TEMP_SERVER_CNF" 'mysqld' 'max_allowed_packet' '32M' 1
# not at all sure about that
edit_ini "$TEMP_SERVER_CNF" 'mysqld' 'sql_mode' 'STRICT_ALL_TABLES'
edit_ini "$TEMP_SERVER_CNF" 'mysqld' 'innodb_buffer_pool_size' '1600M' 1
edit_ini "$TEMP_SERVER_CNF" 'mysqld' 'local_infile' '0'
ucf --debconf-ok "$TEMP_SERVER_CNF" "$SERVER_CNF"
# purge but don't fail if it doesn't belong to us
ucfr --purge "$SERVER_CNF" 2>/dev/null || :
# TODO: Restart mariadb upon changes
done
db_stop
# Update the webserver, if needed
case $WWWTYPE in
apache2)
#TODO: check if this is really the best place to modify the file
sed -i "s/ ServerName .*/ ServerName $domain_name/" /etc/apache2/conf-available/phabricator.conf
# Sniplet adjusted from http://wiki.debian.org/Apache/PackagingFor24
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke enmod rewrite
apache2_invoke enconf phabricator.conf
elif dpkg-query -f '${Version}' -W 'apache2.2-common' > /dev/null 2>&1; then
a2enmod -q rewrite
[ -d /etc/apache2/conf.d/ ] && [ ! -h /etc/apache2/conf.d/phabricator.conf ] && ln -s ../conf-available/phabricator.conf /etc/apache2/conf.d/phabricator.conf
else
echo "Apache2 not installed, skipping"
fi
;;
lighttpd)
if [ -e /etc/lighttpd/conf-available/20-phabricator.conf ] ; then
sed -i "s/\$HTTP\[\"host\"\] =.* {/\$HTTP[\"host\"] == \"$domain_name\" {/" /etc/lighttpd/conf-available/20-phabricator.conf
if which lighty-enable-mod >/dev/null 2>&1 ; then
lighty-enable-mod phabricator
else
echo "Lighttpd not installed, skipping"
fi
fi
;;
nginx)
if [ -e /etc/nginx/sites-available/phabricator.conf ] ; then
sed -i "s/ server_name .*/ server_name $domain_name;/" /etc/nginx/sites-available/phabricator.conf
[ ! -h /etc/nginx/sites-enabled/phabricator.conf ] && ln -s /etc/nginx/sites-available/phabricator.conf /etc/nginx/sites-enabled/phabricator.conf
fi
;;
*)
;;
esac
# Always trigger reload of webservers if the configuration is enabled
if [ -e /etc/apache2/conf.d/phabricator.conf -o -e /etc/apache2/conf-enabled/phabricator.conf ] ; then
invoke-rc.d apache2 reload || true
fi
if [ -e /etc/lighttpd/conf-enabled/20-phabricator.conf ] ; then
# We need to take care: bug #446324
invoke-rc.d lighttpd reload 3>/dev/null || true
fi
if [ -e /etc/nginx/sites-available/phabricator.conf ] ; then
invoke-rc.d nginx reload || true
fi
#we need to have a readable/writable local disk storage!
if ! dpkg-statoverride --list $local_disk_path >/dev/null 2>&1; then
dpkg-statoverride --update --add www-data www-data 755 $local_disk_path
fi
#DEBHELPER#
echo "Installation complete. You can now access Phabricator at $(/usr/share/phabricator/bin/config get phabricator.base-uri | jq '.config[0].value')"
exit 0
|