+# formatted for use in pfile() in package-manager-abstractions
+positive-origins() {
+ isdeb || return 0
+ local archive expression pri name highpri shortest policy
+ # In theory we might want a policy subset, we could alter this to pass
+ # it in.
+ policy="(apt-cache policy)"
+ # 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
+}