Last active
December 24, 2015 11:09
-
-
Save karellm/6788910 to your computer and use it in GitHub Desktop.
Wordpress bootstrap script
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 | |
# 1/ HERE I WANT MY WP-CONFIG.PHP TO BE OVERWRITTEN IF IT EXISTS, | |
# SO I CHANGED THE TEST FOR THE PWD FILE | |
if [ ! -f /mysql-root-pw.txt ]; then | |
#let's create a user to ssh into | |
SSH_USERPASS=`pwgen -c -n -1 8` | |
mkdir /home/user | |
useradd -G sudo -d /home/user user | |
chown user /home/user | |
echo user:$SSH_USERPASS | chpasswd | |
echo ssh user password: $SSH_USERPASS | |
# 2/ WORDPRESS NEED mod_rewrite | |
# I enable it and update the default vhost to set AllowOverride in /var/www. | |
a2enmod rewrite | |
sed -i '\#<Directory /var/www/>#,\#</Directory># s|\(AllowOverride\) None|\1 All|' /etc/apache2/sites-available/default | |
#mysql has to be started this way as it doesn't work to call from /etc/init.d | |
/usr/bin/mysqld_safe & | |
sleep 10s | |
WORDPRESS_DB="wordpress" | |
WORDPRESS_PASSWORD=`pwgen -c -n -1 12` | |
MYSQL_PASSWORD=`pwgen -c -n -1 12` | |
echo wordpress password: $WORDPRESS_PASSWORD | |
echo $WORDPRESS_PASSWORD > /mysql-wordpress-pw.txt | |
echo mysql root password: $MYSQL_PASSWORD | |
echo $MYSQL_PASSWORD > /mysql-root-pw.txt | |
sed -e "s/database_name_here/$WORDPRESS_DB/ | |
s/username_here/$WORDPRESS_DB/ | |
s/password_here/$WORDPRESS_PASSWORD/ | |
/'AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'SECURE_AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'LOGGED_IN_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'NONCE_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'SECURE_AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'LOGGED_IN_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ | |
/'NONCE_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/" /var/www/wp-config-sample.php > /var/www/wp-config.php | |
# 3/ I remove this line I guess the mount -v option made it crash | |
# chown www-data:www-data /var/www/wp-config.php | |
mysqladmin -u root password $MYSQL_PASSWORD | |
mysql -uroot -p$MYSQL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$WORDPRESS_PASSWORD'; FLUSH PRIVILEGES;" | |
# 4/ I also mount some .sql files if the project already exists | |
# that way I can pre populate the db | |
mysql -uroot -p$MYSQL_PASSWORD wordpress < /database/development.sql | |
killall mysqld | |
sleep 10s | |
fi | |
supervisord -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment