forked from majnemer/davesdots
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual_fetch.pl
executable file
·38 lines (30 loc) · 1006 Bytes
/
manual_fetch.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env perl
use warnings;
use strict;
### manual_fetch.pl
# a small Perl script to fetch the latest snapshot of a git repo from gitweb
# using minimal requirements (perl, tar, gzip, and (curl or wget))
# URL of the download link on github
my $URL = 'https://github.com/majnemer/davesdots/tarball/master';
my $tgz = http_fetch($URL);
extract_tgz($tgz);
rename(glob('majnemer-davesdots-*'), 'davesdots');
sub http_fetch {
my $url = shift;
# See if we should use wget or curl
if(grep {-x "$_/curl"} split /:/, $ENV{'PATH'}) {
return qx{curl -L -s '$url'};
} elsif(grep {-x "$_/wget"} split /:/, $ENV{'PATH'}) {
# do not check the cert due to a bug in wget:
# http://support.github.com/discussions/site/2230
return qx{wget --no-check-certificate -O - '$url'};
} else {
die "Could not find curl or wget, aborting!";
}
}
sub extract_tgz {
my $data = shift;
open(my $pipe, '|-', 'tar', '-xzf', '-') || die "manual_fetch.pl: tar failed: $!";
print $pipe $data;
close($pipe);
}