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

111 lines
3.2 KiB
Text
Raw Normal View History

2014-07-06 13:21:10 +02:00
#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
user=$3
is_public=$4
# Check user parameter
sudo yunohost user list --json | grep -q "\"username\": \"$user\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong user"
exit 1
fi
sudo yunohost app setting piwigo admin_user -v $user
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a piwigo
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Generate random password
db_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')
# Use 'piwigo' as database name and user
db_user=piwigo
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting piwigo mysqlpwd -v $db_pwd
# Modify Nginx configuration file and copy it to Nginx conf directory
final_path=/var/www/piwigo
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/piwigo.conf
2014-07-06 13:21:10 +02:00
# Copy files to the right place
datapath=/home/yunohost.app/piwigo
sudo mkdir -p $final_path
sudo mkdir -p $datapath
sudo mkdir -p $datapath/galleries
sudo mkdir -p $datapath/upload
sudo cp -a ../sources/* $final_path
2014-07-06 15:49:09 +02:00
sudo ln -sd $datapath/galleries $final_path/galleries
2014-07-06 13:21:10 +02:00
sudo ln -sd $datapath/upload $final_path/upload
2014-07-06 15:43:16 +02:00
sudo cp ../conf/index.php $final_path/galleries/index.php
2014-07-06 13:21:10 +02:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/piwigo.conf
sudo cp -R ../plugins/Ldap_Login $final_path/plugins/Ldap_Login
2014-07-07 19:07:36 +02:00
sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-piwigo.ini
2014-07-06 13:21:10 +02:00
# set permission
sudo chown -R www-data:www-data $final_path
2014-07-06 15:38:46 +02:00
sudo chown -R www-data:www-data $datapath
2014-07-06 13:21:10 +02:00
sudo chmod 777 $final_path/_data
sudo chmod 777 $final_path/upload
sudo chmod 755 -R $final_path/galleries
# Reload Nginx and regenerate SSOwat conf
sudo service php5-fpm restart
sudo service nginx reload
sudo yunohost app setting piwigo skipped_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
echo "127.0.0.1 $domain #yunopiwigo" | sudo tee -a /etc/hosts
sleep 2
curl -kL -X POST https://$domain$path/install.php?language=fr_FR --data "install=true&dbuser=$db_user&dbpasswd=$db_pwd&dbname=$db_user&admin_name=$user&admin_pass1=$adm_pwd&admin_pass2=$adm_pwd&admin_mail=webmaster@$domain" > /home/admin/test
#change variable in local/config/database.inc.php
sudo sed -i "s@DBTOCHANGE@$db_user@g" ../conf/database.inc.php
sudo sed -i "s@USERTOCHANGE@$db_user@g" ../conf/database.inc.php
sudo sed -i "s@PASSTOCHANGE@$db_pwd@g" ../conf/database.inc.php
sudo cp ../conf/database.inc.php $final_path/local/config/database.inc.php
#activate ldap plugin
mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');"
#protect URIs
if [ $is_public = "No" ];
then
2014-07-13 13:44:32 +02:00
sudo cp ../conf/config.inc.php $final_path/local/config/
2014-07-06 13:21:10 +02:00
sudo yunohost app setting piwigo protected_uris -v "/"
sudo yunohost app ssowatconf
fi
2014-07-06 13:21:10 +02:00
# Remove temporary entry in /etc/hosts
sudo sed -i '/yunopiwigo/d' /etc/hosts