Changeset 299

Show
Ignore:
Timestamp:
08/15/08 20:36:18 (3 months ago)
Author:
mbr
Message:

update to import perl modules via a function and 'require' statements, added --Lib-dir arg

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gpgdir/trunk/gpgdir

    r293 r299  
    3232# 
    3333 
    34 use lib '/usr/lib/gpgdir'; 
    3534use File::Find; 
    3635use File::Copy; 
    37 use Term::ReadKey; 
    38 use GnuPG::Interface; 
    3936use IO::File; 
    4037use IO::Handle; 
     
    6158my $include_pat     = ''; 
    6259my $include_file    = ''; 
     60my $lib_dir         = '/usr/lib/gpgdir'; 
    6361my $pid_file        = ''; 
    6462my $total_encrypted = 0; 
     
    181179    'no-LC_ALL'      => \$no_locale, 
    182180    'no-locale'      => \$no_locale,       # synonym 
     181    'Lib-dir=s'      => \$lib_dir,         # Path to perl module path 
    183182    'verbose'        => \$verbose,         # Verbose mode. 
    184183    'Version'        => \$printver,        # Print version 
     
    204203    die "[*] The -d and --overwrite-encrypted options are incompatible."; 
    205204} 
     205 
     206### import perl modules (GnuPG::Interface, etc.) 
     207&import_perl_modules(); 
    206208 
    207209if ($wipe_mode) { 
     
    10801082        my $msg = 'Password: '; 
    10811083        ### get the password without echoing the chars back to the screen 
    1082         ReadMode 'noecho'
     1084        ReadMode('noecho')
    10831085        while (! $pw) { 
    10841086            print $msg; 
    1085             $pw = ReadLine 0
     1087            $pw = ReadLine(0)
    10861088            chomp $pw; 
    10871089        } 
    1088         ReadMode 'normal'
     1090        ReadMode('normal')
    10891091        if ($quiet) { 
    10901092            print "\n"; 
     
    12041206    close P; 
    12051207    return; 
     1208} 
     1209 
     1210sub import_perl_modules() { 
     1211 
     1212    my $mod_paths_ar = &get_mod_paths(); 
     1213 
     1214    if ($#$mod_paths_ar > -1) {  ### /usr/lib/gpgdir/ exists 
     1215        push @$mod_paths_ar, @INC; 
     1216        splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar; 
     1217    } 
     1218 
     1219    if ($verbose) { 
     1220        print "[+] import_perl_modules(): The \@INC array:\n"; 
     1221        print "$_\n" for @INC; 
     1222    } 
     1223 
     1224    require GnuPG::Interface; 
     1225    require Term::ReadKey; 
     1226 
     1227    Term::ReadKey->import(qw/ReadMode ReadLine/); 
     1228 
     1229    return; 
     1230} 
     1231 
     1232sub get_mod_paths() { 
     1233 
     1234    my @paths = (); 
     1235 
     1236    unless (-d $lib_dir) { 
     1237        my $dir_tmp = $lib_dir; 
     1238        $dir_tmp =~ s|lib/|lib64/|; 
     1239        if (-d $dir_tmp) { 
     1240            $lib_dir = $dir_tmp; 
     1241        } else { 
     1242            return []; 
     1243        } 
     1244    } 
     1245 
     1246    opendir D, $lib_dir or die "[*] Could not open $lib_dir: $!"; 
     1247    my @dirs = readdir D; 
     1248    closedir D; 
     1249 
     1250    push @paths, $lib_dir; 
     1251 
     1252    for my $dir (@dirs) { 
     1253        ### get directories like "/usr/lib/gpgdir/x86_64-linux" 
     1254        next unless -d "$lib_dir/$dir"; 
     1255        push @paths, "$lib_dir/$dir" 
     1256            if $dir =~ m|linux| or $dir =~ m|thread|; 
     1257    } 
     1258    return \@paths; 
    12061259} 
    12071260 
     
    12851338    -u, --user-homedir <dir>    - Path to home directory. 
    12861339    -l, --locale <locale>       - Manually define a locale setting. 
     1340    --Lib-dir <path>            - Path to the perl modules directory (not 
     1341                                  usually necessary). 
    12871342    --no-locale                 - Don't set the locale to anything (the 
    12881343                                  default is the "C" locale).