2012-04-04 14:45:24 +00:00
|
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
releaseUrl=http://hydra.nixos.org/job/nixpkgs/trunk/unstable/latest-finished
|
2012-04-04 14:45:24 +00:00
|
|
|
|
releasesDir=/data/releases/nixpkgs
|
2012-11-09 12:40:10 +00:00
|
|
|
|
channelsDir=/data/releases/channels
|
|
|
|
|
channelName=nixpkgs-unstable
|
2015-12-04 17:15:39 +00:00
|
|
|
|
export GIT_DIR=/home/hydra-mirror/nixpkgs-channels
|
2012-04-04 14:45:24 +00:00
|
|
|
|
curl="curl --silent --show-error --fail"
|
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
json=$($curl -L -H 'Accept: application/json' $releaseUrl)
|
2012-04-04 14:45:24 +00:00
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
releaseId=$(echo "$json" | json id)
|
|
|
|
|
if [ -z "$releaseId" ]; then echo "Failed to get release id"; exit 1; fi
|
2012-04-04 14:45:24 +00:00
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
release=$(echo "$json" | json nixname)
|
2012-04-04 14:45:24 +00:00
|
|
|
|
if [ -z "$release" ]; then echo "Failed to get release"; exit 1; fi
|
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
url=$($curl --head http://hydra.nixos.org/build/$releaseId/eval | sed 's/Location: \(.*\)\r/\1/; t; d')
|
|
|
|
|
if [ -z "$url" ]; then exit 1; fi
|
2012-04-04 14:45:24 +00:00
|
|
|
|
|
2013-08-14 10:18:43 +00:00
|
|
|
|
releaseDir=$releasesDir/$release
|
|
|
|
|
|
2013-10-09 12:04:29 +00:00
|
|
|
|
echo "release is ‘$release’ (build $releaseId), eval is ‘$url’, dir is ‘$releaseDir’" >&2
|
2013-08-21 13:45:14 +00:00
|
|
|
|
|
2015-12-04 17:15:39 +00:00
|
|
|
|
# Figure out the Git revision from which this release was
|
|
|
|
|
# built. FIXME: get this from Hydra directly.
|
|
|
|
|
git remote update nixpkgs >&2
|
|
|
|
|
shortRev=$(echo "$release" | sed 's/.*\.//')
|
|
|
|
|
rev=$(git rev-parse "$shortRev")
|
|
|
|
|
echo "revision is $rev" >&2
|
|
|
|
|
|
2012-04-04 14:45:24 +00:00
|
|
|
|
if [ -d $releaseDir ]; then
|
2013-10-09 12:04:29 +00:00
|
|
|
|
echo "release already exists" >&2
|
2012-04-04 14:45:24 +00:00
|
|
|
|
else
|
|
|
|
|
tmpDir=$releasesDir/.tmp-$release-$$
|
|
|
|
|
mkdir -p $tmpDir
|
|
|
|
|
|
|
|
|
|
echo $url > $tmpDir/src-url
|
|
|
|
|
|
2013-08-13 21:04:08 +00:00
|
|
|
|
perl -w ./mirror-channel.pl "$url/channel" "$tmpDir" \
|
2015-01-12 11:05:39 +00:00
|
|
|
|
nix-cache https://cache.nixos.org \
|
2014-09-10 12:16:36 +00:00
|
|
|
|
"$url/job/tarball/download/1"
|
2012-04-04 14:45:24 +00:00
|
|
|
|
|
2013-08-21 13:45:14 +00:00
|
|
|
|
# Extract the manual.
|
2014-09-10 12:05:26 +00:00
|
|
|
|
$curl -L $url/job/manual/output/out | bzip2 -d | nix-store --restore $tmpDir/foo
|
|
|
|
|
mv $tmpDir/foo/share/doc/nixpkgs $tmpDir/manual
|
|
|
|
|
rm -rf $tmpDir/foo
|
2013-08-21 13:45:14 +00:00
|
|
|
|
ln -s manual.html $tmpDir/manual/index.html
|
|
|
|
|
|
2012-04-04 14:45:24 +00:00
|
|
|
|
mv $tmpDir $releaseDir
|
|
|
|
|
fi
|
|
|
|
|
|
2015-09-02 09:31:13 +00:00
|
|
|
|
# Prevent concurrent writes to the channels and the Git clone.
|
|
|
|
|
exec 10>$channelsDir/.htaccess.lock
|
|
|
|
|
flock 10
|
|
|
|
|
|
2013-10-09 12:04:29 +00:00
|
|
|
|
# Copy over to nixos.org.
|
|
|
|
|
cd "$releasesDir"
|
|
|
|
|
rsync -avR . hydra-mirror@nixos.org:"$releasesDir" --delete >&2
|
|
|
|
|
|
|
|
|
|
# Update the channel.
|
|
|
|
|
htaccess=$channelsDir/.htaccess-$channelName
|
2014-08-05 10:52:18 +00:00
|
|
|
|
echo "Redirect /channels/$channelName /releases/nixpkgs/$release" > $htaccess.tmp
|
|
|
|
|
echo "Redirect /releases/nixpkgs/channels/$channelName /releases/nixpkgs/$release" >> $htaccess.tmp # obsolete
|
2012-04-04 14:45:24 +00:00
|
|
|
|
mv $htaccess.tmp $htaccess
|
2013-10-09 12:04:29 +00:00
|
|
|
|
ln -sfn $releaseDir $channelsDir/$channelName # dummy symlink
|
2013-06-17 23:23:05 +00:00
|
|
|
|
|
2015-09-02 09:31:13 +00:00
|
|
|
|
cat $channelsDir/.htaccess-nix* > $channelsDir/.htaccess
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
|
|
|
|
cd "$channelsDir"
|
|
|
|
|
rsync -avR . hydra-mirror@nixos.org:"$channelsDir" --delete >&2
|
2015-12-04 17:15:39 +00:00
|
|
|
|
|
|
|
|
|
# Update the nixpkgs-channels repo.
|
|
|
|
|
git push nixpkgs-channels "$rev:refs/heads/nixpkgs-unstable" >&2
|