2015-08-23 17:33:13 +02:00
#!/bin/bash
2017-02-05 16:11:01 +01:00
#set -eu
2015-08-23 17:33:13 +02:00
# Retrieve arguments
domain=$1
admin=$2
2017-02-05 16:11:01 +01:00
email=$3
2017-02-11 02:05:28 +01:00
upload=$4
2015-08-23 17:33:13 +02:00
2017-02-05 16:11:01 +01:00
app="hubzilla"
2015-08-23 17:33:13 +02:00
path="/"
2017-02-05 16:11:01 +01:00
# Source app helpers
source /usr/share/yunohost/helpers
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
ynh_app_setting_set $app admin_user $admin
# Check destination directory
final_path="/var/www/$app"
[[ -d $final_path ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app."
sudo yunohost app setting $app is_public -v "Yes"
2015-08-23 17:33:13 +02:00
# Check domain/path availability
2017-02-05 16:11:01 +01:00
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "The path ${domain}${path} is not available for app installation."
2015-08-23 17:33:13 +02:00
# Install dependencies
sudo apt-get install -y -qq php5-cli php5-imagick php5-gd php5-mcrypt
# Use 'hubzilla' as database name and user
db_user=$app
2017-02-05 16:11:01 +01:00
db_name=$app
# Generate random password
dbpass=$(ynh_string_random)
2015-08-23 17:33:13 +02:00
# Initialize database and store mysql password for upgrade
2017-02-05 16:11:01 +01:00
sudo yunohost app initdb $db_user -p $dbpass
sudo yunohost app setting $app mysqlpwd -v $dbpass
#ynh_app_setting_set "$app" mysqlpwd "$dbpass"
2015-08-23 17:33:13 +02:00
# Copy source files
sudo mkdir -p $final_path
sudo rsync -va ../sources/ $final_path/
sudo mkdir -p "$final_path/store/[data]/smarty3"
sudo chmod -R 777 $final_path/store
# Import database schema
2017-02-05 16:11:01 +01:00
sudo mysql -u$db_user -p$dbpass $db_name < $final_path/install/schema_mysql.sql
2015-08-23 17:33:13 +02:00
# Copy the template install/htconfig.sample.php to .htconfig.php
sudo cp $final_path/install/htconfig.sample.php $final_path/.htconfig.php
# Use sed to add the database information to .htconfig.php
sudo sed -i "s/your.mysqlhost.com/localhost/g" $final_path/.htconfig.php
2017-02-05 16:11:01 +01:00
sudo sed -i "s/mysqlpassword/$dbpass/g" $final_path/.htconfig.php
2015-08-23 17:33:13 +02:00
sudo sed -i "s/mysqlusername/$db_user/g" $final_path/.htconfig.php
2017-02-05 16:11:01 +01:00
sudo sed -i "s/mysqldatabasename/$db_name/g" $final_path/.htconfig.php
sudo sed -i "s/mysite.example/$domain/g" $final_path/.htconfig.php
sudo sed -i "s/if the auto install failed, put a unique random string here/$(ynh_string_random)$(ynh_string_random)$(ynh_string_random)/g" $final_path/.htconfig.php
sudo sed -i "s/ADMIN_EMAIL_REPLACE/$email/g" $final_path/.htconfig.php
2015-08-23 17:33:13 +02:00
# Set www-data to owner
sudo chown -R www-data: $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2017-02-05 16:11:01 +01:00
# Modify php.ini to allow exec() function and increase the upload size limits
sudo sed -i 's/,pcntl_exec//g' /etc/php5/fpm/php.ini
2017-02-11 02:05:28 +01:00
sudo sed -i 's/^post_max_size =.*$/post_max_size = $upload/' /etc/php5/fpm/php.ini
sudo sed -i 's/^upload_max_filesize =.*$/upload_max_filesize = $upload/' /etc/php5/fpm/php.ini
2017-02-05 16:11:01 +01:00
sudo sed -i 's/^max_file_uploads =.*$/max_file_uploads = 50/' /etc/php5/fpm/php.ini
# Set SSOwat rules
ynh_app_setting_set "$app" skipped_uris "/"
2015-08-23 17:33:13 +02:00
2017-02-05 16:11:01 +01:00
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true
# Set up poller
sed -i "s@YNH_WWW_PATH@$final_path@g" ../conf/poller-cron
sudo cp ../conf/poller-cron /etc/cron.d/$app