1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wordpress_ynh.git synced 2024-09-03 20:36:10 +02:00
wordpress_ynh/scripts/upgrade
2014-05-31 15:41:55 +02:00

80 lines
2.7 KiB
Bash

#!/bin/bash
# Retrieve arguments
domain=$(sudo yunohost app setting wordpress domain)
path=$(sudo yunohost app setting wordpress path)
admin_wordpress=$(sudo yunohost app setting wordpress admin)
if [ $admin_wordpress = '' ];
then
mysql -u root -p$root_pwd $db_name -e "select MAX(user_login) from wp_users where user_status=0 INTO OUTFILE '/tmp/wordpressuser';"
fi
language=$(sudo yunohost app setting wordpress language)
if [ $language = '' ];
then
grep WPLANG /var/www/wordpress/wp-config.php | cut -d"'" -f4
fi
is_public=$(sudo yunohost app setting wordpress is_public)
if [ is_public = '' ];
then
mysql -u root -p$root_pwd $db_name -e "select * from wp_options where option_name='http_authentication_options'";
fi
# Check if admin is not null
if [[ "$admin_wordpress" = "" || "$is_public" = "" || "$language" = "" ]]; then
echo "Unable to upgrade, please contact support"
exit 1
fi
# Generate random password
db_pwd=$(sudo yunohost app setting wordpress mysqlpwd)
# Use 'wordpress' as database name and user
db_user=wordpress
### Execute potential SQL statements here
# Copy files to the right place
final_path=/var/www/wordpress
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/wp-config.php $final_path/wp-config.php
# Change variables in Wordpress configuration
sudo sed -i "s/yunouser/$db_user/g" $final_path/wp-config.php
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/wp-config.php
sudo sed -i "s/yunobase/$db_user/g" $final_path/wp-config.php
for i in 1 2 3 4 5 6 7 8
do
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
if [ "$j" = "" ];
then
# For obscure reasons, the loop is too fast at execution
sleep 1
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
fi
sudo sed -i "s/KEY$i/$j/g" $final_path/wp-config.php
done
sudo sed -i "s/I18NTOCHANGE/$language/g" $final_path/wp-config.php
sudo sed -i "s@URLWORDPRESS@$domain$path@g" ../conf/*.sql
# Set permissions to roundcube directory
sudo chown -R www-data: $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf*
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf*
if [ $is_public = "Yes" ];
then
sudo cp ../conf/nginx.conf-public /etc/nginx/conf.d/$domain.d/wordpress.conf
grep -q "define('FORCE_SSL_ADMIN', true);" $final_path/wp-config.php
if [[ ! $? -eq 0 ]];
then
echo "define('FORCE_SSL_ADMIN', true);" | sudo tee -a $final_path/wp-config.php
fi
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/wordpress.conf
fi
# Reload Nginx
sudo service nginx reload