App-Repo
view release on metacpan or search on metacpan
#!/usr/bin/env perl
use 5.010;
use warnings;
use strict;
use Mojolicious::Lite;
use File::Find;
use File::Path;
use Getopt::Std;
use App::Repo::Daemon qw< daemonize >;
use App::Repo qw< digest packages >;
use open qw<:encoding(UTF-8)>;
my %switch = ();
$0 = "repo";
getopts('s:d:hp', \%switch);
sub start {
my $packages = packages($switch{d});
my $base_dir = $switch{d}; $base_dir =~ s/(\/deb)//;
system("rm -rf $base_dir/Packages*");
open(my $fh,">>", "$base_dir/Packages") || die "cant open $base_dir/Packages: $!";
for my $package (@$packages){
for(@$package){
print $fh "$_\n";
}
};
close $fh;
system("cd $base_dir && cp Packages Packages.txt && gzip Packages");
my $repo_icon_path = sub {
my $repo_lib_dir = `perldoc -l App::Repo`; chomp $repo_lib_dir;
$repo_lib_dir =~ s/\.pm/\/CydiaIcon\.png/;
return $repo_lib_dir;
};
my $repo_icon = $repo_icon_path->();
unless( -f "$base_dir/CydiaIcon.png" ){
system("cp $repo_icon $base_dir/");
}
if( defined $switch{p} ){ say "refreshed"; return }
say "starting $0: PID $$";
daemonize();
app->static->paths->[0] = $base_dir;
any '/' => sub {
shift->reply->static('Packages.txt');
};
app->start('daemon');
#plugin( 'Directory', root => "$base_dir" )->start('daemon', '-l', "http://*:3000");
}
sub usage {
my $help = <<'END_MESSAGE';
USAGE:
-start repo
repo -d /path/to/deb
-stop repo
repo -stop
-check if repo is running
repo -status
-update packages list
repo -d /path/to/deb -p
-see documentation
perldoc repo
-see this help
repo -h
END_MESSAGE
print $help;
}
if(defined $switch{d}){
start();
} elsif(defined $switch{h}){
usage();
} elsif( defined $switch{s} ){
my $pids = ' ';
my @ps = grep{ /repo/ } qx{ ps aux };
for(@ps){
push my @pid, split(" ", $_);
if( $pid[10] eq $0 ){
$pids .= " $pid[1]" unless $pid[1] eq $$;
}
}
( run in 1.080 second using v1.01-cache-2.11-cpan-df04353d9ac )