1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piwigo_ynh.git synced 2024-09-03 20:06:03 +02:00
piwigo_ynh/scripts/install

118 lines
3.5 KiB
Text
Raw Normal View History

2014-07-06 13:21:10 +02:00
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
2014-07-06 13:21:10 +02:00
shopt -s extglob # sets extended pattern matching options in the bash shell
app=$YNH_APP_INSTANCE_NAME
2014-07-06 13:21:10 +02:00
2017-01-03 18:32:00 +01:00
# Source local helpers
source ./_common.sh
# 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
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2014-07-06 13:21:10 +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
2017-01-28 10:58:14 +01:00
# Fix path if needed
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; 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}"
2014-07-06 13:21:10 +02:00
2017-01-03 18:32:00 +01:00
# Download and extract application
extract_application ..
# Copy source files
src_path=/var/www/$app
sudo mkdir $src_path
sudo cp -a ../!(upload|galleries) $src_path
2014-07-06 13:21:10 +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
sudo ln -sd $datapath/galleries $src_path/galleries
sudo cp -a ../galleries/* $src_path/galleries/
sudo ln -sd $datapath/upload $src_path/upload
2014-07-14 08:54:42 +02:00
sudo cp -R ../plugins/Ldap_Login $src_path/plugins/Ldap_Login
2014-07-06 13:21:10 +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
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
# 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
# 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
# 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-12-30 17:32:19 +01:00
ynh_app_setting_set "$app" unprotected_uris "/"
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
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/
2014-07-06 13:21:10 +02:00
#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
2014-07-06 13:21:10 +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
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
#protect URIs if private
if [ $is_public -eq 0 ];
2014-07-06 13:21:10 +02:00
then
2016-12-30 17:32:19 +01:00
ynh_app_setting_delete "$app" unprotected_uris
ynh_app_setting_set "$app" protected_uris "/"
2014-07-06 13:21:10 +02:00
fi