2014-07-06 13:21:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
|
|
|
|
if [ "$language" = "fr" ] ; then
|
|
|
|
applanguage="fr_FR"
|
|
|
|
else
|
|
|
|
applanguage="en_UK"
|
2014-07-06 13:21:10 +02:00
|
|
|
fi
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Save app settings
|
|
|
|
ynh_app_setting_set "$app" admin "$admin"
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
|
|
ynh_app_setting_set "$app" language "$language"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Check user parameter
|
|
|
|
sudo yunohost user list --json | grep -qi "\"username\": \"$admin\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Wrong user"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Copy source files
|
|
|
|
src_path=/var/www/$app
|
|
|
|
sudo mkdir -p $src_path
|
|
|
|
sudo cp -a ../sources/. $src_path
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
datapath=/home/yunohost.app/$app
|
2014-07-06 13:21:10 +02:00
|
|
|
sudo mkdir -p $datapath
|
|
|
|
sudo mkdir -p $datapath/galleries
|
|
|
|
sudo mkdir -p $datapath/upload
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo ln -sd $datapath/galleries $src_path/galleries
|
|
|
|
sudo ln -sd $datapath/upload $src_path/upload
|
|
|
|
sudo cp ../conf/index.php $src_path/galleries/index.php
|
2014-07-14 08:54:42 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo cp -R ../plugins/Ldap_Login $src_path/plugins/Ldap_Login
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo chown -R www-data:www-data $src_path
|
2014-07-06 15:38:46 +02:00
|
|
|
sudo chown -R www-data:www-data $datapath
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo chmod 777 $src_path/_data
|
|
|
|
sudo chmod 777 $src_path/upload
|
|
|
|
sudo chmod 755 -R $src_path/galleries
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Generate MySQL password and create database
|
|
|
|
dbuser=$app
|
|
|
|
dbname=$app
|
|
|
|
dbpass=$(ynh_string_random 12)
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# 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
|
|
|
|
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-07-14 08:54:42 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Set permissions and reload nginx (needed at this stage for the PHP piwigo installation process)
|
2014-07-06 13:21:10 +02:00
|
|
|
sudo service nginx reload
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo yunohost app setting "$app" unprotected_uris -v "/"
|
2014-07-06 13:21:10 +02:00
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
|
|
|
# Generate random password for admin
|
|
|
|
|
|
|
|
adm_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
|
|
|
|
#configure piwigo via curl
|
|
|
|
sleep 2
|
2016-09-11 10:15:45 +02:00
|
|
|
curl --resolve $domain:443:127.0.0.1 -kL -X POST https://$domain$path/install.php?language=$applanguage --data "install=true&dbuser=$dbuser&dbpasswd=$dbpass&dbname=$dbname&admin_name=$admin&admin_pass1=$adm_pwd&admin_pass2=$adm_pwd&admin_mail=$admin@$domain" > /tmp/piwigo-install.log 2>&1
|
2016-09-07 07:23:00 +02:00
|
|
|
|
|
|
|
#Change local config
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo cp ../conf/config.inc.php $src_path/local/config/
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
|
|
#change variable in local/config/database.inc.php
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo sed -i "s@DBTOCHANGE@$dbname@g" ../conf/database.inc.php
|
|
|
|
sudo sed -i "s@USERTOCHANGE@$dbuser@g" ../conf/database.inc.php
|
|
|
|
sudo sed -i "s@PASSTOCHANGE@$dbpass@g" ../conf/database.inc.php
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo cp ../conf/database.inc.php $src_path/local/config/database.inc.php
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
|
|
#activate ldap plugin
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
mysql -u $dbuser -p$dbpass $dbname -e "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
#protect URIs if private
|
|
|
|
if [ $is_public -eq 0 ];
|
2014-07-06 13:21:10 +02:00
|
|
|
then
|
2016-09-11 10:15:45 +02:00
|
|
|
sudo yunohost app setting "$app" -d unprotected_uris
|
|
|
|
sudo yunohost app setting "$app" protected_uris -v "/"
|
|
|
|
# sudo yunohost app ssowatconf
|
2014-07-06 13:21:10 +02:00
|
|
|
fi
|