From 6f809839633ab4e3434df7eb125cc4d5d0b406b7 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Fri, 22 Mar 2019 10:44:48 -0700 Subject: [PATCH] androidenv: update generate.sh to use nix-shell and fail on error Update generate.sh to run using nix-shell. Also make it fail with meaningful output instead of writing empty output files. This is extracted from https://github.com/NixOS/nixpkgs PR 58131. This relies on the shebang being used. --- .../development/mobile/androidenv/generate.sh | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) mode change 100644 => 100755 pkgs/development/mobile/androidenv/generate.sh diff --git a/pkgs/development/mobile/androidenv/generate.sh b/pkgs/development/mobile/androidenv/generate.sh old mode 100644 new mode 100755 index 1c55734f5f42..895a741adffe --- a/pkgs/development/mobile/androidenv/generate.sh +++ b/pkgs/development/mobile/androidenv/generate.sh @@ -1,16 +1,36 @@ -#!/bin/sh -e +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl libxslt + +set -e + +die() { + echo "$1" >&2 + exit 1 +} + +fetch() { + local url="https://dl.google.com/android/repository/$1" + echo "$url -> $2" + curl -s "$url" -o "$2" || die "Failed to fetch $url" +} + +pushd "$(dirname "$0")" &>/dev/null || exit 1 + +mkdir -p xml # Convert base packages -curl https://dl.google.com/android/repository/repository2-1.xml -o xml/repository2-1.xml +fetch repository2-1.xml xml/repository2-1.xml xsltproc convertpackages.xsl xml/repository2-1.xml > generated/packages.nix # Convert system images for img in android android-tv android-wear android-wear-cn google_apis google_apis_playstore do - curl https://dl.google.com/android/repository/sys-img/$img/sys-img2-1.xml -o xml/$img-sys-img2-1.xml + fetch sys-img/$img/sys-img2-1.xml xml/$img-sys-img2-1.xml xsltproc --stringparam imageType $img convertsystemimages.xsl xml/$img-sys-img2-1.xml > generated/system-images-$img.nix done # Convert system addons -curl https://dl.google.com/android/repository/addon2-1.xml -o xml/addon2-1.xml +fetch addon2-1.xml xml/addon2-1.xml xsltproc convertaddons.xsl xml/addon2-1.xml > generated/addons.nix + +popd &>/dev/null