fi
done < <(echo "$policy" | sed -rn "$expression" | sort -rn || [[ $? == 141 ]])
echo "$shortest"
-
}
+# formatted for use in pfile in brc
+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 ]]
etiona)
echo bionic
;;
+ nabia)
+ echo focal
+ ;;
*)
echo $n
;;
limittime=$(( now - 60*60*2 ))
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
if [[ -r $f ]]; then
- t=$(stat -c %Y $f )
+ t=$(stat -c %Y $f )
if (( t > limittime )); then
limittime=$t
fi
pi() {
pcheck "$@" || return 0
pupdate
- local s; [[ $EUID != 0 ]] && s=sudo
if [[ $- != *i* ]]; then
- echo pi "$@"
+ echo pi "$*"
+ fi
+ if [[ $EUID == 0 ]]; then
+ DEBIAN_FRONTEND=noninteractive apt-get -y install --purge --auto-remove "$@"
+ else
+ sudo DEBIAN_FRONTEND=noninteractive apt-get -y install --purge --auto-remove "$@"
fi
- $s $PI_PREFIX apt-get -y install --purge --auto-remove "$@"
+
}
pi-nostart() {
pcheck "$@" || return 0
plock-wait
pupdate
- local s; [[ $EUID != 0 ]] && s=sudo
local f=/usr/sbin/policy-rc.d
- $s dd of=$f 2>/dev/null <<EOF
+ if [[ $- != *i* ]]; then
+ echo pi-nostart "$@"
+ fi
+ if [[ $EUID == 0 ]]; then
+ dd of=$f 2>/dev/null <<EOF
#!/bin/sh
exit 101
EOF
- $s chmod +x $f
- if [[ $- != *i* ]]; then
- echo pi-nostart "$@"
+ chmod +x $f
+ DEBIAN_FRONTEND=noninteractive apt-get -y install --purge --auto-remove "$@" || ret=$?
+ rm $f
+ else
+ sudo dd of=$f 2>/dev/null <<EOF
+#!/bin/sh
+exit 101
+EOF
+ sudo chmod +x $f
+ sudo DEBIAN_FRONTEND=noninteractive apt-get -y install --purge --auto-remove "$@" || ret=$?
+ sudo rm $f
fi
- $s apt-get -y install --purge --auto-remove "$@" || ret=$?
- $s rm $f
return $ret
}
pf() {
fi
}
pfile() {
+ # -a = search all repos
+ local arg
+ if [[ $1 != -a ]]; then
+ arg="--filter-origins $(positive-origins)"
+ fi
local file=$1
# ucfq can tell us about config files which are not tracked
# with apt-file. but, for at least a few files I tested
# if [[ $file == /* ]] && ! ucfq -w $file | grep ::: &>/dev/null; then
# ucfq $file
- if [[ $file == */* ]]; then
- apt-file find -x "$file"\$
+ if [[ $file == /* ]]; then
+ dpkg -S "$file"
+ elif [[ $file == */* ]]; then
+ apt-file $arg find -x "$file"\$
else
- apt-file find -x /"$file"\$
+ apt-file $arg find -x /"$file"\$
update-alternatives --list "$file" 2>/dev/null
fi
}