Update v-install-wordpress

This commit is contained in:
myvesta 2020-07-18 00:35:19 +02:00 committed by GitHub
commit 32e87ecde1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,23 +1,19 @@
#!/bin/bash #!/bin/bash
# info: WordPress installer in one command line
# WordPress installer in one command line # options: DOMAIN USER
#
# Credits to Luka Paunović for wp-cli implememtation # Credits to Luka Paunović for wp-cli implememtation
if [ $# -lt 1 ]; then #----------------------------------------------------------#
echo usage: v-install-wordpress domain [db_name] [email] # Variable&Function #
exit 1 #----------------------------------------------------------#
fi
# Argument definition
domain=$1 domain=$1
PATH=$PATH:/usr/local/vesta/bin database="wp";
export PATH
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
START_DB="wp";
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
START_DB=$2 database=$2
fi fi
email="info@$domain"; email="info@$domain";
@ -25,6 +21,27 @@ if [ $# -gt 2 ]; then
email=$3 email=$3
fi fi
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
if [ -z "$user" ]; then
check_result $E_NOTEXIST "domain $domain doesn't exist"
fi
# Importing system environment
source /etc/profile
# Includes
source /usr/local/vesta/func/main.sh
source /usr/local/vesta/func/db.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'DOMAIN [DB_NAME] [EMAIL]'
is_format_valid 'domain' 'database' 'email'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ ! -d "/home/$user" ]; then if [ ! -d "/home/$user" ]; then
echo "User doesn't exist"; echo "User doesn't exist";
exit 1; exit 1;
@ -35,15 +52,20 @@ if [ ! -d "/home/$user/web/$domain/public_html" ]; then
exit 1; exit 1;
fi fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
PROTOCOL='http' PROTOCOL='http'
if [ ! -f "/home/$user/conf/web/ssl.$domain.ca" ]; then if [ ! -f "/home/$user/conf/web/ssl.$domain.ca" ]; then
v-add-letsencrypt-domain "$user" "$domain" "www.$domain" "yes" /usr/local/vesta/bin/v-add-letsencrypt-domain "$user" "$domain" "www.$domain" "yes"
fi fi
if [ -f "/home/$user/conf/web/ssl.$domain.ca" ]; then if [ -f "/home/$user/conf/web/ssl.$domain.ca" ]; then
PROTOCOL='https' PROTOCOL='https'
if [ -f "/usr/local/vesta/data/templates/web/nginx/force-https.stpl" ]; then if [ -f "/usr/local/vesta/data/templates/web/nginx/force-https.stpl" ]; then
v-change-web-domain-proxy-tpl "$user" "$domain" "force-https" "jpeg,jpg,png,gif,bmp,ico,svg,tif,tiff,css,js,ttf,otf,webp,txt,csv,rtf,doc,docx,xls,xlsx,ppt,pptx,odf,odp,ods,odt,pdf,psd,ai,eot,eps,ps,zip,tar,tgz,gz,rar,bz2,7z,aac,m4a,mp3,mp4,ogg,wav,wma,3gp,avi,flv,m4v,mkv,mov,mpeg,mpg,wmv,exe,iso,dmg,swf,woff,woff2" "yes" /usr/local/vesta/bin/v-change-web-domain-proxy-tpl "$user" "$domain" "force-https" "jpeg,jpg,png,gif,bmp,ico,svg,tif,tiff,css,js,ttf,otf,webp,txt,csv,rtf,doc,docx,xls,xlsx,ppt,pptx,odf,odp,ods,odt,pdf,psd,ai,eot,eps,ps,zip,tar,tgz,gz,rar,bz2,7z,aac,m4a,mp3,mp4,ogg,wav,wma,3gp,avi,flv,m4v,mkv,mov,mpeg,mpg,wmv,exe,iso,dmg,swf,woff,woff2" "yes"
fi fi
fi fi
@ -51,22 +73,19 @@ WORKINGDIR="/home/$user/web/$domain/public_html"
rm -rf $WORKINGDIR/* rm -rf $WORKINGDIR/*
DBUSERSUF="$START_DB"; DBUSERSUF="$database";
DBUSERSUFB="$START_DB"; DBUSERSUFB="$database";
DBUSER=$user\_$DBUSERSUFB; DBUSER=$user\_$DBUSERSUFB;
DB_OK=0; DB_EXISTS=$(check_if_database_exists "$user" "$DBUSER")
if [ ! -d "/var/lib/mysql/$DBUSER" ]; then
DB_OK=1;
fi
if [ "$DB_OK" -eq "0" ]; then if [ "$DB_EXISTS" = "yes" ]; then
i=1; i=1;
while [ $i -lt 99 ] while [ $i -lt 99 ]; do
do
i=$((i+1)); i=$((i+1));
DBUSERSUF="${DBUSERSUFB}${i}"; DBUSERSUF="${DBUSERSUFB}${i}";
DBUSER=$user\_$DBUSERSUF; DBUSER=$user\_$DBUSERSUF;
if [ ! -d "/var/lib/mysql/$DBUSER" ]; then DB_EXISTS=$(check_if_database_exists "$user" "$DBUSER")
if [ "$DB_EXISTS" = "no" ]; then
break; break;
fi fi
done done
@ -74,9 +93,11 @@ fi
PASSWDDB=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) PASSWDDB=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
v-add-database $user $DBUSERSUF $DBUSERSUF $PASSWDDB mysql #----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
cd /home/$user /usr/local/vesta/bin/v-add-database "$user" "$DBUSERSUF" "$DBUSERSUF" "$PASSWDDB" "mysql"
if [ ! -f "/usr/local/bin/wp" ]; then if [ ! -f "/usr/local/bin/wp" ]; then
echo "=== Downloading latest wp-cli" echo "=== Downloading latest wp-cli"
@ -93,12 +114,8 @@ password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom |
sudo -H -u$user wp core install --url="$domain" --title="$domain" --admin_user="admin" --admin_password="$password" --admin_email="$email" --path=$WORKINGDIR sudo -H -u$user wp core install --url="$domain" --title="$domain" --admin_user="admin" --admin_password="$password" --admin_email="$email" --path=$WORKINGDIR
#FIX za https://github.com/wp-cli/wp-cli/issues/2632
mysql -u$DBUSER -p$PASSWDDB -e "USE $DBUSER; update wp_options set option_value = '$PROTOCOL://$domain' where option_name = 'siteurl'; update wp_options set option_value = '$PROTOCOL://$domain' where option_name = 'home';" mysql -u$DBUSER -p$PASSWDDB -e "USE $DBUSER; update wp_options set option_value = '$PROTOCOL://$domain' where option_name = 'siteurl'; update wp_options set option_value = '$PROTOCOL://$domain' where option_name = 'home';"
# clear
echo "=================================================================" echo "================================================================="
echo "Installation is complete. Your username/password is listed below." echo "Installation is complete. Your username/password is listed below."
echo "" echo ""
@ -112,5 +129,12 @@ echo "================================================================="
chown -R $user:$user $WORKINGDIR chown -R $user:$user $WORKINGDIR
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
echo "v-install-wordpress: Done." echo "v-install-wordpress: Done."
exit 0
log_event "$OK" "$ARGUMENTS"
exit