Permalink
Browse files

Server scripts for WP automatically installing.

This assumes you have cpanel installed and the /scripts/ directory off of /
It also assumes you replace instances of example.com with an url of your own.
It also assumes you have the latest version of WordPress in /root/custom-skel/public_html/
  • Loading branch information...
1 parent 2d87bf9 commit 66365bf9f1745494cf5dec509d1cb5c8590d4182 @brianlayman committed Aug 20, 2012
Showing with 155 additions and 0 deletions.
  1. +4 −0 README
  2. +63 −0 scripts/postwwwacct
  3. +31 −0 scripts/postwwwacct 2
  4. +57 −0 scripts/postwwwacct3
View
4 README
@@ -0,0 +1,4 @@
+Server scripts for WP automatically installing.
+This assumes you have cpanel installed and the /scripts directory off of /
+It also assumes you replace instances of example.com with an url of your own.
+It also assumes you have the latest version of WordPress in /root/custom-skel/public_html
View
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+print "\nCreating MySQL database for WordPress.\n";
+
+# There are two supported methods for creating the database in this script
+# the first preferred method calls mysqladmin and the second calls mysql
+# either of these files could be in /usr/bin/ or /usr/local/bin/
+if (-e "/usr/bin/mysqladmin" ) {
+ $mysqladmin = '/usr/bin/mysqladmin';
+} else {
+ if (-e "/usr/local/bin/mysqladmin" ) {
+ $mysqladmin = '/usr/local/bin/mysqladmin';
+ } else {
+ if (-e "/usr/bin/mysql" ) {
+ $mysql = '/usr/bin/mysql';
+ } else {
+ if (-e "/usr/local/bin/mysql" ) {
+ $mysql = '/usr/local/bin/mysql';
+ } else {
+ print "<hr/>FATAL ERROR: MYSQL AND MYSQLADMIN WERE NOT FOUND<hr/>\n";
+ exit;
+ }
+ }
+ }
+}
+
+# The CPanel hook "postwwwacct" is passed a hash via ARGV
+# Therefore we must convert it to a normal Perl hash containing the data
+%OPTS = @ARGV;
+
+# Of the dozen+ parameters, all we care about is the user name
+$user = $OPTS{'user'};
+$userdb = $user . '_wp';
+
+# If no username was passed, error out.
+if ($user eq "") {
+ print "Syntax: postwwwacct user <username>\n";
+ exit;
+}
+
+# If someone is playing games, exit out.
+if ($user eq "root") {
+ exit;
+}
+
+# If mysqladmin was found, use it.
+if ($mysqladmin ne "") {
+ open(HANDLE,"|$mysqladmin -u root create $userdb");
+ print HANDLE "y";
+ close(HANDLE);
+ print "calling: |$mysqladmin -u root create $userdb"
+} else {
+ # Otherwise call MySQL
+ open(HANDLE,"|$mysql -u root");
+ print HANDLE "CREATE DATABASE $userdb;";
+ close(HANDLE);
+ print "calling: CREATE DATABASE $userdb;"
+}
+
+if (-e "/scripts/postwwwacct2") {
+ print "\nSending variables to postwwwacct2.\n";
+ system("/scripts/postwwwacct2",@ARGV);
+}
+exit;
View
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+# The CPanel hook "postwwwacct" is passed a hash via ARGV
+# Therefore we must convert it to a normal Perl hash containing the data
+%OPTS = @ARGV;
+
+# Of the dozen+ parameters, all we care about is the domain name
+$domain = $OPTS{'domain'};
+
+# If no username was passed, error out.
+if ($domain eq "") {
+ print "Syntax: postwwwacct2 domain <domain>\n";
+ exit;
+}
+
+# If someone is playing games, exit out.
+# change this to your main domain
+if ($domain eq "example.com") {
+ exit;
+}
+
+# change this to your main domain
+print "\nAdding Hostmaster forward to valiases configuration $domain\n";
+system("echo 'hostmaster@" . $domain . ": hostmaster\@example.com' >> /etc/valiases/" . $domain);
+#system("echo 'postmaster@$domain: postmaster@example.com' >> /etc/valiases/$domain");
+system("echo 'postmaster@" . $domain . ": postmaster\@example.com' >> /etc/valiases/" . $domain);
+
+
+if (-e "/scripts/postwwwacct3") {
+ print "\nSending variables to postwwwacct3.\n";
+ system("/scripts/postwwwacct3",@ARGV);
+}
View
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+print "\n In postwwwacct3.\n";
+
+use constant NOT_FOUND => -1; # All good programmers use Constants
+use constant HOSTS_FILE => "/etc/hosts"; # Standard host file location
+
+# The CPanel hook "postwwwacct" is passed a hash via ARGV
+# Therefore we must convert it to a normal Perl hash containing the data
+%OPTS = @ARGV;
+print "\n postwwwacct3: Args Loaded.\n";
+
+# Of the dozen+ parameters, all we care about is the domain name
+$domain = $OPTS{'domain'};
+# $ip = $OPTS('useip');
+#$ip = '127.0.0.1';
+#Change this to your main domain
+$ip=`dig \@ns1.example.com $domain A +short`;
+chomp($ip);
+my $needle="www.$domain"; # I search with www. prefix
+
+my $hostline="$ip $domain www.$domain";
+print "\n postwwwacct3: Vars Done.\n";
+
+# If no username was passed, error out.
+if ($domain eq "") {
+ print "Minimum Syntax: postwwwacct3 domain <domain>\n";
+ exit;
+}
+
+# Read the file into a scalar var in the most backwards compatible way
+local( $/, *FILEHANDLE );
+open(FILEHANDLE, HOSTS_FILE) or die("Cannot access " . HOSTS_FILE);
+my $haystack = <FILEHANDLE>;
+close(FILEHANDLE);
+print "Host File Accessed\n";
+
+# Look for the domain in the file already
+my $result = index($haystack, $needle);
+
+# Index returns
+if ( $result == NOT_FOUND )
+{
+ # If the line wasn't found, add it using an echo append >>
+ open(FILEHANDLE, ">>" . HOSTS_FILE);
+ print FILEHANDLE $hostline . "\n"; #write newline
+ close(FILEHANDLE);
+ print "$hostline added to hosts file\n";
+}
+else
+{
+ print "$needle already exists in hosts file\n";
+}
+
+if (-e "/scripts/postwwwacct4") {
+ print "\nSending variables to postwwwacct4.\n";
+ system("/scripts/postwwwacct4",@ARGV);
+}

0 comments on commit 66365bf

Please sign in to comment.