Created
October 20, 2011 04:59
-
-
Save davidchua/1300457 to your computer and use it in GitHub Desktop.
This code snipplet was originally from: http://www.debian-tutorials.com/bash-2-/bah-script-installupgrade-wordpress
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 | |
# | |
# Homepage: http://www.debian-tutorials.com | |
# Email: contact@debian-tutorials.com | |
# Bash script to download and install or upgrade wordpress to specified directory. | |
install_wp () | |
{ | |
cd ~</pre> | |
<!--more--> | |
<pre> | |
mkdir wordpress | |
cd wordpress | |
wget https://wordpress.org/latest.tar.gz --no-check-certificate; | |
echo "Where would you like your new WordPress install to be located? Please Type the location(Eg:/var/www/) and press [ENTER]: " | |
read wordpress_dir | |
echo "Installing WordPress to $wordpress_dir"; | |
if [ ! -d "$wordpress_dir" ]; then | |
mkdir $wordpress_dir | |
fi | |
tar -zxvf latest.tar.gz -C $wordpress_dir | |
} | |
clean_up () | |
{ | |
cd ~/wordpress | |
rm latest.tar.gz | |
cd ~ | |
rmdir wordpress | |
cd $wordpress_dir/wordpress | |
mv *.* $wordpress_dir | |
mv wp-admin $wordpress_dir | |
mv wp-content $wordpress_dir | |
mv wp-includes $wordpress_dir/ | |
rmdir $wordpress_dir/wordpress | |
cd $wordpress_dir/wp-content | |
mkdir uploads | |
chmod 777 uploads -R | |
cd $wordpress_dir | |
touch $wordpress_dir/.htaccess | |
chmod -v 666 .htaccess | |
echo "Wordpress is now Installed to" . $wordpress_dir . "Enjoy!" | |
} | |
update_wp () | |
{ | |
day=`date +%Y_%m_%d` | |
cd ~ | |
mkdir wordpress_tmp | |
cd wordpress_tmp | |
wget https://wordpress.org/latest.tar.gz --no-check-certificate; | |
echo "In what directory does WordPress already exist, that you would like updated? Please Type the location(Eg:/var/www/) and press [ENTER]: " | |
read update_dir | |
tar -zxvf latest.tar.gz -C $update_dir | |
cd ~/wordpress_tmp | |
rm latest.tar.gz | |
cd ~ | |
rmdir wordpress_tmp | |
cd $update_dir | |
cp $update_dir/ $update_dir/../wordpress_backup_$day -R | |
cp $update_dir/../wordpress_backup_$day/wp-config.php $update_dir | |
# Go to backup directory and remove the new install of WP | |
cd $update_dir/../wordpress_backup_$day | |
rm wordpress -rf | |
# back to the update directory | |
cd $update_dir/wordpress | |
#remove wp-admin and wp-includes | |
cd $update_dir | |
rm wp-admin -rf | |
rm wp-includes -rf | |
cd $update_dir/wordpress | |
mv wp-admin $update_dir | |
mv wp-includes $update_dir | |
#remove the extra updated directoroies | |
rm $update_dir/wordpress/ -rf | |
echo "Upgrade complete! Backup can be found in $update_dir/../$update_dir_backup_$day" | |
} | |
if ["$(id -u)" = "0"]; then { | |
echo "You are root we will continue" 2>&1 | |
install_wp | |
clean_up | |
exit | |
} | |
else | |
{ | |
read -p "If the location you want to install wordpress to requires Root access, Please press 'N' and run this script again as root, or 'Y' to run the script without root (y/n)? " | |
[ "$REPLY" == "n" ] & exit || | |
[ "$REPLY" == "y" ] & | |
echo "Do you wish to install WordPress [Yes] or update [No]? Type 1 or 2 and press [ENTER]" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) install_wp && clean_up && break;; | |
No ) update_wp && break;; | |
esac | |
done | |
} | |
fi | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment