mirror of
https://github.com/YunoHost-Apps/piwigo_ynh.git
synced 2024-09-03 20:06:03 +02:00
113 lines
3.4 KiB
Bash
113 lines
3.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
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
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
if [ "$language" = "fr" ] ; then
|
|
applanguage="fr_FR"
|
|
else
|
|
applanguage="en_UK"
|
|
fi
|
|
|
|
# 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"
|
|
ynh_app_setting_set "$app" language "$language"
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
# Check user parameter
|
|
sudo yunohost user list --json | grep -qi "\"username\": \"$admin\""
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Wrong user"
|
|
exit 1
|
|
fi
|
|
|
|
# Download sources
|
|
sudo wget -q http://piwigo.org/download/dlcounter.php?code=2.8.3 -O piwigo.zip
|
|
|
|
# Uncompress
|
|
sudo unzip -qq piwigo.zip -d ..
|
|
|
|
# Copy source files
|
|
src_path=/var/www/$app
|
|
sudo mkdir -p $src_path/upload
|
|
sudo cp -a ../piwigo/. $src_path
|
|
|
|
datapath=/home/yunohost.app/$app
|
|
sudo mkdir -p $datapath
|
|
sudo mkdir -p $datapath/galleries
|
|
sudo mkdir -p $datapath/upload
|
|
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
|
|
|
|
sudo cp -R ../plugins/Ldap_Login $src_path/plugins/Ldap_Login
|
|
|
|
sudo chown -R www-data:www-data $src_path
|
|
sudo chown -R www-data:www-data $datapath
|
|
sudo chmod 777 $src_path/_data
|
|
sudo chmod 777 $src_path/upload
|
|
sudo chmod 755 -R $src_path/galleries
|
|
|
|
# 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"
|
|
|
|
# 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
|
|
|
|
# Set permissions and reload nginx (needed at this stage for the PHP piwigo installation process)
|
|
sudo service nginx reload
|
|
sudo yunohost app setting "$app" unprotected_uris -v "/"
|
|
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
|
|
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
|
|
|
|
#Change local config
|
|
sudo cp ../conf/config.inc.php $src_path/local/config/
|
|
|
|
#change variable in local/config/database.inc.php
|
|
|
|
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
|
|
|
|
sudo cp ../conf/database.inc.php $src_path/local/config/database.inc.php
|
|
|
|
#activate ldap plugin
|
|
|
|
mysql -u $dbuser -p$dbpass $dbname -e "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');"
|
|
|
|
#protect URIs if private
|
|
if [ $is_public -eq 0 ];
|
|
then
|
|
sudo yunohost app setting "$app" -d unprotected_uris
|
|
sudo yunohost app setting "$app" protected_uris -v "/"
|
|
fi
|