Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #38 from techman83/mirrorkan
Browse files Browse the repository at this point in the history
Mirrorkan
  • Loading branch information
techman83 committed May 18, 2016
2 parents 39e34a7 + 7a95d26 commit 4926a10
Show file tree
Hide file tree
Showing 35 changed files with 2,522 additions and 31 deletions.
40 changes: 40 additions & 0 deletions bin/ckan-webhooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env perl

use v5.010;
use strict;
use warnings;
use Dancer2 appname => "xKanHooks";
use File::Path qw(mkpath);

# PODNAME: ckan-webhooks

# ABSTRACT: ckan-webhooks - Small webserver for accepting webhooks

# VERSION

# TODO: Investigate config passing
$ENV{XKAN_GHSECRET} or die 'XKAN_GHSECRET needs to be set';

if ( -e "/tmp/xKan_netkan.lock" ) {
unlink "/tmp/xKan_netkan.lock";
}

# TODO: This could use a lot of improvement.
if (config->{environment} eq 'development') {
use lib 'lib/';
set logger => "Console";
} else {
if ( ! -d $ENV{HOME}."/CKAN-Webhooks" ) {
mkpath( $ENV{HOME}."/CKAN-Webhooks/" );
}

set appdir => $ENV{HOME}."/CKAN-Webhooks";
set logger => "File";
config->{logger}{log_level} = "info";
config->{logger}{location} = config->{appdir};
}

set serializer => 'JSON';

use App::KSP_CKAN::WebHooks;
dance;
94 changes: 94 additions & 0 deletions bin/mirror-ckan
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env perl

use v5.010;
use strict;
use autodie qw(:all);
use App::KSP_CKAN::Tools::Config;
use App::KSP_CKAN::Mirror;
use Getopt::Long;
use File::Spec;

# PODNAME: mirror-ckan

# ABSTRACT: mirror-ckan - script for uploading ckan files to the mirror.

# VERSION

=head1 SYNOPSIS
Usage:
mirror-ckan --ckan /path/to/file.ckan : Takes a ckan file and mirrors it to the
: Internet Archive.
Debugging commands:
mirror-ckan --debug : Run with debugging enabled.
=head1 Description
This is a simple cli utility for uploading ckans to the Internet Archive.
=head1 BUGS/Features Requests
Please submit any bugs, feature requests to
L<https://github.com/KSP-CKAN/NetKAN-bot/issues> .
Contributions are more than welcome!
=head1 SEE ALSO
L<App::KSP-CKAN>
=cut

my $PROGNAME = (File::Spec->splitpath($0))[2];
$PROGNAME ||= 'mirror-ckan';

my $DEBUG = 0;
my $filename;

# TODO: It'd be nice to specify a path/multiple files
my $getopts_rc = GetOptions(
"version" => \&version,
"debug!" => \$DEBUG,
"ckan=s" => \$filename,

"help|?" => \&print_usage,
);

# TODO: Allow config to be specified
my $config = App::KSP_CKAN::Tools::Config->new(
debugging => $DEBUG,
);
my $mirror = App::KSP_CKAN::Mirror->new( config => $config );

$mirror->upload_ckan($filename);

exit 0;

sub version {
$::VERSION ||= "Unreleased";
say "$PROGNAME version : $::VERSION";
exit 1;
}

sub print_usage {
say q{
Usage:
mirror-ckan --ckan /path/to/file.ckan : Takes a ckan file and mirrors it to the
: Internet Archive.
Debugging commands:
mirror-ckan --debug : Run with debugging enabled.
mirror-ckan --version : Run with debugging enabled.
For more documentation, use `perldoc mirror-ckan`.
};

exit 1;
}

__END__
25 changes: 25 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ repository.url = git://github.com/KSP-CKAN/NetKAN-bot
repository.web = https://github.com/KSP-CKAN/NetKAN-bot
repository.type = git

[Encoding]
encoding = bytes
match = zip

[PruneFiles]
match = init/*

[@Basic]

[Test::Perl::Critic]
Expand All @@ -26,11 +33,29 @@ stopwords = netkan
stopwords = api
stopwords = KSP
stopwords = BaconLabs
stopwords = CKANs
stopwords = CreateURLHash
stopwords = MirrorKAN
stopwords = NetFileCache
stopwords = ckans
stopwords = cli
stopwords = mediatype
stopwords = Webhook
stopwords = metapackage
stopwords = webhooks
stopwords = ckan
stopwords = iaS
stopwords = sha
stopwords = mimetype

[AutoPrereqs]

[Prereqs]
experimental = 0.013
IO::Socket::SSL = 0
EV = 0
Twiggy = 0
LWP::Protocol::https = 0

[OurPkgVersion]
[PodWeaver]
Expand Down
106 changes: 106 additions & 0 deletions init/ckan-webhooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: ckan-webhooks
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: CKAN Webhooks
# Description: init script for CKAN Webhook Service.
### END INIT INFO

USER=netkan
GROUP=netkan
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/$USER/perl5/bin
NAME=ckan-webhooks
DESC="CKAN Webhooks"
PIDDIR=/var/run/$NAME
PIDFILE=$PIDDIR/$NAME.pid
WORKDIR=/home/$USER/CKAN-Webhooks
DAEOPTS="-E production -s Twiggy /home/$USER/perl5/bin/ckan-webhooks"
DAEMON=/home/$USER/perl5/bin/plackup

# TODO: This could use improvement.
GH_SECRET=$WORKDIR/ghsecret
test -e $GH_SECRET || exit 0
export XKAN_GHSECRET=`cat $GH_SECRET`

test -x $DAEMON || exit 0
export PERL5LIB=$PERL5LIB:/home/$USER/perl5/lib/perl5

case "$1" in
start)
echo -n "Starting $DESC ..."
[ -d $PIDDIR ] || install -o $USER -d $PIDDIR
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--make-pidfile \
--chuid $USER:$GROUP \
--chdir $WORKDIR \
--background \
--exec $DAEMON -- $DAEOPTS

case "$?" in
0|1) echo "Started" ;;
2) echo "Failed" ;;
esac
;;
stop)
echo -n "Stopping $DESC ..."
start-stop-daemon --stop --quiet \
--retry=TERM/30/KILL/5 \
--pidfile $PIDFILE \
--user $USER
case "$?" in
0|1) rm -f $PIDFILE
echo "Stopped"
;;
2) echo "Failed" ;;
esac
;;
status)
if start-stop-daemon --test --stop --quiet \
--pidfile $PIDFILE \
--user $USER
then
echo "$DESC is running."
exit 0
else
echo "$DESC is not running"
exit 3
fi
;;
restart)
echo -n "Restarting $DESC ..."
start-stop-daemon --stop --quiet \
--retry=TERM/30/KILL/5 \
--pidfile $PIDFILE \
--user $USER
case "$?" in
0|1)
[ -d $PIDDIR ] || install -o $USER -d $PIDDIR
rm -f $PIDFILE
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--make-pidfile \
--chuid $USER:$GROUP \
--chdir $WORKDIR \
--background \
--exec $DAEMON -- $DAEOPTS
case "$?" in
0) echo "Restarted" ;;
*) echo "Start Failed" ;;
esac
;;
*)
echo "Stop Failed"
;;
esac
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|status}" >&2
exit 3
;;
esac

exit 0
Loading

0 comments on commit 4926a10

Please sign in to comment.