#!/usr/bin/perl -w use strict; use warnings; use Switch; use File::Copy::Recursive; use File::Path; use constant false => 0; use constant true => 1; my $old_mirror_path="/net/mirror/llx1109/"; my $old_mirror_path_pool="$old_mirror_path.pool"; my $new_mirror_path="/net/mirror/llx1206/"; my $new_mirror_path_pool="$new_mirror_path.pool"; my $lliurex_up_mirror_local_conf_dir="/usr/share/lliurex-up/server/llx1206/"; my $lliurex_up_mirror_new_conf_dir="/usr/share/lliurex-up/server/llx1206-new/"; my $action=""; sub update_previous_mirror { # Update previous mirror print "[DEBUG] : Update the llx1109 mirror\n"; `reprepro --show-percent --show-percent -b $old_mirror_path update` || die $!; # Export previous mirro print "[DEBUG] : Export the llx1109 mirror \n"; `reprepro -V -b $old_mirror_path export` || die $!; } sub update_new_mirror { # Update previous mirror print "[DEBUG] : Update the llx1206 mirror\n"; `reprepro --show-percent --show-percent -b $new_mirror_path update` || die $!; # Export previous mirro print "[DEBUG] : Export the llx1206 mirror \n"; `reprepro -V -b $new_mirror_path export` || die $!; } sub prepare_updates_from_local_mirror { # Use the configuration files for a local mirror File::Copy::Recursive::dircopy($lliurex_up_mirror_local_conf_dir,$new_mirror_path) or die $!; } sub prepare_new_mirror_from_scratch { # Create new mirror `mkdir -p $new_mirror_path`; File::Copy::Recursive::dircopy($lliurex_up_mirror_new_conf_dir,$new_mirror_path) or die $!; } sub test_old_mirror { # Test if old mirror exists and if it is usable my $pool_st=`reprepro -b $old_mirror_path checkpool fast`; # At $? is the exit status of previous command (Thanks for BASH) if ($?==0) { print "[DEBUG] : Pool at $old_mirror_path is OK\n"; return true; } else { print "[DEBUG] : Pool at $old_mirror_path is not ready. Not using it...\n"; return false; } } sub test_new_mirror { # Test if new mirror exists and if it is usable my $pool_st=`reprepro -b $new_mirror_path checkpool fast`; # At $? is the exit status of previous command (Thanks for BASH) if ($?==0) { print "[DEBUG] : Pool at $new_mirror_path is OK\n"; return true; } else { print "[DEBUG] : Pool at $new_mirror_path is not ready. Not using it...\n"; return false; } } sub show_info_script { print "Summon mirror for upgrade\n"; } sub migrate_mirror { if (test_new_mirror()) { print "[DEBUG] : Using files from $new_mirror_path"; } elsif (test_old_mirror()) { print "[DEBUG] : Using previous files from Pool directory on $old_mirror_path/pool/\n"; update_previous_mirror(); prepare_updates_from_local_mirror(); } else { print "[DEBUG] : Creating new pool from scratch \n"; prepare_new_mirror_from_scratch(); } # Create update the mirror update_new_mirror(); } # Main program # ################ # Get the parameter $action = $ARGV[0]; switch ($action) { case "migrate" { migrate_mirror(); } case "info" { migrate_mirror(); show_info_script(); } else { die "Not correct parameter [migrate|info]"; } }