if (( ${#shortest} > ${#name} )); then
shortest=$name
fi
- done < <(echo "$policy" | sed -rn "$expression" | sort -rn)
+ done < <(echo "$policy" | sed -rn "$expression" | sort -rn || [[ $? == 141 ]])
echo "$shortest"
}
isdeb || return 0
local policy="$(apt-cache policy)" || return $?
archive=$(debian-archive "$policy")
- echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q"
+ echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" || [[ $? == 141 ]]
}
debian-codename-compat() {
local n=$(debian-codename)
flidas)
echo xenial
;;
+ etiona)
+ echo bionic
+ ;;
*)
echo $n
;;
}
elif command -v apt-get &>/dev/null; then
+ plock-wait() {
+ local i
+ i=0
+ while fuser /var/lib/dpkg/lock &>/dev/null; do
+ sleep 1
+ i=$(( i+1 ))
+ if (( i > 300 )); then
+ echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
+ return 1
+ fi
+ done
+ }
pcheck() {
- if dpkg -s -- "$@" | grep -Fx "Status: install ok installed" &>/dev/null; then
+ for arg; do
+ if [[ $1 == -* ]]; then
+ shift
+ else
+ break
+ fi
+ done
+ if dpkg -s -- "$@" |& grep -Fx "Status: install ok installed" &>/dev/null; then
return 1
fi
return 0
}
pi() {
pcheck "$@" || return 0
- while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
pupdate
local s; [[ $EUID != 0 ]] && s=sudo
+ if [[ $- != *i* ]]; then
+ echo pi "$@"
+ fi
$s $PI_PREFIX apt-get -y install --purge --auto-remove "$@"
}
pi-nostart() {
+ local ret=
pcheck "$@" || return 0
- while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+ plock-wait
pupdate
local s; [[ $EUID != 0 ]] && s=sudo
local f=/usr/sbin/policy-rc.d
- $s dd of=$f <<EOF
+ $s dd of=$f 2>/dev/null <<EOF
#!/bin/sh
exit 101
EOF
$s chmod +x $f
- $s apt-get -y install --purge --auto-remove "$@"
+ if [[ $- != *i* ]]; then
+ echo pi-nostart "$@"
+ fi
+ $s apt-get -y install --purge --auto-remove "$@" || ret=$?
$s rm $f
+ return $ret
}
pf() {
# package name and descriptions
}
pu() {
local s; [[ $EUID != 0 ]] && s=sudo
- while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+ local needed=false
+ for arg; do
+ if dpkg -s -- "$arg" &>/dev/null; then
+ needed=true
+ break
+ fi
+ done
+ $needed || return 0
+ plock-wait
$s apt-get -y remove --purge --auto-remove "$@"
# seems slightly redundant, but it removes more stuff sometimes.
$s apt-get -y autoremove
}
pup() { # upgrade
- while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+ plock-wait
pupdate
local s; [[ $EUID != 0 ]] && s=sudo
$s apt-get -y dist-upgrade --purge --auto-remove "$@"