updateScript: initital work
This commit is contained in:
parent
eee070e49c
commit
3a1d52ff4f
@ -38,6 +38,11 @@
|
|||||||
, libpulseaudio
|
, libpulseaudio
|
||||||
, systemd
|
, systemd
|
||||||
, generated ? import ./sources.nix
|
, generated ? import ./sources.nix
|
||||||
|
, writeScript
|
||||||
|
, xidel
|
||||||
|
, coreutils
|
||||||
|
, gnused
|
||||||
|
, gnugrep
|
||||||
}:
|
}:
|
||||||
|
|
||||||
assert stdenv.isLinux;
|
assert stdenv.isLinux;
|
||||||
@ -62,10 +67,12 @@ let
|
|||||||
|
|
||||||
source = stdenv.lib.findFirst (sourceMatches systemLocale) defaultSource sources;
|
source = stdenv.lib.findFirst (sourceMatches systemLocale) defaultSource sources;
|
||||||
|
|
||||||
|
name = "firefox-bin-unwrapped-${version}";
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "firefox-bin-unwrapped-${version}";
|
inherit name;
|
||||||
|
|
||||||
src = fetchurl { inherit (source) url sha512; };
|
src = fetchurl { inherit (source) url sha512; };
|
||||||
|
|
||||||
@ -165,6 +172,46 @@ stdenv.mkDerivation {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
passthru.ffmpegSupport = true;
|
passthru.ffmpegSupport = true;
|
||||||
|
passthru.updateScript =
|
||||||
|
let
|
||||||
|
version = (builtins.parseDrvName name).version;
|
||||||
|
isBeta = builtins.stringLength version + 1 == builtins.stringLength (builtins.replaceStrings ["b"] ["bb"] version);
|
||||||
|
in
|
||||||
|
writeScript "update-firefox-bin" ''
|
||||||
|
PATH=${coreutils}/bin:${gnused}/bin:${gnugrep}/bin:${xidel}/bin:${curl}/bin
|
||||||
|
|
||||||
|
pushd pkgs/applications/networking/browsers/firefox-bin
|
||||||
|
|
||||||
|
tmpfile=`mktemp`
|
||||||
|
url=http://archive.mozilla.org/pub/firefox/releases/
|
||||||
|
version=`xidel -q $url --extract "//a" | \
|
||||||
|
sed s"/.$//" | \
|
||||||
|
grep "^[0-9]" | \
|
||||||
|
sort --version-sort | \
|
||||||
|
grep -v "funnelcake" | \
|
||||||
|
grep -e "${if isBeta then "b" else ""}\([[:digit:]]\|[[:digit:]][[:digit:]]\)$" | ${if isBeta then "" else "grep -v \"b\" |"} \
|
||||||
|
tail -1`
|
||||||
|
shasums=`curl --silent $url$version/SHA512SUMS`
|
||||||
|
|
||||||
|
echo "{" > $tmpfile
|
||||||
|
echo " version = \"$version\";" >> $tmpfile
|
||||||
|
echo " sources = [" >> $tmpfile
|
||||||
|
for arch in linux-x86_64 linux-i686; do
|
||||||
|
for line in `echo "$shasums" | grep $arch | grep "firefox-$version.tar.bz2$" | tr " " ":"`; do
|
||||||
|
echo " { url = \"$url$version/$arch/`echo $line | cut -d\":\" -f3`\";" >> $tmpfile
|
||||||
|
echo " locale = \"`echo $line | cut -d\":\" -f3 | sed \"s/$arch\///\" | sed \"s/\/.*//\"`\";" >> $tmpfile
|
||||||
|
echo " arch = \"$arch\";" >> $tmpfile
|
||||||
|
echo " sha512 = \"`echo $line | cut -d\":\" -f1`\";" >> $tmpfile
|
||||||
|
echo " }" >> $tmpfile
|
||||||
|
done
|
||||||
|
done
|
||||||
|
echo " ];" >> $tmpfile
|
||||||
|
echo "}" >> $tmpfile
|
||||||
|
|
||||||
|
cat $tmpfile > ${if isBeta then "beta_" else ""}sources.nix
|
||||||
|
|
||||||
|
popd
|
||||||
|
'';
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
description = "Mozilla Firefox, free web browser (binary package)";
|
description = "Mozilla Firefox, free web browser (binary package)";
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
# TODO share code with thunderbird-bin/generate_sources.rb
|
|
||||||
|
|
||||||
require "open-uri"
|
|
||||||
|
|
||||||
version =
|
|
||||||
if ARGV.empty?
|
|
||||||
$stderr.puts("Usage: ruby generate_sources.rb <version> > sources.nix")
|
|
||||||
exit(-1)
|
|
||||||
else
|
|
||||||
ARGV[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
base_path = "http://download-installer.cdn.mozilla.net/pub/firefox/releases"
|
|
||||||
|
|
||||||
Source = Struct.new(:hash, :arch, :locale, :filename)
|
|
||||||
|
|
||||||
sources = open("#{base_path}/#{version}/SHA512SUMS") do |input|
|
|
||||||
input.readlines
|
|
||||||
end.select do |line|
|
|
||||||
/\/firefox-.*\.tar\.bz2$/ === line && !(/source/ === line)
|
|
||||||
end.map do |line|
|
|
||||||
hash, name = line.chomp.split(/ +/)
|
|
||||||
Source.new(hash, *(name.split("/")))
|
|
||||||
end.sort_by do |source|
|
|
||||||
[source.locale, source.arch]
|
|
||||||
end
|
|
||||||
|
|
||||||
arches = ["linux-i686", "linux-x86_64"]
|
|
||||||
|
|
||||||
puts(<<"EOH")
|
|
||||||
# This file is generated from generate_sources.rb. DO NOT EDIT.
|
|
||||||
# Execute the following command to update the file.
|
|
||||||
#
|
|
||||||
# ruby generate_sources.rb 46.0.1 > sources.nix
|
|
||||||
|
|
||||||
{
|
|
||||||
version = "#{version}";
|
|
||||||
sources = [
|
|
||||||
EOH
|
|
||||||
|
|
||||||
sources.each do |source|
|
|
||||||
puts(%Q| { url = "#{base_path}/#{version}/#{source.arch}/#{source.locale}/firefox-#{version}.tar.bz2"; locale = "#{source.locale}"; arch = "#{source.arch}"; sha512 = "#{source.hash}"; }|)
|
|
||||||
end
|
|
||||||
|
|
||||||
puts(<<'EOF')
|
|
||||||
];
|
|
||||||
}
|
|
||||||
EOF
|
|
128
update.nix
Executable file
128
update.nix
Executable file
@ -0,0 +1,128 @@
|
|||||||
|
{ package ? null
|
||||||
|
, maintainer ? null
|
||||||
|
}:
|
||||||
|
|
||||||
|
# TODO: add assert statements
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
pkgs = import ./default.nix { };
|
||||||
|
|
||||||
|
packagesWith = cond: return: set:
|
||||||
|
pkgs.lib.flatten
|
||||||
|
(pkgs.lib.mapAttrsToList
|
||||||
|
(name: pkg:
|
||||||
|
let
|
||||||
|
result = builtins.tryEval (
|
||||||
|
if pkgs.lib.isDerivation pkg && cond name pkg
|
||||||
|
then [(return name pkg)]
|
||||||
|
else if pkg.recurseForFerivations or false || pkg.recureseForRelease or false
|
||||||
|
then packagesWith cond return pkg
|
||||||
|
else []
|
||||||
|
);
|
||||||
|
in
|
||||||
|
if result.success then result.value
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
set
|
||||||
|
);
|
||||||
|
|
||||||
|
packagesWithUpdateScriptAndMaintainer = maintainer':
|
||||||
|
let
|
||||||
|
maintainer =
|
||||||
|
if ! builtins.hasAttr maintainer' pkgs.lib.maintainers then
|
||||||
|
builtins.throw "Maintainer with name `${maintainer'} does not exist in `lib/maintainers.nix`."
|
||||||
|
else
|
||||||
|
builtins.getAttr maintainer' pkgs.lib.maintainers;
|
||||||
|
in
|
||||||
|
packagesWith (name: pkg: builtins.hasAttr "updateScript" pkg &&
|
||||||
|
(if builtins.hasAttr "maintainers" pkg.meta
|
||||||
|
then (if builtins.isList pkg.meta.maintainers
|
||||||
|
then builtins.elem maintainer pkg.meta.maintainers
|
||||||
|
else maintainer == pkg.meta.maintainers
|
||||||
|
)
|
||||||
|
else false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(name: pkg: pkg)
|
||||||
|
pkgs;
|
||||||
|
|
||||||
|
packageByName = name:
|
||||||
|
if ! builtins.hasAttr name pkgs then
|
||||||
|
builtins.throw "Package with an attribute name `${name}` does not exists."
|
||||||
|
else if ! builtins.hasAttr "updateScript" (builtins.getAttr name pkgs) then
|
||||||
|
builtins.throw "Package with an attribute name `${name}` does have an `passthru.updateScript` defined."
|
||||||
|
else
|
||||||
|
builtins.getAttr name pkgs;
|
||||||
|
|
||||||
|
packages =
|
||||||
|
if package != null then
|
||||||
|
[ (packageByName package) ]
|
||||||
|
else if maintainer != null then
|
||||||
|
packagesWithUpdateScriptAndMaintainer maintainer
|
||||||
|
else
|
||||||
|
builtins.throw "No arguments provided.\n\n${helpText}";
|
||||||
|
|
||||||
|
helpText = ''
|
||||||
|
Please run:
|
||||||
|
|
||||||
|
% nix-shell update.nix --argstr maintainer garbas
|
||||||
|
|
||||||
|
to run all update scripts for all packages that lists \`garbas\` as a maintainer
|
||||||
|
and have \`updateScript\` defined, or:
|
||||||
|
|
||||||
|
% nix-shell update.nix --argstr package garbas
|
||||||
|
|
||||||
|
to run update script for specific package.
|
||||||
|
'';
|
||||||
|
|
||||||
|
runUpdateScript = package: ''
|
||||||
|
echo -ne " - ${package.name}: UPDATING ..."\\r
|
||||||
|
${package.updateScript} &> ${(builtins.parseDrvName package.name).name}.log
|
||||||
|
CODE=$?
|
||||||
|
if [ "$CODE" != "0" ]; then
|
||||||
|
echo " - ${package.name}: ERROR "
|
||||||
|
echo ""
|
||||||
|
echo "--- SHOWING ERROR LOG FOR ${package.name} ----------------------"
|
||||||
|
echo ""
|
||||||
|
cat ${(builtins.parseDrvName package.name).name}.log
|
||||||
|
echo ""
|
||||||
|
echo "--- SHOWING ERROR LOG FOR ${package.name} ----------------------"
|
||||||
|
exit $CODE
|
||||||
|
else
|
||||||
|
rm ${(builtins.parseDrvName package.name).name}.log
|
||||||
|
fi
|
||||||
|
echo " - ${package.name}: DONE. "
|
||||||
|
'';
|
||||||
|
|
||||||
|
in pkgs.stdenv.mkDerivation {
|
||||||
|
name = "nixpkgs-update-script";
|
||||||
|
buildCommand = ''
|
||||||
|
echo ""
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
echo "Not possible to update packages using \`nix-build\`"
|
||||||
|
echo ""
|
||||||
|
echo "${helpText}"
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
exit 1
|
||||||
|
'';
|
||||||
|
shellHook = ''
|
||||||
|
echo ""
|
||||||
|
echo "Going to be running update for following packages:"
|
||||||
|
echo "${builtins.concatStringsSep "\n" (map (x: " - ${x.name}") packages)}"
|
||||||
|
echo ""
|
||||||
|
read -n1 -r -p "Press space to continue..." confirm
|
||||||
|
if [ "$confirm" = "" ]; then
|
||||||
|
echo ""
|
||||||
|
echo "Running update for:"
|
||||||
|
${builtins.concatStringsSep "\n" (map runUpdateScript packages)}
|
||||||
|
echo ""
|
||||||
|
echo "Packages updated!"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Aborting!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user