This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from techman83/mirrorkan
Mirrorkan
- Loading branch information
Showing
35 changed files
with
2,522 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.