From 31eaa03522d53008daaa15e47a65ad5a5b4d96c2 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 28 Aug 2020 01:07:00 +0530 Subject: Add kirch's fortunes --- lyra.pl | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lyra.pl b/lyra.pl index 6f86abc..6545552 100755 --- a/lyra.pl +++ b/lyra.pl @@ -63,11 +63,11 @@ my %fortunes = ( ); if ( $ARGV[0] ) { - if ($fortunes{ $ARGV[0] }) { + if ($fortunes{ $ARGV[0] } or -e "$fortune_dir/$ARGV[0]") { my $fortune_file = "$fortune_dir/$ARGV[0]"; random($fortune_file); } - elsif ( $ARGV[0] eq "latest") { get_latest(); } - elsif ( $ARGV[0] eq "mirror") { get_mirror(); } + elsif ( $ARGV[0] eq "latest") { get_kirch(); get_latest(); } + elsif ( $ARGV[0] eq "mirror") { get_kirch(); get_mirror(); } elsif ( $ARGV[0] eq "ls") { run3[ "ls", $fortune_dir]; } else { say "lyra: no such fortune"; } } else { say "Usage: lyra "; } @@ -79,9 +79,29 @@ sub random { say $fortunes[ rand @fortunes ]; # Print random fortune. } +sub get_kirch { + path("/tmp")->mkpath; + + run3 [qw(git -C /tmp clone https://github.com/JKirchartz/fortunes.git kirch)]; + $? # We assume non-zero is an error. + ? warn "[WARN] Cannot get kirch fortunes :: $?\n" + : say "Cloned kirch fortunes to /tmp/kirch"; + + foreach my $file (qw( README.md LICENSE Makefile )) { + my $file_t = "/tmp/kirch/$file"; + unlink $file_t and say "$file_t deleted." + or warn "[WARN] Could not delete $file_t: $!\n"; + } + system("rm -r /tmp/kirch/bin"); + system("cp -r /tmp/kirch/* /home/andinus/fortunes/"); +} + sub get_latest { foreach my $fortune (sort keys %fortunes) { ftp("$fortune_dir/$fortune", $fortunes{$fortune}); + $? # We assume non-zero is an error. + ? warn "[WARN] Failed to get $fortune :: $?\n" + : say "got $fortune"; } } -- cgit 1.4.1-2-gfad0