mirror of
https://github.com/YunoHost-Apps/wordpress_ynh.git
synced 2024-09-03 20:36:10 +02:00
91 lines
4.2 KiB
Bash
Executable file
91 lines
4.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
admin_passwd=$3
|
|
language=$4
|
|
is_public=$5
|
|
|
|
# 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')
|
|
key1=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key2=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key3=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key4=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key5=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key6=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key7=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
key8=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\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
|
|
sudo sed -i "s/KEY1/$key1/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY2/$key2/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY3/$key3/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY4/$key4/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY5/$key5/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY6/$key6/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY7/$key7/g" $final_path/wp-config.php
|
|
sudo sed -i "s/KEY8/$key8/g" $final_path/wp-config.php
|
|
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 #wordpress" | sudo tee -a /etc/hosts
|
|
curl -X POST -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:12.0) Gecko/20100101 Firefox/12.0" -e "http://$domain$path/wp-admin/install.php?step=2" -H "Content-Type:application/x-www-form-urlencoded" -H "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Encoding:gzip, deflate" --data "?step=2&weblog_title=YunoBlog&user_name=admin&admin_password=$admin_passwd&admin_password2=$admin_passwd&admin_email=admin@$domain&Submit=Install+WordPress" http://$domain$path/wp-admin/install.php?step=2&weblog_title=YunoBlog&user_name=admin&admin_password=$admin_passwd&admin_password2=$admin_passwd&admin_email=admin@$domain&Submit=Install+WordPress
|
|
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
|
|
fi
|
|
sudo sed -i '/wordpress/d' /etc/hosts
|