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/install
2013-12-10 10:30:41 +01:00

97 lines
3.2 KiB
Bash
Executable file

#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
admin_wordpress=$3
language=$4
is_public=$5
# Check if admin password is not null
if [ "$admin_wordpress" = "" ]; then
echo "Wrong admin"
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a wordpress
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 'wordpress' as database name and user
db_user=wordpress
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting wordpress mysqlpwd -v $db_pwd
# 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
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/wordpress.conf
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app setting wordpress skipped_uris -v "/"
sudo yunohost app ssowatconf
# Wordpress installation
echo "127.0.0.1 $domain #yunowordpress" | sudo tee -a /etc/hosts
sleep 1
curl -kL -X POST --data "?step=2&weblog_title=YunoBlog&user_name=$admin_wordpress&admin_password=$db_pwd&admin_password2=$db_pwd&admin_email=$admin_wordpress@$domain&Submit=Install+WordPress" http://$domain$path/wp-admin/install.php?step=2 #> /dev/null 2>&1
sleep 5
mysql -u $db_user -p$db_pwd $db_user -e "select * from wp_options;" > /dev/null 2>&1
result=$?
loop_number=1
while [ $result != 0 ] && [ $loop_number -lt 5 ];
do
sleep 5
mysql -u $db_user -p$db_pwd $db_user -e "select * from wp_options;" > /dev/null 2>&1
let result=$?
let loop_number++
done
if [ $is_public = "No" ];
then
sudo yunohost app setting wordpress skipped_uris -d
sudo yunohost app ssowatconf
mysql -u $db_user -p$db_pwd $db_user < ../conf/private.sql
else
mysql -u $db_user -p$db_pwd $db_user < ../conf/public.sql
sudo cp ../conf/nginx.conf-public /etc/nginx/conf.d/$domain.d/wordpress.conf
sudo service nginx reload
fi
sudo sed -i '/yunowordpress/d' /etc/hosts
echo "define('FORCE_SSL_ADMIN', true);" | sudo tee -a $final_path/wp-config.php