about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux/lsb-release
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-08-14 00:20:49 +0000
committerAlyssa Ross <hi@alyssa.is>2019-08-14 00:23:16 +0000
commit4999a38db7c5de0ea9f514a12ecd4133cce647f3 (patch)
treebbb659ab07fda4c9b98053499b7e3f046ac6d5dc /nixpkgs/pkgs/os-specific/linux/lsb-release
parentf9abd30e11337cf07034f2cc8ad1691aa4a69386 (diff)
parent8746c77a383f5c76153c7a181f3616d273acfa2a (diff)
downloadnixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar.gz
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar.bz2
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar.lz
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar.xz
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.tar.zst
nixlib-4999a38db7c5de0ea9f514a12ecd4133cce647f3.zip
Merge commit '8746c77a383f5c76153c7a181f3616d273acfa2a'
Diffstat (limited to 'nixpkgs/pkgs/os-specific/linux/lsb-release')
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lsb-release/lsb_release.sh190
2 files changed, 203 insertions, 26 deletions
diff --git a/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix b/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix
index 34dae105a8dd..7ab10bfac124 100644
--- a/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix
+++ b/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix
@@ -1,34 +1,21 @@
-{ stdenv, fetchurl, perl, coreutils, getopt, makeWrapper }:
+{ substituteAll, lib
+, coreutils, getopt
+}:
 
-stdenv.mkDerivation rec {
-  version = "1.4";
-  name = "lsb-release-${version}";
+substituteAll {
+  name = "lsb_release";
 
-  src = fetchurl {
-    url = "mirror://sourceforge/lsb/${name}.tar.gz";
-    sha256 = "0wkiy7ymfi3fh2an2g30raw6yxh6rzf6nz2v90fplbnnz2414clr";
-  };
-
-  preConfigure = ''
-    substituteInPlace help2man \
-      --replace /usr/bin/perl ${perl}/bin/perl
-  '';
-
-  installFlags = [ "prefix=$(out)" ];
-
-  nativeBuildInputs  = [ makeWrapper perl ];
+  src = ./lsb_release.sh;
 
-  buildInputs = [ coreutils getopt ];
+  dir = "bin";
+  isExecutable = true;
 
-  # Ensure utilities used are available
-  preFixup = ''
-    wrapProgram $out/bin/lsb_release --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils getopt ]}
-  '';
+  inherit coreutils getopt;
 
-  meta = {
+  meta = with lib; {
     description = "Prints certain LSB (Linux Standard Base) and Distribution information";
-    homepage = http://www.linuxfoundation.org/collaborate/workgroups/lsb;
-    license = [ stdenv.lib.licenses.gpl2Plus stdenv.lib.licenses.gpl3Plus ];
-    platforms = stdenv.lib.platforms.linux;
+    license = [ licenses.mit ];
+    maintainers = with maintainers; [ primeos ];
+    platforms = platforms.linux;
   };
 }
diff --git a/nixpkgs/pkgs/os-specific/linux/lsb-release/lsb_release.sh b/nixpkgs/pkgs/os-specific/linux/lsb-release/lsb_release.sh
new file mode 100644
index 000000000000..47b449c31614
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lsb-release/lsb_release.sh
@@ -0,0 +1,190 @@
+#! @shell@
+
+set -o errexit
+set -o nounset
+
+show_help() {
+  @coreutils@/bin/cat << EOF
+Usage: lsb_release [options]
+
+Options:
+  -h, --help         show this help message and exit
+  -v, --version      show LSB modules this system supports
+  -i, --id           show distributor ID
+  -d, --description  show description of this distribution
+  -r, --release      show release number of this distribution
+  -c, --codename     show code name of this distribution
+  -a, --all          show all of the above information
+  -s, --short        show requested information in short format
+EOF
+  exit 0
+}
+
+# Potential command-line options.
+version=0
+id=0
+description=0
+release=0
+codename=0
+all=0
+short=0
+
+@getopt@/bin/getopt --test > /dev/null && rc=$? || rc=$?
+if [[ $rc -ne 4 ]]; then
+  # This shouldn't happen.
+  echo "Warning: Enhanced getopt not supported, please open an issue." >&2
+else
+  # Define all short and long options.
+  SHORT=hvidrcas
+  LONG=help,version,id,description,release,codename,all,short
+
+  # Parse all options.
+  PARSED=`@getopt@/bin/getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@"`
+
+  eval set -- "$PARSED"
+fi
+
+
+# Process each argument, and set the appropriate flag if we recognize it.
+while [[ $# -ge 1 ]]; do
+  case "$1" in
+    -v|--version)
+      version=1
+      ;;
+    -i|--id)
+      id=1
+      ;;
+    -d|--description)
+      description=1
+      ;;
+    -r|--release)
+      release=1
+      ;;
+    -c|--codename)
+      codename=1
+      ;;
+    -a|--all)
+      all=1
+      ;;
+    -s|--short)
+      short=1
+      ;;
+    -h|--help)
+      show_help
+      ;;
+    --)
+      shift
+      break
+      ;;
+    *)
+      echo "lsb_release: unrecognized option '$1'"
+      echo "Type 'lsb_release -h' for a list of available options."
+      exit 1
+      ;;
+  esac
+  shift
+done
+
+#  Read our variables.
+if [[ -e /etc/os-release ]]; then
+  . /etc/os-release
+  OS_RELEASE_FOUND=1
+else
+  # This is e.g. relevant for the Nix build sandbox and compatible with the
+  # original lsb_release binary:
+  OS_RELEASE_FOUND=0
+  NAME="n/a"
+  PRETTY_NAME="(none)"
+  VERSION_ID="n/a"
+  VERSION_CODENAME="n/a"
+fi
+
+# Default output
+if [[ "$version" = "0" ]] && [[ "$id" = "0" ]] && \
+   [[ "$description" = "0" ]] && [[ "$release" = "0" ]] && \
+   [[ "$codename" = "0" ]] && [[ "$all" = "0" ]]; then
+  if [[ "$OS_RELEASE_FOUND" = "1" ]]; then
+    echo "No LSB modules are available." >&2
+  else
+    if [[ "$short" = "0" ]]; then
+      printf "LSB Version:\tn/a\n"
+    else
+      printf "n/a\n"
+    fi
+  fi
+  exit 0
+fi
+
+# Now output the data - The order of these was chosen to match
+# what the original lsb_release used.
+
+SHORT_OUTPUT=""
+append_short_output() {
+  if [[ "$1" = "n/a" ]]; then
+    SHORT_OUTPUT+=" $1"
+  else
+    SHORT_OUTPUT+=" \"$1\""
+  fi
+}
+
+if [[ "$all" = "1" ]] || [[ "$version" = "1" ]]; then
+  if [[ "$OS_RELEASE_FOUND" = "1" ]]; then
+    if [[ "$short" = "0" ]]; then
+      echo "No LSB modules are available." >&2
+    else
+      append_short_output "n/a"
+    fi
+  else
+    if [[ "$short" = "0" ]]; then
+      printf "LSB Version:\tn/a\n"
+    else
+      append_short_output "n/a"
+    fi
+  fi
+fi
+
+if [[ "$all" = "1" ]] || [[ "$id" = "1" ]]; then
+  if [[ "$short" = "0" ]]; then
+    printf "Distributor ID:\t$NAME\n"
+  else
+    append_short_output "$NAME"
+  fi
+fi
+
+if [[ "$all" = "1" ]] || [[ "$description" = "1" ]]; then
+  if [[ "$short" = "0" ]]; then
+    printf "Description:\t$PRETTY_NAME\n"
+  else
+    append_short_output "$PRETTY_NAME"
+  fi
+fi
+
+if [[ "$all" = "1" ]] || [[ "$release" = "1" ]]; then
+  if [[ "$short" = "0" ]]; then
+    printf "Release:\t$VERSION_ID\n"
+  else
+    append_short_output "$VERSION_ID"
+  fi
+fi
+
+if [[ "$all" = "1" ]] || [[ "$codename" = "1" ]]; then
+  if [[ "$short" = "0" ]]; then
+    printf "Codename:\t$VERSION_CODENAME\n"
+  else
+    append_short_output "$VERSION_CODENAME"
+  fi
+fi
+
+if [[ "$short" = "1" ]]; then
+  # Output in one line without the first space:
+  echo "${SHORT_OUTPUT:1}"
+fi
+
+# For compatibility with the original lsb_release:
+if [[ "$OS_RELEASE_FOUND" = "0" ]]; then
+  if [[ "$all" = "1" ]] || [[ "$id" = "1" ]] || \
+     [[ "$description" = "1" ]] || [[ "$release" = "1" ]] || \
+     [[ "$codename" = "1" ]]; then
+    exit 3
+  fi
+fi