virtualbox: add update script

+48 -89
+4 -4
pkgs/applications/virtualization/virtualbox/default.nix
··· 19 19 let 20 20 python = python3; 21 21 buildType = "release"; 22 - # Remember to change the extpackRev and version in extpack.nix and 23 - # guest-additions/default.nix as well. 24 - main = "59f8f5774473f593e3eb5940e2a337e0674bcd9854164b2578fd43f896260c99"; 22 + # Use maintainers/scripts/update.nix to update the version and all related hashes or 23 + # change the hashes in extpack.nix and guest-additions/default.nix as well manually. 25 24 version = "6.1.4"; 26 25 27 26 iasl' = iasl.overrideAttrs (old: rec { ··· 39 38 40 39 src = fetchurl { 41 40 url = "https://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; 42 - sha256 = main; 41 + sha256 = "59f8f5774473f593e3eb5940e2a337e0674bcd9854164b2578fd43f896260c99"; 43 42 }; 44 43 45 44 outputs = [ "out" "modsrc" ]; ··· 216 215 passthru = { 217 216 inherit version; # for guest additions 218 217 inherit extensionPack; # for inclusion in profile to prevent gc 218 + updateScript = ./update.sh; 219 219 }; 220 220 221 221 meta = {
-85
pkgs/applications/virtualization/virtualbox/update.py
··· 1 - #!/usr/bin/env nix-shell 2 - #!nix-shell -i python3 -p python3 3 - 4 - import os 5 - import re 6 - import json 7 - import urllib.request 8 - 9 - from distutils.version import LooseVersion 10 - 11 - UPSTREAM_INFO_FILE = os.path.join( 12 - os.path.dirname(os.path.abspath(__file__)), 13 - "upstream-info.json" 14 - ) 15 - 16 - 17 - def fetch_latest_version(): 18 - url = "http://download.virtualbox.org/virtualbox/LATEST.TXT" 19 - return urllib.request.urlopen(url).read().strip().decode() 20 - 21 - 22 - def load_upstream_info(): 23 - try: 24 - with open(UPSTREAM_INFO_FILE, 'r') as fp: 25 - return json.load(fp) 26 - except FileNotFoundError: 27 - return {'version': "0"} 28 - 29 - 30 - def save_upstream_info(contents): 31 - remark = "Generated using update.py from the same directory." 32 - contents['__NOTE'] = remark 33 - data = json.dumps(contents, indent=2, sort_keys=True) 34 - with open(UPSTREAM_INFO_FILE, 'w') as fp: 35 - fp.write(data + "\n") 36 - 37 - 38 - def fetch_file_table(version): 39 - url = "http://download.virtualbox.org/virtualbox/{}/SHA256SUMS" 40 - url = url.format(version) 41 - result = {} 42 - for line in urllib.request.urlopen(url): 43 - sha, name = line.rstrip().split() 44 - result[name.lstrip(b'*').decode()] = sha.decode() 45 - return result 46 - 47 - 48 - def update_to_version(version): 49 - extpack_start = 'Oracle_VM_VirtualBox_Extension_Pack-' 50 - version_re = version.replace('.', '\\.') 51 - attribute_map = { 52 - 'extpack': r'^' + extpack_start + r'[^-]+-[^.]+.vbox-extpack$', 53 - 'extpackRev': r'^' + extpack_start + r'[^-]+-([^.]+).vbox-extpack$', 54 - 'main': r'^VirtualBox-' + version_re + r'.tar.bz2$', 55 - 'guest': r'^VBoxGuestAdditions_' + version_re + r'.iso$', 56 - } 57 - table = fetch_file_table(version) 58 - new_attrs = {'version': version} 59 - for attr, searchexpr in attribute_map.items(): 60 - result = [re.search(searchexpr, key) for key in table.keys()] 61 - filtered = filter(lambda m: m is not None, result) 62 - found = [m.groups()[0] if len(m.groups()) > 0 else table[m.group(0)] 63 - for m in filtered if m is not None] 64 - 65 - if len(found) == 0: 66 - msg = "No package found for attribute {}".format(attr) 67 - raise AssertionError(msg) 68 - elif len(found) != 1: 69 - msg = "More than one package found for attribute {}: ".format(attr) 70 - msg += ', '.join(found) 71 - raise AssertionError(msg) 72 - else: 73 - new_attrs[attr] = found[0] 74 - return new_attrs 75 - 76 - 77 - info = load_upstream_info() 78 - latest = fetch_latest_version() 79 - if LooseVersion(info['version']) < LooseVersion(latest): 80 - print("Updating to version {}...".format(latest), end="", flush=True) 81 - new_attrs = update_to_version(latest) 82 - save_upstream_info(new_attrs) 83 - print(" done.") 84 - else: 85 - print("Version {} is already the latest one.".format(info['version']))
+44
pkgs/applications/virtualization/virtualbox/update.sh
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p curl common-updater-scripts nix-prefetch-scripts jq 3 + 4 + set -xeuo pipefail 5 + 6 + nixpkgs="$(git rev-parse --show-toplevel)" 7 + 8 + attr=virtualbox 9 + oldVersion="$(nix-instantiate --eval -E "with import $nixpkgs {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')" 10 + latestVersion="$(curl -sS https://download.virtualbox.org/virtualbox/LATEST.TXT)" 11 + 12 + function fileShaSum() { 13 + echo "$1" | grep -w $2 | cut -f1 -d' ' 14 + } 15 + function oldHash() { 16 + nix-instantiate --eval --strict -A "$1.drvAttrs.outputHash" | tr -d '"' 17 + } 18 + function nixFile() { 19 + nix-instantiate --eval --strict -A "${1}.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/' 20 + } 21 + 22 + if [ ! "$oldVersion" = "$latestVersion" ]; then 23 + shaSums=$(curl -sS https://download.virtualbox.org/virtualbox/$latestVersion/SHA256SUMS) 24 + 25 + virtualBoxShaSum=$(fileShaSum "$shaSums" "VirtualBox-$latestVersion.tar.bz2") 26 + extpackShaSum=$(fileShaSum "$shaSums" "Oracle_VM_VirtualBox_Extension_Pack-$latestVersion.vbox-extpack") 27 + guestAdditionsShaSum=$(fileShaSum "$shaSums" "*VBoxGuestAdditions_$latestVersion.iso") 28 + 29 + virtualboxNixFile=$(nixFile ${attr}) 30 + extpackNixFile=$(nixFile ${attr}Extpack) 31 + guestAdditionsNixFile=$(nixFile linuxPackages.${attr}GuestAdditions) 32 + 33 + extpackOldShaSum=$(oldHash ${attr}Extpack) 34 + guestAdditionsOldShaSum=$(oldHash linuxPackages.${attr}GuestAdditions.src) 35 + 36 + update-source-version $attr $latestVersion $virtualBoxShaSum 37 + sed -i -e 's|value = "'$extpackOldShaSum'"|value = "'$extpackShaSum'"|' $extpackNixFile 38 + sed -i -e 's|sha256 = "'$guestAdditionsOldShaSum'"|sha256 = "'$guestAdditionsShaSum'"|' $guestAdditionsNixFile 39 + 40 + git add $virtualboxNixFile $extpackNixFile $guestAdditionsNixFile 41 + git commit -m "$attr: ${oldVersion} -> ${latestVersion}" 42 + else 43 + echo "$attr is already up-to-date" 44 + fi