xref: /aosp_15_r20/external/toybox/scripts/probes/cmd2dpkg (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1#!/bin/bash
2
3# Show debian packages host versions of each command live in
4# (Alas, not as useful as I thought it would be.)
5
6[ -x toybox ] || { echo "no ./toybox" >&2; exit 1; }
7
8declare -A ray
9
10# Sad that this is NOT in the default path, but less dumb than /bin/sh->dash
11PATH="$PATH":/sbin:/usr/sbin
12
13# Only checks installed packages, puts anything it can't find in none:
14for i in $(./toybox)
15do
16  tty -s && echo -n . >&2
17  which $i >/dev/null || { ray["none:"]+=" $i"; continue; }
18
19  ray[$(dpkg-query -S $(readlink -f $(which $i)) | toybox cut -DF 1)]+=" $i"
20done
21
22# Print results
23for i in ${!ray[@]}
24do
25  echo $i ${ray[$i]}
26done
27