-
-
Save samface/5583768 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Exit this bash script if any statement returns a non-true return value (same as: set -e) | |
set -o errexit | |
if [ -z "$1" ]; then | |
echo | |
echo "ERROR: Must pass parameter of absolute or relative path to directory where Wordpress is to be installed." | |
echo "USAGE: $0 path/to/public/html/dir" | |
echo | |
exit 1 | |
fi | |
WP_TARGET_DIR=$(echo "$1"|sed 's/\/$//g') | |
WP_LANG="sv_SE" | |
WP_DOMAIN="sv.wordpress.org" | |
WP_FILE_VER=$(curl -s http://api.wordpress.org/core/version-check/1.5/ | head -n 4 | tail -n 1) | |
WP_FILE_EXT="tar.gz" | |
WP_FILE_NAME="wordpress-$WP_FILE_VER-$WP_LANG.$WP_FILE_EXT" | |
WP_FILE_URL="http://$WP_DOMAIN/$WP_FILE_NAME" | |
printf "PLEASE NOTE: This will install Wordpress $WP_FILE_VER in $WP_TARGET_DIR\n" | |
printf "Database Name (will be created if not exists): " | |
read -e dbname | |
printf "Database User (will be created if not exists): " | |
read -e dbuser | |
printf "Database Password: " | |
read -s dbpass | |
printf "\nReady to run install? (y/n)" | |
read -e run | |
if [ "$run" == n ] ; then | |
exit | |
else | |
#create mysql user and database | |
MYSQL=`which mysql` | |
Q1="CREATE DATABASE IF NOT EXISTS $dbname;" | |
Q2="GRANT ALL ON $dbname.* TO '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';" | |
Q3="FLUSH PRIVILEGES;" | |
SQL="${Q1}${Q2}${Q3}" | |
printf "Configuring database, this will require the root password...\n" | |
$MYSQL -uroot -p -e "$SQL" | |
#download wordpress | |
curl -O "$WP_FILE_URL" | |
#unzip wordpress | |
tar -zxvf "$WP_FILE_NAME" | |
#copy files to target dir | |
cp -rf wordpress/* $WP_TARGET_DIR/ | |
#remove files from wordpress folder | |
rm -R wordpress | |
#create wp config | |
cp $WP_TARGET_DIR/wp-config-sample.php $WP_TARGET_DIR/../wp-config.php | |
#set database details with perl find and replace | |
sed -i -e "s/'DB_NAME', '[^']*'/'DB_NAME', '$dbname'/g" $WP_TARGET_DIR/../wp-config.php | |
sed -i -e "s/'DB_USER', '[^']*'/'DB_USER', '$dbuser'/g" $WP_TARGET_DIR/../wp-config.php | |
sed -i -e "s/'DB_PASSWORD', '[^']*'/'DB_PASSWORD', '$dbpass'/g" $WP_TARGET_DIR/../wp-config.php | |
#Make sure the angrycreative user is a member of www-data | |
usermod -a -G www-data angrycreative | |
#set default permissions | |
find $WP_TARGET_DIR/ -type d -exec chmod 755 {} \; | |
find $WP_TARGET_DIR/ -type f -exec chmod 644 {} \; | |
#set install and upgrade permissions on the wp-content directory | |
chgrp -R www-data $WP_TARGET_DIR/wp-content | |
chmod -R g+w $WP_TARGET_DIR/wp-content | |
chmod g+s $WP_TARGET_DIR/wp-content | |
#force direct file installing/updating | |
echo -e "\n\ndefine('FS_METHOD', 'direct');" >> $WP_TARGET_DIR/../wp-config.php | |
#added to be enabled in production environment | |
echo -e "\n\n//define('DISALLOW_FILE_MODS', true);" >> $WP_TARGET_DIR/../wp-config.php | |
#create uploads folder and set permissions | |
mkdir $WP_TARGET_DIR/wp-content/uploads | |
chmod -R g+w $WP_TARGET_DIR/wp-content/uploads | |
#remove zip file | |
rm "$WP_FILE_NAME" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment