Skip to content

Commit 7a2df53

Browse files
rootroot
authored andcommitted
Adding in the vhost generators.
1 parent 26a7910 commit 7a2df53

File tree

3 files changed

+232
-4
lines changed

3 files changed

+232
-4
lines changed

install-wordpress.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ randpass
3535
USER_PASS=$RET
3636

3737
#Make user and group
38-
useradd -m $DOMAIN_NAME
38+
useradd -m -d /home/$DOMAIN_NAME -U $DOMAIN_NAME
3939
echo $USER_PASS > tmp
4040
echo $USER_PASS >> tmp
4141
passwd $DOMAIN_NAME < tmp
4242
rm tmp
4343

4444

4545
INSTALL_DIR="/home/$DOMAIN_NAME/wordpress"
46-
mkdir -p $INSTALL_DIR
4746
cd $INSTALL_DIR
4847

4948
#Get latest version, delete old version
@@ -58,8 +57,9 @@ rm -rf wordpress/
5857
#change permissions (not necessary so far)
5958

6059
#Create Database and Database user
61-
echo "CREATE DATABASE $DOMAIN_NAME;
62-
GRANT ALL PRIVILEGES ON $DOMAIN_NAME.* TO "$DOMAIN_NAME"@"localhost" IDENTIFIED BY '"$DB_PASS"';
60+
echo "CREATE USER '$DOMAIN_NAME'@'localhost' IDENTIFIED BY '$DB_PASS'
61+
CREATE DATABASE $DOMAIN_NAME;
62+
GRANT ALL PRIVILEGES ON $DOMAIN_NAME.* TO '$DOMAIN_NAME'@'localhost' IDENTIFIED BY '$DB_PASS';
6363
FLUSH PRIVILEGES;
6464
EXIT;" > input
6565
mysql --user=root --password=$2 < input

