aboutsummaryrefslogtreecommitdiffstats
path: root/src/getname.sh
blob: 3bd5bf647afedbca340bc4ec3e2ca930d3e3b5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh

# Usage:
#   getname.sh
#       Returns the list of all known .udeb files.
#   getname.sh [name]
#       Returns the canonical name of a package name.

set -ue

if [ $# -gt 0 ]; then
    name="${1#src/}"
    case "$1" in
        src/*-udeb/*) name="${name%%/*}";;
        *-udeb);;
        *) name="${name%.udeb}"; name="${name%%_*}-udeb";;
    esac
    echo $name
else
    for dir in src/*-udeb/; do
    if [ -r "$dir/debian/files" ]; then
        echo src/$(cut -d' ' -f1 "$dir/debian/files")
    else
        deb_arch=$(dpkg-architecture -qDEB_HOST_ARCH ${ARCH:+-a$ARCH})
        sed -nr "s@^(\S+) \(([0-9.]+)\).*@src/\1_\2_${deb_arch}.udeb@p" "$dir/debian/changelog"
    fi
    done
fi