mvhub-dev team mailing list archive
-
mvhub-dev team
-
Mailing list archive
-
Message #00218
[Merge] lp:~leegoodrich/mvhub/update_mv_developer_home_dir into lp:mvhub
Lee Goodrich has proposed merging lp:~leegoodrich/mvhub/update_mv_developer_home_dir into lp:mvhub.
Requested reviews:
MVHub devs with commit rights (mvhub-commit)
Added functions that create the .bazaar and .ssh directories within a developer's home directory, then creates bazaar.conf and locations.conf in .bazaar and config within .ssh with the defaults that we use. If those files already exists, the default files will be created with a .default appended to it (bazaar.conf.default, for example) as to not overwrite a user's configuration settings. This is invoked via the mv_update_development script.
--
https://code.launchpad.net/~leegoodrich/mvhub/update_mv_developer_home_dir/+merge/26336
Your team MVHub Developers is subscribed to branch lp:mvhub.
=== modified file 'app-mvhub/project-tools/bin/mv_update_development'
--- app-mvhub/project-tools/bin/mv_update_development 2010-05-20 18:03:55 +0000
+++ app-mvhub/project-tools/bin/mv_update_development 2010-05-28 19:11:42 +0000
@@ -20,19 +20,20 @@
use MVHub::Utils::Setup;
my @ALLOWED_HOSTS = qw/ brave cricket /;
-my @WEBSITE_CODES = @MVHub::Utils::Setup::SITE_CODES;
+my @WEBSITE_CODES = @MVHub::Utils::Setup::SITE_CODES;
{ # main
- my $interactive = 0;
- my $usage = 0;
- my $hostname = `hostname`;
+ my $interactive = 0;
+ my $usage = 0;
+ my $hostname = `hostname`;
chomp $hostname;
-
- Getopt::Long::GetOptions( 'prompt' => \$interactive,
- 'help|?' => \$usage )
- or die "GetOptions failed";
-
- if ( $usage ) {
+
+ Getopt::Long::GetOptions(
+ 'prompt' => \$interactive,
+ 'help|?' => \$usage
+ ) or die "GetOptions failed";
+
+ if ($usage) {
print usage();
exit 0;
}
@@ -47,43 +48,68 @@
system('clear');
- my $base_dir = $cfg->param('BASE.dir');
- my @dirs = MVHub::Utils::Setup::get_dirs_with( "$base_dir", $USERNAME );
-
my $prompt = "Create $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
- }
-
- $prompt = "Update config files for $USERNAME? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_config_files_for( $USERNAME, $cfg, @WEBSITE_CODES );
- $cfg = MVHub::Utils::ConfigSimple::create_config_from( $ENV{MV_CONFIG_FILE} );
-
- }
-
- $prompt = "DESTROY and reload databases for $USERNAME (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_database_user( $USERNAME, $cfg);
- MVHub::Utils::Setup::make_databases_for( $USERNAME, $cfg, @WEBSITE_CODES );
- MVHub::Utils::Setup::load_test_data_for( $USERNAME, $cfg, @WEBSITE_CODES );
- }
-
- $prompt = "Apply database updates for $USERNAME? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::apply_database_updates_for( $USERNAME, $cfg, @WEBSITE_CODES );
- }
-
+ print "Creating $USERNAME directory structure...";
+ my $base_dir = $cfg->param('BASE.dir');
+ my @dirs = MVHub::Utils::Setup::get_dirs_with( "$base_dir", $USERNAME );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
+ }
+ $prompt = "Create config files in /home/$USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ print "Creating config files in /home/$USERNAME...\n";
+ prompt(
+ "Enter developer email address: ",
+ -default=>"$USERNAME\@thecsl.org" );
+ my $dev_email = $_;
+ prompt( "Enter developer Launchpad username: ",
+ -default=>$USERNAME );
+ my $launchpad_login = $_;
+
+ my @dev_home_dirs = MVHub::Utils::Setup::get_dev_home_dirs($USERNAME);
+ MVHub::Utils::Setup::make_dirs_from( \@dev_home_dirs );
+ my @dev_home_files =
+ MVHub::Utils::Setup::get_dev_home_files( $USERNAME, $dev_email,
+ $launchpad_login );
+ MVHub::Utils::Setup::make_dev_home_files(@dev_home_files);
+ }
+
+ $prompt = "Update config files for $USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::make_config_files_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ $cfg = MVHub::Utils::ConfigSimple::create_config_from(
+ $ENV{MV_CONFIG_FILE} );
+
+ }
+
+ $prompt = "DESTROY and reload databases for $USERNAME (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::make_database_user( $USERNAME, $cfg );
+ MVHub::Utils::Setup::make_databases_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ MVHub::Utils::Setup::load_test_data_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ }
+
+ $prompt = "Apply database updates for $USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::apply_database_updates_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ }
+
if ( defined $ENV{SUDO_USER} ) {
foreach my $prefix (@WEBSITE_CODES) {
- $prompt = "Add $prefix entries for $USERNAME into DNS and Apache? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::add_dns( $USERNAME, $prefix );
- MVHub::Utils::Setup::add_apache_config( $USERNAME, $prefix );
- }
+ $prompt =
+ "Add $prefix entries for $USERNAME into DNS and Apache? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::add_dns( $USERNAME, $prefix );
+ MVHub::Utils::Setup::add_apache_config( $USERNAME, $prefix );
+ }
}
}
}
+
sub die_if_bad_env_for {
my $username = shift or croak 'missing parameter $username\n';
my $msg = '';
=== modified file 'app-mvhub/project-tools/bin/mv_update_production'
--- app-mvhub/project-tools/bin/mv_update_production 2010-05-21 19:52:52 +0000
+++ app-mvhub/project-tools/bin/mv_update_production 2010-05-28 19:11:42 +0000
@@ -60,7 +60,7 @@
my $prompt = "Create $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
}
$prompt = "Update config files for $USERNAME? (Y/N):";
=== modified file 'app-mvhub/project-tools/bin/mv_update_staging'
--- app-mvhub/project-tools/bin/mv_update_staging 2010-05-21 19:52:52 +0000
+++ app-mvhub/project-tools/bin/mv_update_staging 2010-05-28 19:11:42 +0000
@@ -60,7 +60,7 @@
my $prompt = "Recreate $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
}
$prompt = "Update config files? (Y/N):";
=== modified file 'lib-mvhub/lib/MVHub/Utils/Setup.pm'
--- lib-mvhub/lib/MVHub/Utils/Setup.pm 2010-05-21 20:01:19 +0000
+++ lib-mvhub/lib/MVHub/Utils/Setup.pm 2010-05-28 19:11:42 +0000
@@ -14,20 +14,23 @@
use MVHub::Utils::DB;
our @EXPORT_OK = qw(
- @SITE_CODES
- add_apache_config
- add_dns
- get_production_data
- get_testing_data
- make_config_files_for
- make_database_user
- make_databases_for
- make_dirs_from
- load_production_data
- load_test_data_for
- remove_cron_jobs
- restart_services
- update_etc_files
+ @SITE_CODES
+ add_apache_config
+ add_dns
+ get_dev_home_dirs
+ get_dev_home_files
+ get_production_data
+ get_testing_data
+ make_config_files_for
+ make_database_user
+ make_databases_for
+ make_dev_home_files
+ make_dirs_from
+ load_production_data
+ load_test_data_for
+ remove_cron_jobs
+ restart_services
+ update_etc_files
);
our @SITE_CODES = qw/ mvh nsp /;
@@ -37,20 +40,20 @@
my $tmp_file = "$file.tmp";
open( IN, $file )
- or die "bad open: $file error: $! \n";
+ or die "bad open: $file error: $! \n";
my @lines = <IN>;
close(IN) or die "bad close $file error: $!\n";
push @lines, $append_lines;
open( OUT, ">", "$tmp_file" )
- or die "couldn't open $tmp_file.tmp error: $! \n";
+ or die "couldn't open $tmp_file.tmp error: $! \n";
( print OUT @lines )
- or die "couldn't write to $tmp_file $!\n";
+ or die "couldn't write to $tmp_file $!\n";
close(OUT) or die "couldn't close $tmp_file $!\n";
File::Copy::move( $tmp_file, $file )
- or die "couldn't rename $tmp_file to $file\n";
+ or die "couldn't rename $tmp_file to $file\n";
}
sub _add_calculable_values {
@@ -58,10 +61,11 @@
my $username = shift or croak 'missing param: $username';
my $site_code = shift or croak 'missing param: $site_code';
- $template_cfg->param( 'DATABASE.database_name', "$username.$site_code" );
- $template_cfg->param( 'DATABASE.database_user', "$username" );
- $template_cfg->param( 'NOTIFICATION.admin_email', "$username\@thecsl.org" );
- $template_cfg->param( 'NOTIFICATION.dev_email', "$username\@thecsl.org" );
+ $template_cfg->param( 'DATABASE.database_name', "$username.$site_code" );
+ $template_cfg->param( 'DATABASE.database_user', "$username" );
+ $template_cfg->param( 'NOTIFICATION.admin_email',
+ "$username\@thecsl.org" );
+ $template_cfg->param( 'NOTIFICATION.dev_email', "$username\@thecsl.org" );
$template_cfg->param( 'SITE.website_name',
"$site_code.$username.testing123.net" );
$template_cfg->param( 'SITE.website_code', "$site_code" );
@@ -125,8 +129,8 @@
usename = ?
SQL
- my $matching_db_users_aref =
- $dbh->selectall_arrayref( $sql, {}, ($username) );
+ my $matching_db_users_aref
+ = $dbh->selectall_arrayref( $sql, {}, ($username) );
return scalar @$matching_db_users_aref;
}
@@ -143,10 +147,10 @@
rolname = ?
SQL
- my $role_rows_aref =
- $dbh->selectall_arrayref( $sql, { Slice => {} }, ($username) );
+ my $role_rows_aref
+ = $dbh->selectall_arrayref( $sql, { Slice => {} }, ($username) );
my $result = $$role_rows_aref[0]{rolcreaterole}
- && $$role_rows_aref[0]{rolcreatedb};
+ && $$role_rows_aref[0]{rolcreatedb};
return $result ? 1 : 0;
}
@@ -164,8 +168,8 @@
rolname = ?
SQL
- my $role_rows_aref =
- $dbh->selectall_arrayref( $sql, { Slice => {} }, ($username) );
+ my $role_rows_aref
+ = $dbh->selectall_arrayref( $sql, { Slice => {} }, ($username) );
return $$role_rows_aref[0]{rolsuper} ? 1 : 0;
}
@@ -186,7 +190,7 @@
$cmd =~ s/^\s+//;
my @cmd = split /\s+/, $cmd;
( system(@cmd) == 0 )
- or die "$cmd failed ABORTING\n";
+ or die "$cmd failed ABORTING\n";
}
sub _get_dbh_for_template1_db {
@@ -207,7 +211,7 @@
);
my $dbh = DBI->connect( $data_source, $database_username, $auth, \%attr )
- or die "couldn't connect to database";
+ or die "couldn't connect to database";
return $dbh;
}
@@ -234,10 +238,10 @@
my $filename = shift or croak 'missing Param $filename';
open my $out_fh, '>', $filename
- or die "failed to open $filename for writing error:$!\n";
+ or die "failed to open $filename for writing error:$!\n";
print $out_fh "#Config file\n [ignore]\n";
close $out_fh
- or die "failed to close $filename error:$!\n";
+ or die "failed to close $filename error:$!\n";
return 1;
}
@@ -268,7 +272,7 @@
my $filename = shift or croak 'missing parameter: $filename';
open my $in_fh, $filename
- or die "failed to open $filename error:$!";
+ or die "failed to open $filename error:$!";
my @contents = <$in_fh>;
my $regex = qr/$host/;
@@ -287,7 +291,8 @@
}
elsif ( $output =~ /ROLLBACK/ ) {
print "FAIL\n";
- print "The following OUTPUT occured while processing $filename:\n";
+ print
+ "The following OUTPUT occured while processing $filename:\n";
die "$output\n\n****Processing $filename FAILED****\n";
}
}
@@ -345,8 +350,9 @@
my @website_codes = @_;
foreach my $prefix (@website_codes) {
- my $update_user_cfg_filename =
- _determine_user_config_filename_from( $username, $prefix, $cfg );
+ my $update_user_cfg_filename
+ = _determine_user_config_filename_from( $username, $prefix,
+ $cfg );
my $update_user_cfg = MVHub::Utils::ConfigSimple::create_config_from(
$update_user_cfg_filename);
my $dbh = MVHub::Utils::DB::get_dbh($update_user_cfg_filename);
@@ -373,8 +379,8 @@
my $dbh = shift;
my $version;
- my $exist_sql =
-"SELECT 1 FROM information_schema.tables WHERE table_name='version_log' LIMIT 1";
+ my $exist_sql
+ = "SELECT 1 FROM information_schema.tables WHERE table_name='version_log' LIMIT 1";
my $table_exists = ( $dbh->selectrow_array($exist_sql) )[0];
if ($table_exists) {
@@ -405,7 +411,7 @@
}
else {
die
-"ERROR: '$script' does not conform to naming standard: nnn_word_description.sql\n";
+ "ERROR: '$script' does not conform to naming standard: nnn_word_description.sql\n";
}
}
return sort @scripts;
@@ -415,50 +421,42 @@
my $base_dir = shift or croak 'missing param: $base_dir';
my $username = shift or croak 'missing param: $username';
my @dirs = (
- {
- dir => 'conf',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'cover_db',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'reports',
+ { dir => 'conf',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'cover_db',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'reports',
owner => '',
group => '',
permissions => 'u=rwx,g=rwsx,o=r-x',
},
- {
- dir => 'reports',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'source-code',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'log/mvh',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'log/nsp',
- owner => '',
- group => '',
- permissions => 'u=rwx,g=rwsx,o=rx',
- },
- {
- dir => 'tmp',
+ { dir => 'reports',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'source-code',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'log/mvh',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'log/nsp',
+ owner => '',
+ group => '',
+ permissions => 'u=rwx,g=rwsx,o=rx',
+ },
+ { dir => 'tmp',
owner => '',
group => '',
permissions => 'u=rwx,g=rwsx,o=rx',
@@ -466,9 +464,9 @@
);
foreach my $dir_href (@dirs) {
$dir_href->{owner} = $username
- if not $dir_href->{owner};
+ if not $dir_href->{owner};
$dir_href->{group} = $username
- if not $dir_href->{group};
+ if not $dir_href->{group};
$dir_href->{dir} = "$base_dir/$username/" . $dir_href->{dir};
}
@@ -491,8 +489,8 @@
$cmd .= "/tmp/${site_code}_production_data.dump";
( system($cmd) == 0 )
- or die
- "Failed to rsync ${timestamp}_${site_code}_production_db.sql\n";
+ or die
+ "Failed to rsync ${timestamp}_${site_code}_production_db.sql\n";
}
print "done\n";
}
@@ -506,18 +504,19 @@
print "Loading production data...";
foreach my $suffix (@website_codes) {
- my $cfg_filename =
- _determine_user_config_filename_from( $username, $suffix, $cfg );
- my $user_cfg =
- MVHub::Utils::ConfigSimple::create_config_from($cfg_filename);
+ my $cfg_filename
+ = _determine_user_config_filename_from( $username, $suffix,
+ $cfg );
+ my $user_cfg
+ = MVHub::Utils::ConfigSimple::create_config_from($cfg_filename);
_set_db_ENV_vars($user_cfg);
- $cmd =
-"pg_restore -O -x -d $username.$suffix /tmp/${suffix}_production_data.dump >/dev/null";
+ $cmd
+ = "pg_restore -O -x -d $username.$suffix /tmp/${suffix}_production_data.dump >/dev/null";
( system($cmd) == 0 )
- or warn "failed to load ${suffix}_production_data.dump";
+ or warn "failed to load ${suffix}_production_data.dump";
}
print "done\n";
}
@@ -527,23 +526,25 @@
my $cfg = shift or croak 'missing param: $cfg';
my @website_codes = @_;
- my $path_to_project_tools = $cfg->param('ABSOLUTE_PATH.project_tools_dir');
+ my $path_to_project_tools
+ = $cfg->param('ABSOLUTE_PATH.project_tools_dir');
my $cmd;
print "Loading test data...";
foreach my $suffix (@website_codes) {
- my $cfg_filename =
- _determine_user_config_filename_from( $username, $suffix, $cfg );
- my $user_cfg =
- MVHub::Utils::ConfigSimple::create_config_from($cfg_filename);
+ my $cfg_filename
+ = _determine_user_config_filename_from( $username, $suffix,
+ $cfg );
+ my $user_cfg
+ = MVHub::Utils::ConfigSimple::create_config_from($cfg_filename);
_set_db_ENV_vars($user_cfg);
- $cmd =
- "psql -f ${path_to_project_tools}/test_${suffix}_db.sql >/dev/null";
+ $cmd
+ = "psql -f ${path_to_project_tools}/test_${suffix}_db.sql >/dev/null";
( system($cmd) == 0 )
- or warn "failed to load data for $username.$suffix";
+ or warn "failed to load data for $username.$suffix";
}
print "done\n";
}
@@ -554,15 +555,16 @@
my @website_codes = @_;
my @keys_for_user_generated_values = qw/ DATABASE.database_magic_word /;
- my $template_config_file =
- $cfg->param('ABSOLUTE_PATH.template_conf_dir') . "/template.conf";
+ my $template_config_file
+ = $cfg->param('ABSOLUTE_PATH.template_conf_dir') . "/template.conf";
my $template_cfg = new Config::Simple($template_config_file)
- or die "failed to create config object from $template_config_file";
+ or die "failed to create config object from $template_config_file";
foreach my $site_code (@website_codes) {
- my $cfg_filename =
- _determine_user_config_filename_from( $username, $site_code, $cfg );
+ my $cfg_filename
+ = _determine_user_config_filename_from( $username, $site_code,
+ $cfg );
my $user_cfg = new Config::Simple( syntax => 'ini' );
if ( !-e $cfg_filename ) {
_make_empty_config_file_named($cfg_filename);
@@ -574,8 +576,8 @@
$template_cfg = _add_site_specific_values( $template_cfg, $username,
%site_specific_values );
- $template_cfg =
- _add_calculable_values( $template_cfg, $username, $site_code );
+ $template_cfg
+ = _add_calculable_values( $template_cfg, $username, $site_code );
$template_cfg = _add_user_generated_values( $template_cfg, $user_cfg,
@keys_for_user_generated_values );
@@ -585,6 +587,82 @@
}
}
+sub get_dev_home_dirs {
+ my $username = shift or croak 'missing param: $username';
+ my @dirs = (
+ { dir => "/home/$username/.bazaar",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=rwx,o=rx',
+ },
+ { dir => "/home/$username/.ssh",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=,o=',
+ }
+ );
+ return @dirs;
+}
+
+sub get_dev_home_files {
+ my $username = shift or croak 'missing param: $username';
+ my $email_address = shift or croak 'missing param: $email_address';
+ my $launchpad_login = shift or croak 'missing param: $launchpad_login';
+
+ my $result = ( getpwnam("$username") )[6];
+ croak "$username not a valid username\n" if !( defined $result );
+ my $name = ( split ",", $result )[0];
+
+ my @files = (
+ { dest => "/home/$username/.bazaar/bazaar.conf",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rw,g=rw,o=r',
+ contents => <<"CONTENT",
+[DEFAULT]
+email = $name <$email_address>
+launchpad_username = $launchpad_login
+mail_client = mutt
+
+[ALIASES]
+recentlog = log -r-20..-1 --short --forward
+ll = log -r-10..-1 --line --forward
+CONTENT
+ },
+ { dest => "/home/$username/.bazaar/locations.conf",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rw,g=rw,o=r',
+ contents => <<"CONTENT",
+[/var/www/mvhub/$username/source-code]
+push_location = lp:~$launchpad_login/mvhub/
+push_location:policy = appendpath
+public_branch = lp:~$launchpad_login/mvhub/
+public_branch:policy = appendpath
+submit_to = merge\@code.launchpad.net
+submit_branch = lp:mvhub
+
+[/var/www/mvhub/$username/source-code/trunk]
+push_location = lp:mvhub/trunk
+public_branch = lp:mvhub/trunk
+CONTENT
+ },
+ { dest => "/home/$username/.ssh/config",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=,o=',
+ contents => <<'CONTENT',
+Host bazaar.launchpad.net
+IdentityFile ~/.ssh/id_rsa_launchpad
+
+Host *
+IdentityFile ~/.ssh/id_rsa
+CONTENT
+ }
+ );
+ return @files;
+}
+
sub make_database_user {
my $username = shift or croak 'missing parameter: $username';
my $cfg = shift or croak 'missing parameter: $cfg';
@@ -592,8 +670,8 @@
my $dbh = _get_dbh_for_template1_db($cfg);
if ( !_db_user_found( $dbh, $username ) ) {
- my $sql =
- "CREATE USER $username WITH PASSWORD 'test' CREATEDB CREATEROLE";
+ my $sql
+ = "CREATE USER $username WITH PASSWORD 'test' CREATEDB CREATEROLE";
$dbh->do($sql);
}
}
@@ -611,7 +689,7 @@
if ( !_db_user_has_needed_roles( $dbh, $user_running_cmd ) ) {
warn
-"\nSkipping db stuff $user_running_cmd lacks CREATEDB or CREATEROLE\n";
+ "\nSkipping db stuff $user_running_cmd lacks CREATEDB or CREATEROLE\n";
return;
}
@@ -635,33 +713,49 @@
# kludge to avoid 'db being currently being accessed' errs
sleep 1;
- $sql =
-qq{CREATE DATABASE "$username.${suffix}" OWNER "$username" ENCODING='SQL_ASCII' };
+ $sql
+ = qq{CREATE DATABASE "$username.${suffix}" OWNER "$username" ENCODING='SQL_ASCII' };
$dbh->do($sql);
}
print "done\n";
}
+sub make_dev_home_files {
+ my @files = @_;
+ croak 'missing param: @files' if !( scalar @files );
+ foreach my $file_href (@files) {
+ if ( -e $file_href->{dest} ) {
+ $file_href->{dest} = "$file_href->{dest}.default";
+ }
+ open FILE, ">$file_href->{dest}" or croak "open FILE failed: $!";
+ print FILE $file_href->{contents};
+ close FILE or croak "close FILE failed: $!";
+ my $chown_cmd
+ = "chown $file_href->{owner}:$file_href->{group} $file_href->{dest}";
+ my $chmod_cmd = "chmod $file_href->{permissions} $file_href->{dest}";
+ _do_or_die($chown_cmd);
+ _do_or_die($chmod_cmd);
+ }
+}
+
sub make_dirs_from {
- my $username = shift or croak 'missing param: $username';
- my $dir_hrefs_href = shift or croak 'missing param: $dir_hrefs_href';
- my @dir_hrefs = @$dir_hrefs_href;
+ my $dir_aref_hrefs = shift or croak 'missing param: $dir_hrefs_href';
+ my @dir_hrefs = @$dir_aref_hrefs;
- print "Updating $username directory structure...";
foreach my $dir_href (@dir_hrefs) {
my $mkdir_cmd = "mkdir -p $dir_href->{dir}";
- my $chown_cmd =
- "chown -R $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
+ my $chown_cmd
+ = "chown -R $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
if ( $dir_href->{dir} =~ /log/ ) {
- # root owns log files it creates don't try to change ownership on them
- $chown_cmd =
- "chown $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
+ # root owns log files it creates don't try to change ownership on them
+ $chown_cmd
+ = "chown $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
}
else {
- $chown_cmd =
- "chown -R $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
+ $chown_cmd
+ = "chown -R $dir_href->{owner}:$dir_href->{group} $dir_href->{dir}";
}
my $chmod_cmd = "chmod $dir_href->{permissions} $dir_href->{dir}";
_do_or_die($mkdir_cmd);
=== added directory 'lib-mvhub/t/Utils/Setup'
=== added file 'lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t'
--- lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t 2010-05-28 19:11:42 +0000
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2 + 1; # + 1 for no warnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies with no username';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_dirs() } $test_message;
+
+###
+$test_message = 'lives ok';
+###
+my $username = 'test';
+lives_ok { MVHub::Utils::Setup::get_dev_home_dirs($username) } $test_message;
=== added file 'lib-mvhub/t/Utils/Setup/get_dev_home_files.t'
--- lib-mvhub/t/Utils/Setup/get_dev_home_files.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/get_dev_home_files.t 2010-05-28 19:11:42 +0000
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5 + 1; # + 1 for NoWarnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies with no username';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_files() } $test_message;
+
+###
+$test_message = 'dies with no email_address';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_files('test') } $test_message;
+
+###
+$test_message = 'dies with no launchpad_login';
+###
+dies_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'test', 'test@xxxxxxxxxxxxxx' );
+}
+$test_message;
+
+###
+$test_message = 'dies with invalid username';
+###
+dies_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'test', 'test@xxxxxxxxxxxxxx',
+ 'test_lp' );
+}
+$test_message;
+
+###
+$test_message = 'lives with valid username';
+###
+lives_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'omacneil',
+ 'test@xxxxxxxxxxxxxx', 'test_lp' );
+}
+$test_message;
+
=== added file 'lib-mvhub/t/Utils/Setup/make_dev_home_files.t'
--- lib-mvhub/t/Utils/Setup/make_dev_home_files.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/make_dev_home_files.t 2010-05-28 19:11:42 +0000
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use English '-no_match_vars';
+
+use Test::More tests => 6 + 1; # + 1 for NoWarnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies when not passed in array';
+###
+dies_ok { MVHub::Utils::Setup::make_dev_home_files() } $test_message;
+
+###
+$test_message = 'dies when passed invalid array';
+###
+my @test_data = ();
+dies_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'dies when passed array with invalid file path';
+###
+@test_data = ( { dest => '/this/is/a/bad/path' } );
+dies_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'lives when passed valid array';
+###
+my $group_id = ( split ' ', $GID )[0];
+@test_data = (
+ { dest => "/tmp/make_dev_home_files_t_$PID.txt",
+ owner => $UID,
+ group => $group_id,
+ permissions => 'u=rwx,g=rwx,o=rx',
+ contents => <<"CONTENT",
+This is a test file created by make_dev_home_files.t. You can delete it.
+CONTENT
+ },
+);
+lives_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'test file created correctly';
+###
+open FILE, "<$test_data[0]->{dest}";
+my $line = <FILE>;
+close FILE;
+is( $line, $test_data[0]->{contents}, $test_message );
+
+###
+$test_message = 'Backup created when file already exists';
+###
+my $original_file = $test_data[0]->{dest};
+MVHub::Utils::Setup::make_dev_home_files(@test_data);
+ok( ( -e "$test_data[0]->{dest}" ), $test_message );
+
+unlink $original_file;
+unlink $test_data[0]->{dest};
Follow ups