added wordpress automation script
[SimpleScripts.git] / wp-all
blob8819205b882efeb002163b35d0fe0d52ebbcf2a6
1 #!/bin/bash
2 ##
3 ## wp-new.sh
4 ## Login : <plovs@s1lver>
5 ## Started on Sat Apr 25 14:49:45 2009 Alexander Poslavsy
6 ## Time-stamp: <Last changed 11-05-2009 15:49:21 by Alexander Poslavsy, plovs>
7 ##
8 ## Copyright (C) 2009 Alexander Poslavsy
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
13 ##
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
18 ##
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 WWDIR="/home/www/httpdoc"
25 WPDIR="/home/plovs/Build/WP"
26 OWNER="plovs:www-data"
27 SQLUSER="root"
28 SQLPWD="changeme"
29 NEEDSUDO="yes"
31 plugins=( google-sitemap-generator.3.1.2.zip all-in-one-seo-pack.zip wp-security-scan.2.4.zip akismet.zip maintenance-mode.4.3.zip )
32 themes=( iblog.1.0.7.zip threattocreativity.1.6.zip)
34 VERBOSE=""
36 CFG="$HOME/.wp-buildrc"
37 [ -f "$CFG" ] && source "$CFG"
39 function checksudo() {
40 if [ $NEEDSUDO -a $UID -ne 0 ]; then
41 echo "Use sudo!"
42 exit 1
46 function error() {
47 echo "$1"
48 exit 1
51 function usage() {
52 cat<<EOF
53 1. Wordpress installer on local machine
54 2. Install themes or plugins in a wordpress install, use -t or -p
56 Usage: $(basename $0) -s <sitename> (-w) list of plugins/themes to install
57 Usage: $(basename $0) -s <sitename> (-d) (-f) (re-)install/remove site
58 -h this help
59 -v verbose
60 -l list all wp instances
62 -b backup site -s <sitename>
64 -s sitename, always needed!
65 -w download latest version of everyting
67 -t install theme(s)
68 -p install plugin(s)
70 -d delete previous version of the wp install
71 -f force, asume yes on all overwrites
73 -r really, completely wipe away wp install
74 you need -f as well, just to make sure
75 EOF
76 exit 0
79 function install() {
80 [ "$VERBOSE" ] && echo "Installing $1 $3 in $2"
81 PKG=$(basename $3)
82 [ -f "$WPDIR/$1/$PKG" ] || error "$PKG does not exist"
83 sudo unzip -q -o -d "$WWDIR/$2/wp-content/$1" "$WPDIR/$1/$PKG"
84 sudo chown $OWNER "$WWDIR"
87 function dload() {
88 [ "$VERBOSE" ] && echo "* Downloading latest versions of wordpress and plugins..."
89 cd "$WPDIR"
90 [ -f "latest.tar.gz" ] && mv latest.tar.gz latest_$(date +%F).tar.gz
91 wget http://wordpress.org/latest.tar.gz
92 cd "$WPDIR/plugins"
93 wget http://downloads.wordpress.org/plugin/wp-security-scan.2.4.zip
94 wget http://downloads.wordpress.org/plugin/google-sitemap-generator.3.1.2.zip
95 wget http://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip
96 wget http://downloads.wordpress.org/plugin/akismet.zip
97 wget http://downloads.wordpress.org/plugin/maintenance-mode.4.3.zip
100 function killsite() {
101 [ "$FORCE" ] || error "To kill a site (-k) also use force (-f), just to make sure"
103 [ "$VERBOSE" ] && echo "* Killing $SITENAME:"
104 DELETE="-d"
105 sqldrop
106 rm -rf "$SITE"
107 exit 0
110 function sqldrop() {
111 [ "$VERBOSE" ] && echo "* Dropping $USER database"
112 if [ "$DELETE" ];then
113 cat>$TMPFILE<<EOF
114 DROP USER '$USER'@'localhost';
115 DROP DATABASE IF EXISTS \`$USER\` ;
117 mysql -u$SQLUSER -p$SQLPWD < "$TMPFILE"
118 rm "$TMPFILE"
122 function sqlnew() {
123 [ "$VERBOSE" ] && echo "* New $USER database"
124 cat>$TMPFILE<<EOF
125 CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PWORD';
127 GRANT USAGE ON * . * TO '$USER'@'localhost' IDENTIFIED BY '$PWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
129 CREATE DATABASE IF NOT EXISTS \`$USER\` ;
130 GRANT ALL PRIVILEGES ON \`$USER\` . * TO '$USER'@'localhost';
133 mysql -u$SQLUSER -p$SQLPWD < "$TMPFILE"
134 rm "$TMPFILE"
136 [ "$VERBOSE" ] && echo "* Database: $USER@localhost"
137 [ "$VERBOSE" ] && echo "* Password: $PWORD"
140 function newgit() {
141 [ "$VERBOSE" ] && echo "* Adding $SITENAME to git"
142 cd "$SITE"
143 git init
144 git add .
145 git commit -a -m "Initial commit, from $0"
148 function buildsite() {
149 [ -e "$WPDIR/wordpress-latest.tar.gz" ] || error "Missing $WPDIR/wordpress-latest.tar.gz"
150 SITE="$WWDIR/$SITENAME"
152 if [ -d "$SITE" ]; then
153 if [ "$FORCE" ]; then
154 if [ "$DELETE" ]; then
155 echo "* Removing old $SITE"
156 rm -rf "$SITE"
157 else
158 echo "* Overwriting existing $SITE"
160 else
161 error "$SITE exists! Use -f to override, the old site will be overwritten, use -d to remove the old site"
165 echo "* Building site: $SITE ($SITENAME)"
166 cd "$WWDIR"
167 tar xzf "$WPDIR/wordpress-latest.tar.gz"
168 mv wordpress "$SITENAME"
170 USER=$(echo "$SITENAME" | sed -e "s/\.ap//" -e "s/\.//")
171 PWORD="$USER"111
173 [ "$KILLSITE" ] && killsite
174 [ "$DELETE" ] && sqldrop
175 sqlnew
178 function listsites() {
179 cd "$WWDIR"
181 exit
184 function removesite() {
185 [ "$FORCE" ] || error "You need to use -f to remove a site"
186 USER=$(echo "$SITENAME" | sed -e "s/\.ap//" -e "s/\.//")
187 PWORD="$USER"111
189 killsite
190 sqldrop
191 exit 0
194 function backupsite() {
195 error "backupsite not implemented yet"
196 # mysqldump wordpress –add-drop-table -h localhost -u wpdbuser -pyourpasswd | gzip > db.$DATE.gz
197 # DATE=`date | tr ” ” _`
198 # echo $DATE
199 # tar cvfz code.$DATE.gz
200 exit 0
203 while getopts "bdfghklprs:tvw" Option; do
204 case $Option in
205 b) BACKUP="-y";;
206 d) DELETE="-y";;
207 f) FORCE="-t";;
208 g) GIT="-g";;
209 h) usage;;
210 k) KILLSITE="-k";;
211 l) listsites;;
212 r) REMOVESITE="-y";;
213 s) SITENAME=$OPTARG;;
214 t) TYPE="themes";;
215 p) TYPE="plugins";;
216 v) VERBOSE="-v";;
217 w) WEB="-w";;
218 esac
219 done
220 shift $(( OPTIND - 1 ))
221 OPTIND=1
223 if [ ! "$TYPE" -o "$SITENAME" ];then
224 usage
226 checksudo
228 [ "$REMOVESITE" ] && removesite
229 [ "$BACKUP" ] && backupsite
230 [ "$WEB" ] && dload
231 TMPFILE=$(mktemp) || error "Problem creating tempfile"
233 if [ "$TYPE" ]; then
234 ALLTYPES=$@
235 [ "$ALLTYPES" ] || error "Maybe add some $TYPE?"
236 for name in $ALLTYPES; do
237 install "$TYPE" "$SITENAME" "$name"
238 done
239 else
240 buildsite
241 cd "$WWDIR/$SITENAME/wp-content/"
242 for name in ${plugins[@]}
244 install "plugins" "$SITENAME" "$name"
245 done
247 for name in ${themes[@]}
249 install "themes" "$SITENAME" "$name"
250 done
252 chown -R $OWNER "$WWDIR"
253 find "$WWDIR" -type d | sudo xargs chmod g+wx
255 cd "$WWDIR/$SITENAME"
256 WRKFILE="wp-config.php"
257 mv wp-config-sample.php $WRKFILE
258 sed -i "s/putyourdbnamehere/$USER/" $WRKFILE
259 sed -i "s/usernamehere/$USER/" $WRKFILE
260 sed -i "s/yourpasswordhere/$PWORD/" $WRKFILE
262 [ "$GIT" ] && newgit
266 exit 0