بایگانی

خودکارسازی نصب وردپرس با پلسک

/bin/date >> /tmp/event_handler.log # information on the event date and time

/usr/bin/id >> /tmp/event_handler.log # information on the user, on behalf of which the script was executed (to ensure control)

#we need random string generators. One simple for logins, and the other is more complex for secure passwords.

genpass_alphanum() {

 local l=$1

 [ “$l” == “” ] && l=16

 tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs

}

genpass() {

 local l=$1

 [ “$l” == “” ] && l=16

 tr -dc A-Za-z0-9_!@#$%^&*?< /dev/urandom | head -c ${l} | xargs

}

#We want to make we provide the latest WordPress version. See http://docs.plesk.com/en-US/12.5/cli-linux/using-command-line-utilities/aps-application-catalog.63094/ for more details on “plesk bin aps” functionality

VER_RAW=(plesk bin aps -gp|grep WordPress -A2 -B1|grep -v Vendor|awk '{print $2}')

VER_LEN=${#VER_RAW[*]}

VER=()

for i in {0,$((VER_LEN/3)),1}; do VER=(${VER[@]} ${VER_RAW[$((i*3-1))]}); done

IFS=$’n’ sorted=($(sort <<<“${VER[*]}”))

LVC=${#sorted[*]}

LATEST_VER=${sorted[$((LVC-1))]}

echo latest version is $LATEST_VER >>/tmp/event_handler.log

LATEST_PACKAGE_ID=plesk bin aps -gp|grep $LATEST_VER -B3|head -1|awk '{print $2}'

echo latest package id is $LATEST_PACKAGE_ID >>/tmp/event_handler.log

echo “domain ${NEW_DOMAIN_NAME}” >> /tmp/event_handler.log

# Find out plan name on which domain is created – see http://docs.plesk.com/en-US/12.5/cli-linux/using-command-line-utilities/site-sites.67067/ for reference

PLAN=plesk bin site -i "${NEW_DOMAIN_NAME}"|grep -i plan|awk -F" '{ print $2 }'

echo $PLAN >> /tmp/event_handler.log

#if plan is right, we are installing WP, and for this we need to extract user name and email from domain owner, in order to provide WP with the same data, without having to make user correct it later

if [ “$PLAN” == “$TARGET_PLAN” ]; then

echo “${NEW_DOMAIN_NAME} is eligible for WP installation” >> /tmp/event_handler.log

USER=plesk bin domain -i $NEW_DOMAIN_NAME|grep Owner|awk -F( '{print $2}'|awk -F) '{print $1}'

EMAIL=plesk bin user -i $USER|grep mail|awk '{print $2}'

echo $USER $EMAIL >> /tmp/event_handler.log

#Generating password, login, database name and database user name

echo “installing WordPress version $LATEST_VER package ID $LATEST_PACKAGE_ID for domain ${NEW_DOMAIN_NAME}” >> /tmp/event_handler.log

echo “generating secure password” >> /tmp/event_handler.log

PASSWD=genpass 8_

#echo “Password $PASSWD” >> /tmp/event_handler.log

echo “generating db name and db user name” >> /tmp/event_handler.log

DBUSER=admin_genpass_alphanum 6

echo “DB User $DBUSER” >> /tmp/event_handler.log

DBNAME=wp_genpass_alphanum 6

echo “DB Name $DBNAME” >> /tmp/event_handler.log

# We need to generate an XML template for Plesk to provide an APS package. Each APS package has its own requirements to the template. In WP template we need to put user name, email address, password and locale – all this information will be used in WordPress instance. User can edit it later.

echo “Generating template for WP” >> /tmp/event_handler.log

echo “

 

 admin_email

 $EMAIL

 

 

 admin_name

 $NEW_SYSTEM_USER

 

 

 admin_password

 $PASSWD

 

 

 locale

 en-US

 

 

 title

 WordPress

 

” > /tmp/template1.xml

#now ready to install WordPress instance. First let’s log command to execute

echo “plesk bin aps –install “/tmp/template1.xml” -package-id $LATEST_PACKAGE_ID -domain ${NEW_DOMAIN_NAME} -ssl false -url-prefix wordpress -db-name $DBNAME -db-user $DBUSER -passwd ”$PASSWD” ” >> /tmp/event_handler.log

#and fire it for real

plesk bin aps –install “/tmp/template1.xml” -package-id $LATEST_PACKAGE_ID -domain ${NEW_DOMAIN_NAME} -ssl false -url-prefix wordpress -db-name $DBNAME -db-user $DBUSER -passwd “$PASSWD” >> /tmp/event_handler.log 2>&1

#you might want to remove logging in the above line, as APS package installation produces a lot of output.

echo “Finished installing WordPress for domain ${NEW_DOMAIN_NAME}” >> /tmp/event_handler.log

echo “Notifying user of successful installation” >> /tmp/event_handler.log

#Optional email notification sent out to the domain owner. Make sure your Plesk has correct FQDN and DNS is setup properly.

mail -s “Your WordPress is ready” “$EMAIL” <

Hello, $USER.

Your WordPress installation is ready.

To access it, open ${NEW_DOMAIN_NAME}/wordpress

Login: $NEW_SYSTEM_USER

Password: $PASSWD

EOF

rm /tmp/template1.xml –f

#If plan name is not our target plan, skipping the installation

else echo  “${NEW_DOMAIN_NAME} does not need WP installation” >> /tmp/event_handler.log

fi

echo “————–” >> /tmp/event_handler.log

در صورت نیاز به سرور و خدمات مدیریت آن با ما در تماس باشید

۰۲۱۲۸۴۲۱۱۹۳
۰۹۱۲۹۷۲۶۳۴۳
۰۹۳۶۲۱۹۶۳۴۳
@omidahmadyani
@omid_ahmadyani