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>
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.
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.
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"
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)
36 CFG
="$HOME/.wp-buildrc"
37 [ -f "$CFG" ] && source "$CFG"
39 function checksudo
() {
40 if [ $NEEDSUDO -a $UID -ne 0 ]; then
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
60 -l list all wp instances
62 -b backup site -s <sitename>
64 -s sitename, always needed!
65 -w download latest version of everyting
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
80 [ "$VERBOSE" ] && echo "Installing $1 $3 in $2"
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"
88 [ "$VERBOSE" ] && echo "* Downloading latest versions of wordpress and plugins..."
90 [ -f "latest.tar.gz" ] && mv latest.
tar.gz latest_$
(date +%F
).
tar.gz
91 wget http
://wordpress.org
/latest.
tar.gz
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:"
111 [ "$VERBOSE" ] && echo "* Dropping $USER database"
112 if [ "$DELETE" ];then
114 DROP USER '$USER'@'localhost';
115 DROP DATABASE IF EXISTS \`$USER\` ;
117 mysql
-u$SQLUSER -p$SQLPWD < "$TMPFILE"
123 [ "$VERBOSE" ] && echo "* New $USER database"
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"
136 [ "$VERBOSE" ] && echo "* Database: $USER@localhost"
137 [ "$VERBOSE" ] && echo "* Password: $PWORD"
141 [ "$VERBOSE" ] && echo "* Adding $SITENAME to git"
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"
158 echo "* Overwriting existing $SITE"
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)"
167 tar xzf
"$WPDIR/wordpress-latest.tar.gz"
168 mv wordpress
"$SITENAME"
170 USER
=$
(echo "$SITENAME" |
sed -e "s/\.ap//" -e "s/\.//")
173 [ "$KILLSITE" ] && killsite
174 [ "$DELETE" ] && sqldrop
178 function listsites
() {
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/\.//")
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 ” ” _`
199 # tar cvfz code.$DATE.gz
203 while getopts "bdfghklprs:tvw" Option
; do
213 s
) SITENAME
=$OPTARG;;
220 shift $
(( OPTIND
- 1 ))
223 if [ ! "$TYPE" -o "$SITENAME" ];then
228 [ "$REMOVESITE" ] && removesite
229 [ "$BACKUP" ] && backupsite
231 TMPFILE
=$
(mktemp
) || error
"Problem creating tempfile"
235 [ "$ALLTYPES" ] || error
"Maybe add some $TYPE?"
236 for name
in $ALLTYPES; do
237 install "$TYPE" "$SITENAME" "$name"
241 cd "$WWDIR/$SITENAME/wp-content/"
242 for name
in ${plugins[@]}
244 install "plugins" "$SITENAME" "$name"
247 for name
in ${themes[@]}
249 install "themes" "$SITENAME" "$name"
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