PDA

View Full Version : Example domain_create_post.sh script.



thuskey
09-21-2004, 08:58 PM
I remember someone was asking if the domain_create_post.sh script can be ran at the reseller level and not at the server level. I was in the same situation, so I wrote this script, which only does something useful if the resellers name is johndoe. In this example, the /home/johndoe/domains/default/ directory has a complete prebuilt installation of oscommerce. The problem was a few files and directories lost their write access during account creation, so this script fixes the osc installation.



#!/bin/bash

username=${username}

creator=`grep creator /usr/local/directadmin/data/users/$username/user.conf | cut -f2 -d"="`

if [ $creator = 'johndoe' ]

then

cp -r /var/lib/mysql/oscmaster /var/lib/mysql/oscommerce_$username

chown -R mysql:mysql /var/lib/mysql/oscommerce_$username

ln -s /home/five/domains/giftswithtlc.com/public_html/images /home/$username/domains/${domain}/public_html/images

ln -s /home/$username/public_html/images /home/$username/domains/${domain}/public_html/catalog/images

chmod -R go+rw /home/$username/domains/${domain}/public_html/catalog/templates/

chmod -R go+rw /home/$username/domains/${domain}/public_html/catalog/admin/backups/

chmod -R go+rw /home/$username/domains/${domain}/public_html/catalog/includes/languages/

chmod -R go+rw /home/$username/domains/${domain}/public_html/catalog/admin/images/graphs/

fi

thuskey
10-04-2005, 10:30 AM
Just an update of my original sample code. It's gotten much more involved over the last few months.

#!/usr/bin/perl

&update_aliases;
&log;

if ( $ENV{usertype} eq 'reseller' && $ENV{package} eq 'wholesale' ) {
`cp -R /home/freesites/domains/default/ /home/$ENV{username}/domains/default/`;
`cp -R -f /home/reseller/* /usr/local/directadmin/data/users/$ENV{username}/`;
`chown -R diradmin:diradmin /usr/local/directadmin/data/users/$ENV{username}`;
# `cp -R /usr/local/directadmin/data/users/freesites/packages/webstore.pkg /usr/local/directadmin/data/users/$ENV{username}/packages/ `;
# `cp -R /usr/local/directadmin/data/users/freesites/packages.list /usr/local/directadmin/data/users/$ENV{username}/ `;
# `chown -R $ENV{username}:$ENV{username} /home/$ENV{username}/domains/default/ `;
# `chown -R $ENV{username}:$ENV{username} /usr/local/directadmin/data/users/$ENV{username}/packages/ `;

}

if ( $ENV{package} eq 'webstore' ) {
$database = $ENV{username} . "_" . $ENV{domain} . "_oscommerce";
$database =~ s/\./_/g;

if ( $ENV{creator} eq 'just1host' ) {
`cp -R -p /var/lib/mysql/demo1_demo_just1host_com_oscommerce /var/lib/mysql/$database`;
} else {
`cp -R -p /var/lib/mysql/admin_oscommerce /var/lib/mysql/$database`;
}
`ln -s /home/admin/domains/sharedip/wh1 /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog/images/wh1`;
`chmod -R go+w /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog`;
`chmod 444 /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog/includes/configure.php`;
`chmod 444 /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog/admin/includes/configure.php`;

if ( $database =~ /wholesale/ ) {
`/home/admin/scripts/update_store_stock_status.pl $database`;
}

&create_mysql_user;
&create_osc_admin;
}

if ( $ENV{package} ne 'webstore' && $ENV{creator} ne 'freestores') {
`rm -r -f /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog`;
`rm -f /home/$ENV{username}/domains/$ENV{domain}/public_html/.htaccess`;
}

if ( $ENV{creator} eq 'freestores' ) {
$database = $ENV{username} . "_store";
`cp -R -p /var/lib/mysql/admin_store /var/lib/mysql/$database`;
`chmod -R go+w /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog`;
`chmod 444 /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog/includes/configure.php`;
`chmod 444 /home/$ENV{username}/domains/$ENV{domain}/public_html/catalog/admin/includes/configure.php`;
&create_store_mysql_user;
&create_store_admin;
}

exit;

sub create_store_mysql_user {
use DBI();
$dbh = DBI->connect("dbi:mysql:host=localhost","adminusername","xxxxxx");
$dbh->do("GRANT USAGE ON * . * TO '$ENV{username}_store'\@'localhost';");
$dbh->do("GRANT ALL PRIVILEGES ON `$database` . * TO '$ENV{username}_store'\@'localhost' WITH GRANT OPTION ;");
$dbh->do("SET PASSWORD FOR '$ENV{username}_store'\@'localhost' = PASSWORD('xxxxxx') ");
$dbh->do("FLUSH PRIVILEGES;");
$dbh->disconnect();
}

sub create_store_admin {
$dbh2 = DBI->connect("dbi:mysql:database=$database:host=localhost","$ENV{username}_store","xxxxxx");
$dbh2->do("INSERT INTO `admin` ( `admin_groups_id`, `admin_firstname`, `admin_lastname`, `admin_email_address`, `admin_password` ) VALUES ( '1', 'Store', 'Owner', '$ENV{email}', '901d1d6a604293aa3c58b3f5ff56757c:74') ") || print "Admin Creation Failed";
$dbh2->disconnect();
}

sub create_mysql_user {
use DBI();
$dbh = DBI->connect("dbi:mysql:host=localhost","adminaccount","xxxxxx");
$dbh->do("GRANT USAGE ON * . * TO '$ENV{username}_osc'\@'localhost';");
$dbh->do("GRANT ALL PRIVILEGES ON `$database` . * TO '$ENV{username}_osc'\@'localhost' WITH GRANT OPTION ;");
$dbh->do("SET PASSWORD FOR '$ENV{username}_osc'\@'localhost' = PASSWORD('xxxxxx') ");
$dbh->do("FLUSH PRIVILEGES;");
$dbh->disconnect();
}

sub create_osc_admin {
$dbh2 = DBI->connect("dbi:mysql:database=$database:host=localhost","$ENV{username}_osc","xxxxxx");
$dbh2->do("INSERT INTO `admin` ( `admin_groups_id`, `admin_firstname`, `admin_lastname`, `admin_email_address`, `admin_password` ) VALUES ( '1', 'Store', 'Owner', '$ENV{email}', '901d1d6a604293aa3c58b3f5ff56757c:74') ") || print "Admin Creation Failed";
$dbh2->disconnect();
}

sub update_aliases {
open (ALIASES, "/etc/virtual/$ENV{domain}/aliases");
while (<ALIASES>) {
chomp ($line = $_);
$line =~ s/:fail:/$ENV{email}/g;
$temp .= "$line\n";
}
close ALIASES;
open (ALIASES, "> /etc/virtual/$ENV{domain}/aliases");
print ALIASES $temp;
close ALIASES;
`rm -f -r /home/$ENV{username}/domains/$ENV{domain}/private_html/`;
`ln -s /home/$ENV{username}/domains/$ENV{domain}/public_html /home/$ENV{username}/domains/$ENV{domain}/private_html`;
}

sub log {
open (FILE, "> ./outfile");
foreach $key (sort keys %ENV) {
print FILE $key . ":" . $ENV{$key} . "\n";
}
}

nobaloney
10-05-2005, 04:52 PM
There's a lot of work in there, Travis.

Can you possible tell us all it does so we don't have to study every line of it?

Thanks.

Jeff