package SBO::App::Snap; # vim: ts=2:et # # sbosnap # script to pull down / update a local copy of the slackbuilds.org tree. # # authors: Jacob Pipkin # Luke Williams # Andreas Guldstrand # maintainer: Slack Coder use 5.16.0; use strict; use warnings FATAL => 'all'; use SBO::Lib qw/ _ERR_USAGE fetch_tree import_gpg_key update_tree %config show_version /; use Getopt::Long qw/ GetOptionsFromArray /; use parent 'SBO::App'; our $VERSION = '2.8.0'; sub _parse_opts { my $class = shift; my @ARGS = @_; my ($help, $vers); my $res = GetOptionsFromArray( \@ARGS, 'help|h' => \$help, 'version|v' => \$vers, ); return ({ help => $help, vers => $vers, args => \@ARGS, }, $res); } sub show_usage { my $self = shift; my $fname = $self->{fname}; print <<"EOF"; Usage: $fname [options|command] Options: -h|--help: this screen. -v|--version: version information. Commands: fetch: initialize a local copy of the slackbuilds.org tree. import-key [path or url]: import GPG for verifying the slackbuilds.org tree. Defaults to the key shipped with sbotools2. update: update an existing local copy of the slackbuilds.org tree. (generally, you may prefer "sbocheck" over "$fname update") EOF return 1; } sub run { my $self = shift; my @args = @{ $self->{args} }; if ($self->{help}) { $self->show_usage(); return 0 } if ($self->{vers}) { $self->show_version(); return 0 } unless ($< == 0) { warn "This script requires root privileges.\n"; exit _ERR_USAGE; } # check for a command and, if found, execute it $args[0] //= ''; if ($args[0] eq 'fetch') { fetch_tree(); } elsif ($args[0] eq 'import-key') { my $key_path_or_url = "/usr/doc/sbotools2-$VERSION/slackbuilds-devel\@slackbuilds.org.asc"; if ($args[1]) { $key_path_or_url = $args[1]; } my $key_id = $config{'GPG_KEY'}; import_gpg_key($key_path_or_url, $key_id); } elsif ($args[0] eq 'update') { update_tree(); } else { $self->show_usage(); return 1; } return 0; } 1;