Snap.pm (2164B)
1 package SBO::App::Snap; 2 3 # vim: ts=2:et 4 # 5 # sbosnap 6 # script to pull down / update a local copy of the slackbuilds.org tree. 7 # 8 # authors: Jacob Pipkin <j@dawnrazor.net> 9 # Luke Williams <xocel@iquidus.org> 10 # Andreas Guldstrand <andreas.guldstrand@gmail.com> 11 # maintainer: Slack Coder <slackcoder@server.ky> 12 13 use 5.16.0; 14 use strict; 15 use warnings FATAL => 'all'; 16 use SBO::Lib qw/ _ERR_USAGE fetch_tree import_gpg_key update_tree %config show_version /; 17 use Getopt::Long qw/ GetOptionsFromArray /; 18 19 use parent 'SBO::App'; 20 21 our $VERSION = '2.9.0'; 22 23 sub _parse_opts { 24 my $class = shift; 25 my @ARGS = @_; 26 27 my ($help, $vers); 28 29 my $res = GetOptionsFromArray( 30 \@ARGS, 31 'help|h' => \$help, 32 'version|v' => \$vers, 33 ); 34 35 return ({ help => $help, vers => $vers, args => \@ARGS, }, $res); 36 } 37 38 sub show_usage { 39 my $self = shift; 40 my $fname = $self->{fname}; 41 print <<"EOF"; 42 Usage: $fname [options|command] 43 44 Options: 45 -h|--help: 46 this screen. 47 -v|--version: 48 version information. 49 50 Commands: 51 fetch: initialize a local copy of the slackbuilds.org tree. 52 import-key [path or url]: import GPG for verifying the slackbuilds.org tree. Defaults to the key shipped with sbotools2. 53 update: update an existing local copy of the slackbuilds.org tree. 54 (generally, you may prefer "sbocheck" over "$fname update") 55 56 EOF 57 return 1; 58 } 59 60 sub run { 61 my $self = shift; 62 my @args = @{ $self->{args} }; 63 64 if ($self->{help}) { $self->show_usage(); return 0 } 65 if ($self->{vers}) { $self->show_version(); return 0 } 66 67 unless ($< == 0) { 68 warn "This script requires root privileges.\n"; 69 exit _ERR_USAGE; 70 } 71 72 # check for a command and, if found, execute it 73 $args[0] //= ''; 74 75 if ($args[0] eq 'fetch') { 76 fetch_tree(); 77 } elsif ($args[0] eq 'import-key') { 78 my $key_path_or_url = "/usr/doc/sbotools2-$VERSION/slackbuilds-devel\@slackbuilds.org.asc"; 79 if ($args[1]) { 80 $key_path_or_url = $args[1]; 81 } 82 my $key_id = $config{'GPG_KEY'}; 83 84 import_gpg_key($key_path_or_url, $key_id); 85 } elsif ($args[0] eq 'update') { 86 update_tree(); 87 } else { 88 $self->show_usage(); 89 return 1; 90 } 91 92 return 0; 93 } 94 95 1;