| 1 | #! @PERL@ -w |
| 2 | # |
| 3 | # VFS to manage the gputils archives. |
| 4 | # Written by Molnár Károly (proton7@freemail.hu) 2012 |
| 5 | # |
| 6 | |
| 7 | my %month = ('jan' => '01', 'feb' => '02', 'mar' => '03', |
| 8 | 'apr' => '04', 'may' => '05', 'jun' => '06', |
| 9 | 'jul' => '07', 'aug' => '08', 'sep' => '09', |
| 10 | 'oct' => '10', 'nov' => '11', 'dec' => '12'); |
| 11 | |
| 12 | my @PATHS = ('/usr/bin/gplib', '/usr/local/bin/gplib'); |
| 13 | |
| 14 | my $gplib = ''; |
| 15 | |
| 16 | foreach my $i (@PATHS) |
| 17 | { |
| 18 | if (-x $i) |
| 19 | { |
| 20 | $gplib = $i; |
| 21 | last; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | if ($gplib eq '') |
| 26 | { |
| 27 | print STDERR "\a\t$0 : Gplib not found!\n"; |
| 28 | exit(1); |
| 29 | } |
| 30 | |
| 31 | my $cmd = shift; |
| 32 | my $archive = shift; |
| 33 | |
| 34 | #------------------------------------------------------------------------------- |
| 35 | |
| 36 | sub mc_ulib_fs_list |
| 37 | { |
| 38 | open(PIPE, "$gplib -tq $archive |") || die("Error in $gplib -tq"); |
| 39 | |
| 40 | my($dev, $inode, $mode, $nlink, $uid, $gid) = stat($archive); |
| 41 | |
| 42 | while (<PIPE>) |
| 43 | { |
| 44 | chomp; |
| 45 | my @w = split(/\s+/o); |
| 46 | my $fname = $w[0]; |
| 47 | |
| 48 | $fname =~ s|\\|/|g; |
| 49 | |
| 50 | printf("-rw-r--r-- 1 %s %s %d %s-%02u-%s %s %s\n", |
| 51 | $uid, $gid, int($w[1]), $month{lc($w[4])}, $w[5], $w[7], substr($w[6], 0, 5), $fname); |
| 52 | } |
| 53 | |
| 54 | close (PIPE); |
| 55 | } |
| 56 | |
| 57 | #------------------------------------------------------------------------------- |
| 58 | |
| 59 | sub mc_ulib_fs_copyin |
| 60 | { |
| 61 | system("$gplib -r $archive $_[0]"); |
| 62 | my $ret = $?; |
| 63 | |
| 64 | if ($ret) |
| 65 | { |
| 66 | die("Error in: $gplib -r"); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | #------------------------------------------------------------------------------- |
| 71 | |
| 72 | sub mc_ulib_fs_copyout |
| 73 | { |
| 74 | my($module, $fname) = @_; |
| 75 | my $tmpdir = $ENV{'TMPDIR'}; |
| 76 | |
| 77 | $tmpdir = '/tmp' if ($tmpdir eq ''); |
| 78 | |
| 79 | open(PIPE, "$gplib -tq $archive |") || die("Error in: $gplib -tq"); |
| 80 | |
| 81 | while (<PIPE>) |
| 82 | { |
| 83 | chomp; |
| 84 | my @w = split(/\s+/o); |
| 85 | my $module_orig = $w[0]; |
| 86 | my $count = () = ($module_orig =~ /(\\)/g); |
| 87 | my $md = $module_orig; |
| 88 | |
| 89 | $md =~ s|\\|/|g; |
| 90 | |
| 91 | if ($module eq $md) |
| 92 | { |
| 93 | return if ($count); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | close (PIPE); |
| 98 | |
| 99 | chdir($tmpdir); |
| 100 | system("$gplib -x $archive $module"); |
| 101 | my $ret = $?; |
| 102 | |
| 103 | if ($ret) |
| 104 | { |
| 105 | die("Error in: $gplib -x"); |
| 106 | } |
| 107 | |
| 108 | rename($module, $fname) || die("Error in: rename($module, $fname)"); |
| 109 | } |
| 110 | |
| 111 | #------------------------------------------------------------------------------- |
| 112 | |
| 113 | sub mc_ulib_fs_rm |
| 114 | { |
| 115 | system("$gplib -d $archive $_[0]"); |
| 116 | my $ret = $?; |
| 117 | |
| 118 | if ($ret) |
| 119 | { |
| 120 | die("Error in: $gplib -d"); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | ################################################################################ |
| 125 | |
| 126 | if ($cmd eq 'list') |
| 127 | { |
| 128 | mc_ulib_fs_list(@ARGV); |
| 129 | } |
| 130 | elsif ($cmd eq 'copyin') |
| 131 | { |
| 132 | mc_ulib_fs_copyin(@ARGV); |
| 133 | } |
| 134 | elsif ($cmd eq 'copyout') |
| 135 | { |
| 136 | mc_ulib_fs_copyout(@ARGV); |
| 137 | } |
| 138 | elsif ($cmd eq 'rm') |
| 139 | { |
| 140 | mc_ulib_fs_rm(@ARGV); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | exit(1); |
| 145 | } |