1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/humhub_ynh.git synced 2024-09-03 19:26:11 +02:00
humhub_ynh/scripts/install
scith e9d1b11b31 Major improvements
- Auto-install
- Auto-setup LDAP
- Install and upgrade from URL (no source in repo)
- Improvement upgrade
- PHP5-FPM
- Package_check attempt
2017-04-24 16:04:55 +02:00

135 lines
4.5 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
app=$YNH_APP_INSTANCE_NAME
version=$(cat ../sources/version)
source='https://sourceforge.net/projects/humhub/files/'
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_extrahelpers
# Correct path: puts a / at the start and nothing at the end
if [ "${path:0:1}" != "/" ]; then
path="/$path"
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
path="${path:0:${#path}-1}"
fi
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Check admin user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist"
ynh_app_setting_set "$app" admin "$admin"
# Copy source files
src_path=/var/www/$app
sudo mkdir -p $src_path
sudo wget -q "${source}humhub-${version}.zip/download" -O humhub-${version}.zip
sudo unzip -qq humhub-${version}.zip
sudo cp -a humhub-${version}/. $src_path
# Hotfixes
# Fix LDAP email. See https://github.com/humhub/humhub/issues/1949
sudo cp -a ../sources/fix/AuthClientHelpers.php $src_path/protected/humhub/modules/user/authclient/AuthClientHelpers.php
# Fix to allow passwordless LDAP login
sudo cp -a ../sources/fix/ZendLdapClient.php $src_path/protected/humhub/modules/user/authclient/ZendLdapClient.php
sudo sed -i "s@defined('YII_DEBUG') or define('YII_DEBUG', true);@//defined('YII_DEBUG') or define('YII_DEBUG', true);@g" $src_path/index.php
sudo sed -i "s@defined('YII_ENV') or define('YII_ENV', 'dev');@//defined('YII_ENV') or define('YII_ENV', 'dev');@g" $src_path/index.php
# MySQL
dbuser=$app
dbname=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# Conf
app_conf=../conf/common.php
sed -i "s@DBNAME_TO_CHANGE@$dbname@g" $app_conf
sed -i "s@DBUSER_TO_CHANGE@$dbuser@g" $app_conf
sed -i "s@DBPASS_TO_CHANGE@$dbpass@g" $app_conf
sudo cp $app_conf $src_path/protected/config/common.php
# Set permissions to app files
sudo chown -R www-data: $src_path
# Cron
echo "30 * * * * $src_path/protected/yii cron hourly >/dev/null 2>&1" > cron
echo "00 18 * * * $src_path/protected/yii cron daily >/dev/null 2>&1" > cron
sudo mv cron /etc/cron.d/${app}
sudo chown root /etc/cron.d/${app}
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@${path:-/}@g" $nginx_conf
sed -i "s@YNH_WWW_ALIAS@$src_path/@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@$src_path/@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
# Reload services
sudo service php5-fpm reload
sudo service nginx reload
# Install
# Disable SSO
ynh_app_setting_set "$app" unprotected_uris "/"
sudo yunohost app ssowatconf
# Install with CURL
admin_temp_pass=$(ynh_string_random 6)
admin_email=$(sudo yunohost user info "$admin" --output-as plain | ynh_get_plain_key mail)
admin_firstname=$(sudo yunohost user info "$admin" --output-as plain | ynh_get_plain_key firstname)
admin_lastname=$(sudo yunohost user info "$admin" --output-as plain | ynh_get_plain_key lastname)
ynh_local_curl "/index.php?r=installer/index/go" "go"
ynh_local_curl "/index.php?r=installer/config/basic" \
"ConfigBasicForm[name]=YunoHost"
ynh_local_curl "/index.php?r=installer/config/use-case" \
"UseCaseForm[useCase]=" \
"UseCaseForm[useCase]=other"
ynh_local_curl "/index.php?r=installer/config/admin" \
"User[username]=$admin" \
"User[email]=$admin_email" \
"Password[newPassword]=$admin_temp_pass" \
"Password[newPasswordConfirm]=$admin_temp_pass" \
"Profile[firstname]=$admin_firstname" \
"Profile[lastname]=$admin_lastname" \
"save"
ynh_local_curl "/index.php?r=installer/config/sample-data" \
"SampleDataForm[sampleData]=0"
# Populate the LDAP parameters
sed -i "s@YNH_ADMIN_USER@$admin@g" ../conf/ldap.sql
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap.sql
# Enable SSO if chosen by the user
if [ $is_public = 0 ];
then
ynh_app_setting_delete $app unprotected_uris
sudo yunohost app ssowatconf
fi