Memo : Installation automatique de wordpress + FTP + mysql sous linux ubuntu

Voici un script d’installation automatique de wordpress, avec création d’un ftp et d’une base de données.

Définissez :
$MYSQL_USER
$MYSQL_PASSWORD

Dépéndance :
apg

display_usage() {
    echo "This script must be run with super-user privileges."
    echo "You have to choose a username"
    echo  "\nUsage:\n$0 [USERNAME] \n"
}
if [ $# -le 0 ]
then
        display_usage
        exit 1
fi

if [[ $USER != "root" ]]; then
        display_usage
        exit 1
fi

pass=`apg -n 1 -q` # generation de mot de passe automatique
username='wp-'$1   # on concatene le username avec wp histoire de reconnaitre les comptes générés par le script
adduser $username --ingroup clientsftp --home /var/www/$username/ --shell /bin/false  --disabled-password --quiet --gecos "" # ajout de user sans prompt
adduser $username www-data 
echo "$username:$pass" | chpasswd # on change le mot de passe utilisateur wordpress
cat  /etc/apache2/sites-available/wordpress | sed -e"s/USR/$username/g" > /etc/apache2/sites-available/$username.conf
a2ensite $username.conf # on copie et active une conf wordpress de base ou 
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE USER '${username}'@'localhost' IDENTIFIED BY  '$pass'; GRANT USAGE ON * . * TO  '${username}'@'localhost' IDENTIFIED BY  '$pass' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; CREATE DATABASE IF NOT EXISTS  \`${username}\` ; GRANT ALL PRIVILEGES ON  \`${username}\` . * TO  '${username}'@'localhost';" # creation de la db mysql wordpress et du user mysql wordpress
cd /var/www/$username  
wget  http://wordpress.org/latest.tar.gz # telechargement de la derniere archive wordpress
tar -xvf latest.tar.gz # decompression de la derniere archive wordpress
rm latest.tar.gz
chown -R www-data:www-data wordpress
chmod -R 0775 wordpress
/etc/init.d/apache2 reload
echo "\n\nInfo\n"
echo "URL http://$username.mutu6.gaboweb.net/wp-admin/"
echo "Login $username"
echo "Pass $pass"

Le contenu de /etc/apache2/sites-availabled/wordpress

<VirtualHost *:80>

  ServerName USR.myzone.gaboweb.net
  DocumentRoot /var/www/USR/wordpress/
  ErrorLog /var/www/USR/wordpress/error.log
  CustomLog /var/www/USR/wordpress/access.log combined
</VirtualHost>