1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 19:51:17 +00:00

* A better server-side release upload script.

svn path=/nixpkgs/trunk/; revision=615
This commit is contained in:
Eelco Dolstra 2004-01-06 16:47:28 +00:00
parent 91aafbcae4
commit b75f6860da
2 changed files with 99 additions and 1 deletions

View file

@ -0,0 +1,98 @@
#! /usr/bin/perl -w
use strict;
# Global settings.
my $releasesDir = "/home/eelco/public_html/test";
umask 0002;
sub printResult {
my $result = shift;
print "Content-Type: text/plain\n\n";
print "$result\n";
}
my $args = $ENV{"PATH_INFO"};
# Parse command.
die unless $args =~ /^\/([a-z]+)\/(.*)$/;
my $command = $1;
$args = $2;
# Perform the command.
# Start creation of a release.
if ($command eq "create") {
die unless $args =~ /^([A-Za-z0-9-][A-Za-z0-9-\.]*)$/;
my $releaseName = $1;
my $uniqueNr = int (rand 1000000);
my $sessionName = "tmp-$uniqueNr-$releaseName";
my $releaseDir = "$releasesDir/$sessionName";
mkdir $releaseDir, 0775 or die "cannot create $releaseDir: $!";
printResult "$sessionName";
}
# Upload a file to a release.
elsif ($command eq "upload") {
die unless $args =~ /^([A-Za-z0-9-][A-Za-z0-9-\.]*)((\/[A-Za-z0-9-][A-Za-z0-9-\.]*)+)$/;
my $sessionName = $1;
my $path = $2;
my $fullPath = "$releasesDir/$sessionName/$path";
open OUT, ">$fullPath" or die "cannot create $fullPath: $!";
while (<STDIN>) {
print OUT "$_" or die;
}
close OUT or die;
printResult "ok";
}
# Finish the release.
elsif ($command eq "finish") {
die unless $args =~ /^([A-Za-z0-9-][A-Za-z0-9-\.]+)$/;
my $sessionName = $1;
die unless $sessionName =~ /^tmp-\d+-(.*)$/;
my $releaseName = $1;
my $releaseDir1 = "$releasesDir/$sessionName";
my $releaseDir2 = "$releasesDir/$releaseName";
if (-d $releaseDir2) {
my $uniqueNr = int (rand 1000000);
my $releaseDir3 = "$releasesDir/replaced-$uniqueNr-$releaseName";
rename $releaseDir2, $releaseDir3
or die "cannot rename $releaseDir2 to $releaseDir3";
}
rename $releaseDir1, $releaseDir2
or die "cannot rename $releaseDir1 to $releaseDir2";
printResult "$releaseName";
}
# Check for release existence.
elsif ($command eq "exists") {
die unless $args =~ /^([A-Za-z0-9-][A-Za-z0-9-\.]*)$/;
my $releaseName = $1;
my $releaseDir = "$releasesDir/$releaseName";
if (-d $releaseDir) {
printResult "yes";
} else {
printResult "no";
}
}
else {
die "invalid command";
}

View file

@ -5,7 +5,7 @@ use strict;
my $uploadpath = $ENV{"PATH_INFO"};
# Sanitise upload path.
die unless $uploadpath =~ /^(\/[A-Za-z0-9-][A-Za-z0-9-\.]+)+$/;
die unless $uploadpath =~ /^(\/[A-Za-z0-9-][A-Za-z0-9-\.]*)+$/;
my $dst = "/home/eelco/public_html/nix/$uploadpath";
my $tmp = "${dst}_$$";