Commit bab020eb authored by Leigh B Stoller's avatar Leigh B Stoller

Add option to set groups. Add option to hash downloaded file.

The reason for the groups option is so that we can use this
for users that are in more the 16 groups (stupid group limit that
breaks everything!).
parent e468f885
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2003-2011 University of Utah and the Flux Group. # Copyright (c) 2003-2012 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
use Getopt::Std; use Getopt::Std;
use BSD::Resource; use BSD::Resource;
use POSIX qw(:signal_h); use POSIX qw(:signal_h);
use strict;
# #
# Fetch tarballs and RPMs on behalf of a user. # Fetch tarballs and RPMs on behalf of a user.
...@@ -15,13 +16,15 @@ use POSIX qw(:signal_h); ...@@ -15,13 +16,15 @@ use POSIX qw(:signal_h);
# #
sub usage() sub usage()
{ {
print "Usage: $0 [-q] -u user URL localfile\n"; print "Usage: $0 [-q] [-h] -u user [-g g1,g2,...] URL localfile\n";
exit(-1); exit(-1);
} }
my $optlist = "qu:"; my $optlist = "qu:g:h";
my $quiet = 0; my $quiet = 0;
my $hashit = 0;
my $user; my $user;
my $grouplist;
# #
# Configure variables # Configure variables
...@@ -37,6 +40,7 @@ my $ISFS = ("@USERNODE_IP@" eq "@FSNODE_IP@") ? 1 : 0; ...@@ -37,6 +40,7 @@ my $ISFS = ("@USERNODE_IP@" eq "@FSNODE_IP@") ? 1 : 0;
my $WGET = "/usr/local/bin/wget"; my $WGET = "/usr/local/bin/wget";
my $REALPATH = "/bin/realpath"; my $REALPATH = "/bin/realpath";
my $CHMOD = "/bin/chmod"; my $CHMOD = "/bin/chmod";
my $SHA1 = "/sbin/sha1";
# #
# Turn off line buffering on output # Turn off line buffering on output
...@@ -73,6 +77,12 @@ if (defined($options{"q"})) { ...@@ -73,6 +77,12 @@ if (defined($options{"q"})) {
if (defined($options{"u"})) { if (defined($options{"u"})) {
$user = $options{"u"}; $user = $options{"u"};
} }
if (defined($options{"h"})) {
$hashit = 1;
}
if (defined($options{"g"})) {
$grouplist = $options{"g"};
}
if (@ARGV != 2 || !defined($user)) { if (@ARGV != 2 || !defined($user)) {
usage(); usage();
} }
...@@ -89,18 +99,10 @@ if (!($user =~ /^([\w-]+)$/)) { ...@@ -89,18 +99,10 @@ if (!($user =~ /^([\w-]+)$/)) {
$user = $1; $user = $1;
} }
(undef,undef,$unix_uid) = getpwnam($user) or my (undef,undef,$unix_uid) = getpwnam($user) or
die("*** $0:\n". die("*** $0:\n".
" No such user $user\n"); " No such user $user\n");
if (!($URL =~
/^((http|https|ftp):\/\/[\w.\-\/\@:~]+(\.tar|\.tar\.Z|\.tar\.gz|\.tgz|\.bz2|\.rpm))$/)) {
die("*** $0:\n".
" Illegal URL given: $URL\n");
} else {
$URL = $1;
}
if (!($localfile =~ /^([\w\.\_\-+\/]+)$/)) { if (!($localfile =~ /^([\w\.\_\-+\/]+)$/)) {
die("*** $0:\n". die("*** $0:\n".
" Illegal local filename given: $localfile\n"); " Illegal local filename given: $localfile\n");
...@@ -123,13 +125,21 @@ if (!($localfile =~ /^([\w\.\_\-+\/]+)$/)) { ...@@ -123,13 +125,21 @@ if (!($localfile =~ /^([\w\.\_\-+\/]+)$/)) {
# cause thats the correct thing to do. Too bad perl does not have a # cause thats the correct thing to do. Too bad perl does not have a
# getgrouplist function like the C library. # getgrouplist function like the C library.
# #
my $glist = `id -G $user`; my $glist;
if ($glist =~ /^([\d ]*)$/) {
$glist = $1; if (defined($grouplist)) {
$glist = join(" ", split(",", $grouplist));
} }
else { else {
die("*** $0:\n". $glist = `id -G $user`;
" Unexpected results from 'id -G $user': $glist\n");
if ($glist =~ /^([\d ]*)$/) {
$glist = $1;
}
else {
die("*** $0:\n".
" Unexpected results from 'id -G $user': $glist\n");
}
} }
# Need to split off the first group and create a proper list for $GUID. # Need to split off the first group and create a proper list for $GUID.
...@@ -163,9 +173,14 @@ if (! $pid) { ...@@ -163,9 +173,14 @@ if (! $pid) {
# Give parent a chance to react. # Give parent a chance to react.
sleep(1); sleep(1);
exec("nice -15 $WGET -q -O $localfile $URL"); open(GET, "| nice -15 $WGET --no-check-certificate -q -O $localfile -i -")
die("Could not exec wget!\n"); or die("Cannot start $WGET\n");
print GET "$URL\n";
if (!close(GET)) {
exit(1);
}
exit(0);
} }
# #
...@@ -195,7 +210,14 @@ if (($exit_status & 0xff) == SIGKILL) { ...@@ -195,7 +210,14 @@ if (($exit_status & 0xff) == SIGKILL) {
# #
system("$CHMOD g+w $localfile") == 0 system("$CHMOD g+w $localfile") == 0
or die ("*** ERROR - Unable to change permissions on $localfile!"); or die ("*** ERROR - Unable to change permissions on $localfile!");
}
if ($hashit) {
my $hashfile = $localfile . ".sha1";
system("$SHA1 $localfile > $hashfile");
}
if ($?) {
die("Could not generate sha1 hash of $localfile\n");
}
}
exit($exit_status >> 8); exit($exit_status >> 8);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment