mirror of
https://github.com/myvesta/vesta.git
synced 2024-11-20 20:40:08 -08:00
171 lines
6.0 KiB
Bash
171 lines
6.0 KiB
Bash
#!/bin/bash
|
|
# info: WordPress installer in one command line
|
|
# options: DOMAIN [DB_NAME] [EMAIL]
|
|
#
|
|
# Credits to Luka Paunović for wp-cli implememtation
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
whoami=$(whoami)
|
|
if [ "$whoami" != "root" ]; then
|
|
echo "You must be root to execute this script"
|
|
exit 1
|
|
fi
|
|
|
|
# Importing system environment
|
|
source /etc/profile
|
|
|
|
# Argument definition
|
|
domain=$1
|
|
|
|
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
|
|
USER=$user
|
|
|
|
# Includes
|
|
source /usr/local/vesta/func/main.sh
|
|
source /usr/local/vesta/func/db.sh
|
|
source /usr/local/vesta/conf/vesta.conf
|
|
|
|
if [ -z "$user" ]; then
|
|
check_result $E_NOTEXIST "domain $domain doesn't exist"
|
|
fi
|
|
|
|
if [[ $(is_package_full 'DATABASES') = *reached* ]]; then
|
|
echo "Database limit is reached. Delete database or upgrade user package."
|
|
exit
|
|
fi
|
|
|
|
#----------------------------------------------------------#
|
|
# 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"
|
|
|
|
# take --parameters
|
|
source /usr/local/vesta/func/handle_parameters.sh
|
|
|
|
if [ -z "$database" ]; then
|
|
if [ ! -z "$MAX_DBUSER_LEN" ] && [ "$MAX_DBUSER_LEN" -ge 80 ]; then
|
|
database=$(echo "$domain" | sed 's#\.#_#g')
|
|
else
|
|
database="wp"
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$email" ]; then
|
|
email="info@$domain";
|
|
fi
|
|
|
|
if [ ! -d "/home/$user" ]; then
|
|
echo "User doesn't exist";
|
|
exit 1;
|
|
fi
|
|
|
|
if [ ! -d "/home/$user/web/$domain/public_html" ]; then
|
|
echo "Domain doesn't exist";
|
|
exit 1;
|
|
fi
|
|
|
|
DBUSERSUF="$database";
|
|
DBUSERSUFB="$database";
|
|
DBUSER=$user\_$DBUSERSUFB;
|
|
DB_EXISTS=$(check_if_database_exists "$user" "$DBUSER")
|
|
|
|
if [ "$DB_EXISTS" = "yes" ]; then
|
|
i=1;
|
|
while [ $i -lt 99 ]; do
|
|
i=$((i+1));
|
|
DBUSERSUF="${DBUSERSUFB}${i}";
|
|
DBUSER=$user\_$DBUSERSUF;
|
|
DB_EXISTS=$(check_if_database_exists "$user" "$DBUSER")
|
|
if [ "$DB_EXISTS" = "no" ]; then
|
|
break;
|
|
fi
|
|
done
|
|
fi
|
|
|
|
PASSWDDB=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
PROTOCOL='http'
|
|
if [ -z "$SKIP_LE" ]; then
|
|
if [ ! -f "/home/$user/conf/web/ssl.$domain.ca" ]; then
|
|
/usr/local/vesta/bin/v-add-letsencrypt-domain "$user" "$domain" "www.$domain" "yes"
|
|
fi
|
|
else
|
|
PROTOCOL='https'
|
|
fi
|
|
|
|
TPL_CHANGED=0;
|
|
|
|
if [ -f "/home/$user/conf/web/ssl.$domain.ca" ] || [ ! -z "$SKIP_LE" ]; then
|
|
PROTOCOL='https'
|
|
if [ -f "/usr/local/vesta/data/templates/web/nginx/force-https-firewall-wordpress.stpl" ] && [ $TPL_CHANGED -eq 0 ]; then
|
|
TPL_CHANGED=1;
|
|
/usr/local/vesta/bin/v-change-web-domain-proxy-tpl "$user" "$domain" "force-https-firewall-wordpress" "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
|
|
if [ -f "/usr/local/vesta/data/templates/web/nginx/force-https.stpl" ] && [ $TPL_CHANGED -eq 0 ]; then
|
|
TPL_CHANGED=1;
|
|
/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
|
|
else
|
|
if [ -f "/usr/local/vesta/data/templates/web/nginx/hosting-firewall-wordpress.stpl" ] && [ $TPL_CHANGED -eq 0 ]; then
|
|
TPL_CHANGED=1;
|
|
/usr/local/vesta/bin/v-change-web-domain-proxy-tpl "$user" "$domain" "hosting-firewall-wordpress" "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
|
|
|
|
/usr/local/vesta/bin/v-add-database "$user" "$DBUSERSUF" "$DBUSERSUF" "$PASSWDDB" "mysql"
|
|
|
|
if [ ! -f "/usr/local/bin/wp" ]; then
|
|
echo "=== Downloading latest wp-cli"
|
|
wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp
|
|
chmod +x /usr/local/bin/wp
|
|
fi
|
|
|
|
WORKINGDIR="/home/$user/web/$domain/public_html"
|
|
rm -rf $WORKINGDIR/*
|
|
cd $WORKINGDIR
|
|
|
|
sudo -H -u$user wp core download
|
|
sudo -H -u$user wp core config --dbname=$DBUSER --dbuser=$DBUSER --dbpass=$PASSWDDB
|
|
|
|
password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
|
|
|
|
wpadmin=$(echo "$domain" | sed 's#\.#_#g')_4dm1n
|
|
|
|
sudo -H -u$user wp core install --url="$domain" --title="$domain" --admin_user="$wpadmin" --admin_password="$password" --admin_email="$email" --path=$WORKINGDIR
|
|
|
|
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';"
|
|
|
|
echo "================================================================="
|
|
echo "Installation is complete. Your username/password is listed below."
|
|
echo ""
|
|
echo "Site: $PROTOCOL://$domain/"
|
|
echo ""
|
|
echo "Login: $PROTOCOL://$domain/wp-admin/"
|
|
echo "Username: $wpadmin"
|
|
echo "Password: $password"
|
|
echo ""
|
|
echo "================================================================="
|
|
|
|
chown -R $user:$user $WORKINGDIR
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
echo "v-install-wordpress: Done."
|
|
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|