mindtouch-vhost-gen.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#Exit statuses:
2+
# 1: Incorrect arguements
3+
# 2: Vhost already exists
4+
5+
#Makes the script exit if anything is evaluated as false or a variable
6+
#isn't set properly. Robust!!
7+
#set -uo
8+
9+
#The directory in which the vhost files will be stored. Default is
10+
# '/etc/apache2/sites-available/' in Debian/Ubuntu. Make sure it ends in a "/"
11+
APACHE_DIR='/etc/apache2/sites-available/'
12+
13+
#MySQL hostname. Change to "localhost" if Apache and MySQL are on the same
14+
#server.
15+
MYSQL_HOST="localhost"
16+
17+
#Removes the periods in the domain name and replaces them with double
18+
#underscores (for usernames and database names)
19+
WIKI=$(echo $1 | sed "s/\./__/")
20+
21+
#Random Password Generator Script originally from jbreland
22+
#http://legroom.net/2010/05/06/bash-random-password-generator
23+
24+
# Generate a random password
25+
PASS=`cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16}`
26+
WEB_PASS=`cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16}`
27+
28+
#Print usage if no args.
29+
if [ $# != "2" ]; then
30+
echo ""
31+
echo "Generates a VirtualHost file for the given hostname, to be used with"
32+
echo 'MindTouch multi-tenant installations. Must have "Include script-dir/*"'
33+
echo "in an enabled Apache site for this to work. Apache will then use every"
34+
echo "VHost file in that directory."
35+
echo ""
36+
echo " Usage:"
37+
echo " vhost-gen.sh hostname admin_email"
38+
echo ""
39+
exit 1
40+
fi
41+
42+
#Check if VHost directory exists. If not, make it.
43+
if [ ! -d $APACHE_DIR ]; then
44+
mkdir $APACHE_DIR
45+
fi
46+
47+
if [ -f $APACHE_DIR$1 ]; then
48+
echo "VHost already exists"
49+
exit 2
50+
fi
51+
52+
#Write the vhost file to the Apache vhost directory
53+
#echo "<VirtualHost *:80>" >> $APACHE_DIR$1
54+
#echo " ServerName $1" >> $APACHE_DIR$1
55+
#echo " ServerAlias $1" >> $APACHE_DIR$1
56+
#echo " DocumentRoot /var/www/dekiwiki/" >> $APACHE_DIR$1
57+
#echo "</VirtualHost>" >> $APACHE_DIR$1
58+
59+
#Enable the new vhost
60+
#a2ensite $APACHE_DIR$1
61+
62+
/var/www/dekiwiki/maintenance/createdb.sh --dbName $1 --dbAdminUser root --dbAdminPassword ThetHethE \
63+
--dbServer localhost --dbWikiUser $WIKI --wikiAdmin Admin \
64+
--wikiAdminPassword $PASS --wikiAdminEmail $2 \
65+
--storageDir /var/www/dekiwiki/attachments/$1 \
66+
--s3PublicKey AKIAJRNNTU7U2XLDXSXA \
67+
--s3PrivateKey s36seTXsQNKnIbfYW5NXm7jNGTTlAOSdhzM6H3Ao \
68+
--s3Bucket servercobra-mindtouch --s3Prefix $1 --s3Timeout 60\
69+
--storageDir /var/www/dekiwiki/$1 >> /tmp/createdb
70+
71+
#Adds to the mindtouch config file, using sed to go in the middle of the file.
72+
# -i is to do in place editing, while creating a backup file (file.bak)
73+
#Searches for string "/globalconfig" (note escaped /)
74+
#Then appends the rest at the next line (a\ )
75+
#Final line specifies config file location. Note double quotes to allow
76+
#variables in sed strings.
77+
78+
79+
sed -i.bak "
80+
/\/globalconfig/ a\
81+
\ <config id=\"$1\">\
82+
\n\ <host>$1</host>\
83+
\n\ <db-server>localhost</db-server>\
84+
\n\ <db-port>3306</db-port>\
85+
\n\ <db-catalog>$WIKI</db-catalog>\
86+
\n\ <db-user>$WIKI</db-user>\
87+
\n\ <db-password>$PASS</db-user>\
88+
\n\ <db-options>>pooling=true; Connection Timeout=5; Protocol=socket; Min Pool Size=2; Max Pool Size=50; Connection Reset=false;character set=utf8;$
89+
\n\ </config>
90+
" /etc/dekiwiki/mindtouch.deki.startup.xml
91+
92+
#Does the same as above, but modifies the LocalSettings.php file in
93+
#the dekiwiki web directory. Not sure why there are two places for
94+
#the same information though.
95+
96+
sed -i.bak "
97+
/$wgWikis = array(/ a\
98+
\ '$1' => array(
99+
\n\ 'db-server' => 'localhost',
100+
\n\ 'db-port' => '3306',
101+
\n\ 'db-catalog' => '$WIKI',
102+
\n\ 'db-user' => '$WIKI',
103+
\n\ 'db-password' => '$PASS',
104+
\n\ ),
105+
" /var/www/dekiwiki/LocalSettings.php
106+
107+
#Make Apache aware of the new VHost file.
108+
/etc/init.d/apache2 reload
109+
#Restart Mindtouch for changes to take effect. This needs to be fixed
110+
#eventually, because everyone's site goes down at the same time.
111+
#MindTouch has an artice on how they fixed it, which may be of use.
112+
#
113+
#http://developer.mindtouch.com/Wik.is/EC2_Infrastructure
114+
/etc/init.d/dekiwiki restart

vhost-gen.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#Exit statuses:
2+
# 1: Incorrect arguements
3+
# 2: Vhost already exists
4+
5+
#Makes the script exit if anything is evaluated as false or a variable
6+
#isn't set properly. Robust!!
7+
#set -uo
8+
9+
#The directory in which the vhost files will be stored. Default is
10+
# '/etc/apache2/sites-available/' in Debian/Ubuntu. Make sure it ends in a "/"
11+
APACHE_DIR='/etc/apache2/sites-available/'
12+
13+
#MySQL hostname. Change to "localhost" if Apache and MySQL are on the same
14+
#server.
15+
MYSQL_HOST="localhost"
16+
17+
#Removes the periods in the domain name and replaces them with double
18+
#underscores (for usernames and database names)
19+
WIKI=$(echo $1 | sed "s/\./__/")
20+
21+
#Random Password Generator Script originally from jbreland
22+
#http://legroom.net/2010/05/06/bash-random-password-generator
23+
24+
# Generate a random password
25+
PASS=`cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16}`
26+
WEB_PASS=`cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16}`
27+
28+
#Print usage if no args.
29+
if [ $# != "2" ]; then
30+
echo ""
31+
echo "Generates a VirtualHost file for the given hostname, to be used with"
32+
echo 'MindTouch multi-tenant installations. Must have "Include script-dir/*"'
33+
echo "in an enabled Apache site for this to work. Apache will then use every"
34+
echo "VHost file in that directory."
35+
echo ""
36+
echo " Usage:"
37+
echo " vhost-gen.sh hostname admin_email"
38+
echo ""
39+
exit 1
40+
fi
41+
42+
#Check if VHost directory exists. If not, make it.
43+
if [ ! -d $APACHE_DIR ]; then
44+
mkdir $APACHE_DIR
45+
fi
46+
47+
if [ -f $APACHE_DIR$1 ]; then
48+
echo "VHost already exists"
49+
exit 2
50+
fi
51+
52+
#Write the vhost file to the Apache vhost directory
53+
#echo "<VirtualHost *:80>" >> $APACHE_DIR$1
54+
#echo " ServerName $1" >> $APACHE_DIR$1
55+
#echo " ServerAlias $1" >> $APACHE_DIR$1
56+
#echo " DocumentRoot /var/www/dekiwiki/" >> $APACHE_DIR$1
57+
#echo "</VirtualHost>" >> $APACHE_DIR$1
58+
59+
#Enable the new vhost
60+
#a2ensite $APACHE_DIR$1
61+
62+
/var/www/dekiwiki/maintenance/createdb.sh --dbName $1 --dbAdminUser root --dbAdminPassword ThetHethE \
63+
--dbServer localhost --dbWikiUser $WIKI --wikiAdmin Admin \
64+
--wikiAdminPassword $PASS --wikiAdminEmail $2 \
65+
--storageDir /var/www/dekiwiki/attachments/$1 \
66+
--s3PublicKey AKIAJRNNTU7U2XLDXSXA \
67+
--s3PrivateKey s36seTXsQNKnIbfYW5NXm7jNGTTlAOSdhzM6H3Ao \
68+
--s3Bucket servercobra-mindtouch --s3Prefix $1 --s3Timeout 60\
69+
--storageDir /var/www/dekiwiki/$1 >> /tmp/createdb
70+
71+
#Adds to the mindtouch config file, using sed to go in the middle of the file.
72+
# -i is to do in place editing, while creating a backup file (file.bak)
73+
#Searches for string "/globalconfig" (note escaped /)
74+
#Then appends the rest at the next line (a\ )
75+
#Final line specifies config file location. Note double quotes to allow
76+
#variables in sed strings.
77+
78+
79+
sed -i.bak "
80+
/\/globalconfig/ a\
81+
\ <config id=\"$1\">\
82+
\n\ <host>$1</host>\
83+
\n\ <db-server>localhost</db-server>\
84+
\n\ <db-port>3306</db-port>\
85+
\n\ <db-catalog>$WIKI</db-catalog>\
86+
\n\ <db-user>$WIKI</db-user>\
87+
\n\ <db-password>$PASS</db-user>\
88+
\n\ <db-options>>pooling=true; Connection Timeout=5; Protocol=socket; Min Pool Size=2; Max Pool Size=50; Connection Reset=false;character set=utf8;$
89+
\n\ </config>
90+
" /etc/dekiwiki/mindtouch.deki.startup.xml
91+
92+
#Does the same as above, but modifies the LocalSettings.php file in
93+
#the dekiwiki web directory. Not sure why there are two places for
94+
#the same information though.
95+
96+
sed -i.bak "
97+
/$wgWikis = array(/ a\
98+
\ '$1' => array(
99+
\n\ 'db-server' => 'localhost',
100+
\n\ 'db-port' => '3306',
101+
\n\ 'db-catalog' => '$WIKI',
102+
\n\ 'db-user' => '$WIKI',
103+
\n\ 'db-password' => '$PASS',
104+
\n\ ),
105+
" /var/www/dekiwiki/LocalSettings.php
106+
107+
#Make Apache aware of the new VHost file.
108+
/etc/init.d/apache2 reload
109+
#Restart Mindtouch for changes to take effect. This needs to be fixed
110+
#eventually, because everyone's site goes down at the same time.
111+
#MindTouch has an artice on how they fixed it, which may be of use.
112+
#
113+
#http://developer.mindtouch.com/Wik.is/EC2_Infrastructure
114+
/etc/init.d/dekiwiki restart

0 commit comments

Comments
 (0)