Last active
March 1, 2024 17:27
-
-
Save maagmirror/99015f9acf47f381038940000273f818 to your computer and use it in GitHub Desktop.
Script to install a wordpress in vesta server with changes in database name generator, add the essential plugins, generate good link structure for seo, change lang of the core to spanish, remove unused base themes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# info: WordPress installer in one command line | |
# options: DOMAIN USER | |
# | |
# Credits to Luka Paunović for wp-cli implememtation | |
#----------------------------------------------------------# | |
# Variable&Function # | |
#----------------------------------------------------------# | |
password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12) | |
adminname=admin | |
whoami=$(whoami) | |
if [ "$whoami" != "root" ]; then | |
echo "You must be root to execute this script" | |
exit 1 | |
fi | |
# Argument definition | |
domain=$1 | |
#remove dots on the string / domain | |
databasename=${domain//[-._]/} | |
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" | |
# take --parameters | |
source /usr/local/vesta/func/handle_parameters.sh | |
if [ -z "$database" ]; then | |
database="$databasename" | |
# database="wp" | |
fi | |
if [ -z "$emil" ]; 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 | |
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.stpl" ]; then | |
/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 | |
/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 | |
sudo -H -u$user wp core install --url="$domain" --title="$domain" --admin_user="$adminname" --admin_password="$password" --admin_email="$email" --path=$WORKINGDIR | |
#remove default themes | |
sudo -H -u$user wp theme delete twentynineteen | |
sudo -H -u$user wp theme delete twentytwenty | |
sudo -H -u$user wp theme delete twentytwentyone | |
#install astra as default | |
sudo -H -u$user wp theme install astra --activate | |
#tip, if u want to add more plugins preinstalled, add the SLUG of the plugin NOT THE NAME | |
#----------------------------------------------------------# | |
# Begin install plugins # | |
#----------------------------------------------------------# | |
#install woocommerce | |
sudo -H -u$user wp plugin install woocommerce --activate | |
#install Yoast SEO | |
sudo -H -u$user wp plugin install seo-by-rank-math --activate | |
#install Elementor | |
#sudo -H -u$user wp plugin install elementor --activate | |
#install Woocommerce MercadoPago | |
sudo -H -u$user wp plugin install woocommerce-mercadopago --activate | |
#install Classic Widgets | |
#sudo -H -u$user wp plugin install classic-widgets --activate | |
#install Restore Smart-slider-3 | |
sudo -H -u$user wp plugin install smart-slider-3 --activate | |
#install Restore contact-form-7 | |
sudo -H -u$user wp plugin install contact-form-7 --activate | |
#install Essential addons for elementor | |
#sudo -H -u$user wp plugin install essential-addons-for-elementor-lite --activate | |
#----------------------------------------------------------# | |
# Set lang to Spanish # | |
#----------------------------------------------------------# | |
#change site lang to spanish | |
sudo -H -u$user wp language core install es_ES --activate | |
#change the structure of urls | |
sudo -H -u$user wp option get permalink_structure | |
sudo -H -u$user wp option update permalink_structure '/%postname%/' | |
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: $adminname" | |
echo "Password: $password" | |
echo "Database Name: $databasename" | |
echo "" | |
echo "=================================================================" | |
chown -R $user:$user $WORKINGDIR | |
#----------------------------------------------------------# | |
# Vesta # | |
#----------------------------------------------------------# | |
echo "v-install-wordpress-nibiru: Done." | |
log_event "$OK" "$ARGUMENTS" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment