3
0
Fork 0
forked from mirrors/nixpkgs

Merge branch 'chromium-updater' of https://github.com/aszlig/nixpkgs

chromium: Improve update script and update to latest versions.

Previously, we had a single hash of the whole version response from
omahaproxy.

Unfortunately the dev version is released quite frequently, so the hash
is of no use at all (we could rather directly fetch rather than
executing the script, because it will fetch all channels anyway).

This pull request adds two methods of caching:

* First of all, if a perticular version/channel is already in the
previous version of the sources.nix file, don't download it again.

* And the second method is to check if the current sha256 is already
downloaded and reads the corresponding sha256 from the lookup table.

So, this should really help to avoid flooding the download servers and
to not stress impatient users too much.
This commit is contained in:
Shea Levy 2012-08-22 06:36:33 -04:00
commit f34225c440
2 changed files with 92 additions and 30 deletions

View file

@ -1,19 +1,18 @@
# This file is autogenerated from update.sh in the same directory.
# VHASH: c9500486764a2433d0f059134a981eb9adccd3546a6f779bc0e05cdcb26d2ae6
{
dev = {
version = "22.0.1221.1";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-22.0.1221.1.tar.bz2";
sha256 = "08cx2im0ng1dg83mk8jlx4in7v8f5vsf9y2ild0i22jb20c7h31s";
version = "22.0.1229.8";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-22.0.1229.8.tar.bz2";
sha256 = "0gaa4mqvd0v4y587y6mri2f3b0rc8npmcbs9bfs4wwb8n1cp8kw0";
};
beta = {
version = "21.0.1180.57";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-21.0.1180.57.tar.bz2";
sha256 = "0idimvkrhs09x93hl8p7rddyb0ymk9f8i5jm6m3lg6ga959aj6ri";
version = "21.0.1180.79";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-21.0.1180.79.tar.bz2";
sha256 = "1jscpibv02pyqpcj6djcx0d1qwq8hcxampfqbsz8dicgjprp22c8";
};
stable = {
version = "21.0.1180.57";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-21.0.1180.57.tar.bz2";
sha256 = "0idimvkrhs09x93hl8p7rddyb0ymk9f8i5jm6m3lg6ga959aj6ri";
version = "21.0.1180.79";
url = "http://commondatastorage.googleapis.com/chromium-browser-official/chromium-21.0.1180.79.tar.bz2";
sha256 = "1jscpibv02pyqpcj6djcx0d1qwq8hcxampfqbsz8dicgjprp22c8";
};
}

View file

@ -4,16 +4,92 @@ channels_url="http://omahaproxy.appspot.com/";
bucket_url="http://commondatastorage.googleapis.com/chromium-browser-official/";
output_file="$(cd "$(dirname "$0")" && pwd)/sources.nix";
get_channels()
nix_getattr()
{
input_file="$1";
attr="$2";
var="$(nix-instantiate --eval-only -A "$attr" "$output_file")";
echo "$var" | tr -d '\\"';
}
### poor mans key/value-store :-) ###
ver_sha_table=""; # list of version:sha256
sha_lookup()
{
version="$1";
for ver_sha in $ver_sha_table;
do
if [ "x${ver_sha%:*}" = "x$version" ];
then
echo "${ver_sha##*:}";
return 0;
fi;
done;
return 1;
}
sha_insert()
{
version="$1";
sha256="$2";
ver_sha_table="$ver_sha_table $version:$sha256";
}
if [ -e "$output_file" ];
then
get_sha256()
{
channel="$1";
version="$2";
url="$3";
oldver="$(nix_getattr "$output_file" "$channel.version")";
echo -n "Checking if $oldver ($channel) is up to date..." >&2;
if [ "x$version" != "x$oldver" ];
then
echo " no, getting sha256 for new version $version:" >&2;
sha256="$(nix-prefetch-url "$url")";
else
echo " yes, keeping old sha256." >&2;
sha256="$(nix_getattr "$output_file" "$channel.sha256")";
fi;
sha_insert "$version" "$sha256"
echo "$sha256";
}
else
get_sha256()
{
nix-prefetch-url "$url";
}
fi;
get_channel_exprs()
{
for chline in $(echo "$1" | cut -d, -f-2);
do
channel="${chline%%,*}";
version="${chline##*,}";
url="${bucket_url%/}/chromium-$version.tar.bz2";
sha256="$(nix-prefetch-url "$url")";
echo -n "Checking if sha256 of version $version is cached..." >&2;
if sha256="$(sha_lookup "$version")";
then
echo "yes: $sha256" >&2;
else
echo "no." >&2;
sha256="$(get_sha256 "$channel" "$version" "$url")";
fi;
sha_insert "$version" "$sha256";
echo " $channel = {";
echo " version = \"$version\";";
@ -25,26 +101,13 @@ get_channels()
cd "$(dirname "$0")";
versions="$(curl -s "$channels_url" | sed -n -e 's/^linux,\(\([^,]\+,\)\{2\}\).*$/\1/p')";
if [ -e "$output_file" ];
then
vhash="$(echo "$versions" | sha256sum | cut -d' ' -f1)";
old_vhash="$(sed -n 's/# *VHASH: *//p' "$output_file")";
if [ "x$vhash" = "x$old_vhash" ];
then
echo "$output_file is already up to date, bailing out." >&2;
exit 1;
fi;
fi;
channels="$(get_channels "$versions")";
omaha="$(curl -s "$channels_url")";
versions="$(echo "$omaha" | sed -n -e 's/^linux,\(\([^,]\+,\)\{2\}\).*$/\1/p')";
channel_exprs="$(get_channel_exprs "$versions")";
cat > "$output_file" <<-EOF
# This file is autogenerated from update.sh in the same directory.
# VHASH: $vhash
{
$channels
$channel_exprs
}
EOF