Created
May 15, 2014 23:12
-
-
Save etcet/b4c2e0a6b74f38a90aa2 to your computer and use it in GitHub Desktop.
Create new account with WordPress installed on cPanel server
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 | |
user_domain="wordtest.habal.net" | |
user_user="wordtest" | |
user_email="wordtest@etcet.net" | |
user_title="Wordtest" | |
user_admin_user="chris" | |
user_dbname="wordtest_wpdb" | |
user_dbuser="wordtest_wpuser" | |
user_dbprefix="wp_" | |
genpasswd() { | |
local l=$1 | |
[ "$l" == "" ] && l=16 | |
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs | |
} | |
user_admin_password=$(genpasswd) | |
user_dbpass=$(genpasswd) | |
domain=$user_domain | |
user=$user_user | |
pass=$(genpasswd) | |
quota=0 | |
cpmod=x3 | |
ip=n | |
cgi=n | |
frontpage=n | |
maxftp=0 | |
maxsql=1 | |
maxpop=1 | |
maxlst=0 | |
maxsub=0 | |
bwlimit=0 | |
hasshell=0 | |
#owner="n" | |
#plan="default" | |
#maxpark=0 | |
#maxaddon=0 | |
#featurelist="default" | |
#contactemail="wordtest@etcet.net" | |
/usr/local/cpanel/scripts/wwwacct $domain $user $pass $quota $cpmod $ip $cgi $frontpage $maxftp $maxsql $maxpo $maxlst $maxsub $bwlimit $hasshell | |
# $owner $plan $maxpark $maxaddon $featurelist $contactemail | |
mysql -e "create database $user_dbname;" | |
mysql -e "grant all privileges on $user_dbname.* TO '$user_dbuser'@'localhost' identified by '$user_dbpass';" | |
mysql -e "flush privileges;" | |
/usr/local/cpanel/bin/dbmaptool $user_user --type mysql --dbuser '$user_dbuser' --db '$user_dbname' | |
wget -N https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
chmod +x wp-cli.phar | |
mv wp-cli.phar /usr/local/bin/wp | |
rm -f /tmp/wp-cli-cacert.pem | |
public_html="/home/$user/public_html" | |
su - $user -c "wp core download --path=$public_html" | |
su - $user -c "wp core config --path=$public_html --dbname=$user_dbname --dbuser=$user_dbuser --dbpass=$user_dbpass --dbprefix=$user_dbprefix" | |
su - $user -c "wp core install --path=$public_html --url=$user_domain --title=$user_title --admin_user=$user_admin_user --admin_password=$user_admin_password --admin_email=$user_email" | |
HOMEDIR=$(egrep ^${user} /etc/passwd | cut -d: -f6) | |
if [ ! -f /var/cpanel/users/$user ]; then | |
echo "$user user file missing, likely an invalid user" | |
elif [ "$HOMEDIR" == "" ];then | |
echo "Couldn't determine home directory for $user" | |
else | |
echo "Backing up permissions for $user" | |
find $HOMEDIR -printf 'chmod %#m "%p"\n' > /root/$user-perms_backup_`date +%s`.sh | |
echo "Backing up ownerships for $user" | |
find $HOMEDIR -printf 'chown %u:%g "%p"\n' > /root/$user-owners_backup_`date +%s`.sh | |
echo "Setting ownership for user $user" | |
chown -R $user:$user $HOMEDIR | |
chmod 711 $HOMEDIR | |
chown $user:nobody $HOMEDIR/public_html $HOMEDIR/.htpasswds | |
chown $user:mail $HOMEDIR/etc $HOMEDIR/etc/*/shadow $HOMEDIR/etc/*/passwd | |
echo "Setting permissions for user $user" | |
find $HOMEDIR -type f -exec chmod 644 {} \; | |
find $HOMEDIR -type d -exec chmod 755 {} \; | |
find $HOMEDIR -type d -name cgi-bin -exec chmod 755 {} \; | |
find $HOMEDIR -type f \( -name "*.pl" -o -name "*.perl" -o -name "*.cgi" \) -exec chmod 755 {} \; | |
fi | |
echo | |
echo "http://$domain/wp-admin/" | |
echo "User: $user_admin_user" | |
echo "Pass: $user_admin_password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment