clarify licensing
[distro-functions] / src / identify-distros
index 9c2221f43b7826137f1bbe3206984321fa3356eb..4e461b014ea74113a183cd49e73f5aa1f55517a3 100644 (file)
@@ -1,5 +1,12 @@
 #!/bin/bash
-# Copyright (C) 2014 Ian Kelling
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -91,9 +98,34 @@ EOF
     fi
   done < <(echo "$policy" | sed -rn "$expression" | sort -rn || [[ $? == 141 ]])
   echo "$shortest"
-
 }
 
+# formatted for use in pfile() in package-manager-abstractions
+positive-origins() {
+  isdeb || return 0
+  local archive expression pri name highpri shortest
+  local policy="${1:-$(apt-cache policy)}" || return $?
+  # a = archive
+  # n = codename
+  # o = origin
+  # c = component (licensing component)
+  # l = label (Debian{,-Security,-Updates})
+  read -rd '' expression <<EOF ||:
+/^ *([-0-9]+).*/{s/^ *([-0-9]+).*/\1/;h}
+/^.*o=([^,]+).*/{s/^.*o=([^,]+).*/ \1/;H;x;s/\n//;p}
+EOF
+  origins=
+  while read -r pri name; do
+    if (( pri > 0 )); then
+      if [[ ! $origins ]]; then
+        origins=$name
+      else
+        origins+=,$name
+      fi
+    fi
+  done < <(echo "$policy" | sed -rn "$expression" | sort -rn || [[ $? == 141 ]])
+  echo $origins
+}
 
 isdebian-testing() {
   [[ $(debian-archive) == testing ]]
@@ -118,6 +150,12 @@ debian-codename-compat() {
     etiona)
       echo bionic
       ;;
+    nabia)
+      echo focal
+      ;;
+    aramo)
+      echo jammy
+      ;;
     *)
       echo $n
       ;;