2016-10-05 19:44:08 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
|
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
|
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
|
# db names, ...
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
# Save app settings
|
|
|
|
|
ynh_app_setting_set "$app" admin "$admin"
|
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
|
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
|
|
2016-10-08 19:08:37 +02:00
|
|
|
|
tmp=/tmp/flaruminstall
|
|
|
|
|
sudo rm -rf $tmp
|
|
|
|
|
sudo mkdir -p $tmp
|
|
|
|
|
sudo chown -R www-data:www-data $tmp
|
|
|
|
|
sudo chmod -R 755 $tmp
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
|
|
|
|
### composer ###
|
2016-10-08 19:08:37 +02:00
|
|
|
|
if ! type "composer" > /dev/null; then
|
|
|
|
|
# Install composer (https://getcomposer.org)
|
|
|
|
|
EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
|
|
|
|
|
sudo su - www-data -s /bin/bash -c "php -r \"copy('https://getcomposer.org/installer', '$tmp/composer-setup.php');\""
|
|
|
|
|
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', '$tmp/composer-setup.php');")
|
|
|
|
|
if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
|
|
|
|
|
then
|
|
|
|
|
sudo mkdir /var/www/.composer
|
|
|
|
|
sudo chown -R www-data:www-data /var/www/.composer
|
|
|
|
|
sudo chmod -R 755 /var/www/.composer
|
|
|
|
|
sudo su - www-data -s /bin/bash -c "php $tmp/composer-setup.php --install-dir=$tmp --filename=composer"
|
|
|
|
|
sudo mv $tmp/composer /usr/local/bin
|
|
|
|
|
sudo chown root:root /usr/local/bin/composer
|
|
|
|
|
RESULT=$?
|
|
|
|
|
else
|
|
|
|
|
>&2 echo 'ERROR: Invalid installer signature'
|
|
|
|
|
RESULT=1
|
|
|
|
|
fi
|
|
|
|
|
if [ $RESULT != 0 ]
|
|
|
|
|
then
|
|
|
|
|
sudo rm -rf $final_path
|
|
|
|
|
exit $RESULT
|
|
|
|
|
fi
|
2016-10-05 19:44:08 +02:00
|
|
|
|
fi
|
2016-10-08 19:08:37 +02:00
|
|
|
|
sudo mkdir -p /var/www/.composer
|
|
|
|
|
sudo chown -R www-data:www-data /var/www/.composer
|
|
|
|
|
sudo chmod -R 755 /var/www/.composer
|
2016-10-05 19:44:08 +02:00
|
|
|
|
### composer end ###
|
|
|
|
|
|
|
|
|
|
### Install flarum
|
2016-10-08 19:08:37 +02:00
|
|
|
|
cwd=$(pwd)
|
|
|
|
|
sudo su - www-data -s /bin/bash -c "mkdir -p $tmp/$app && cd $tmp/$app && php -d memory_limit=-1 /usr/local/bin/composer create-project flarum/flarum . --stability=beta"
|
|
|
|
|
sudo mkdir $final_path
|
|
|
|
|
sudo mv $tmp/$app $final_path/..
|
|
|
|
|
sudo chown -R www-data:www-data $final_path
|
|
|
|
|
cd $cwd
|
|
|
|
|
sudo rm -rf $tmp
|
2016-10-05 19:44:08 +02:00
|
|
|
|
|
2016-10-08 19:08:37 +02:00
|
|
|
|
### MySQL ###
|
2016-10-05 19:44:08 +02:00
|
|
|
|
dbuser=$app
|
|
|
|
|
dbname=$app
|
|
|
|
|
dbpass=$(ynh_string_random 15)
|
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
|
2016-10-08 19:08:37 +02:00
|
|
|
|
### Nginx ###
|
|
|
|
|
if [ $path = "/" ]; then
|
|
|
|
|
nginx_conf=../conf/nginx_root.conf
|
|
|
|
|
else
|
2016-10-05 19:44:08 +02:00
|
|
|
|
nginx_conf=../conf/nginx.conf
|
2016-10-08 19:08:37 +02:00
|
|
|
|
fi
|
2016-10-05 19:44:08 +02:00
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
|
|
|
sed -i "s@YNH_WWW_ALIAS@$app/@g" $nginx_conf
|
|
|
|
|
sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
|
|
|
|
|
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
|
|
### PHP ###
|
|
|
|
|
sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
|
|
|
|
sed -i "s@YNH_WWW_ALIAS@$app/@g" ../conf/php-fpm.conf
|
|
|
|
|
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
|
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
|
|
|
sudo chown root: $finalphpconf
|
|
|
|
|
sudo chmod 644 $finalphpconf
|
|
|
|
|
sudo service php5-fpm reload
|
|
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
|
if [[ $is_public -eq 1 ]]; then
|
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Reload services
|
|
|
|
|
sudo service nginx reload
|
2016-10-08 19:08:37 +02:00
|
|
|
|
|
|
|
|
|
# Tell user the MySQL credentials for post-installation
|
2016-10-05 19:44:08 +02:00
|
|
|
|
echo "MySQL database user is " $dbuser
|
|
|
|
|
echo "MySQL database password is " $dbpass
|