Apt independant!

Except for virtual packages
Still dpkg dependant though.
You can now specify the variable DEBIAN_DB that holds a package list
(like what you can find in /var/lib/dpkg/available or in
$DEBIAN_MIRROR/dist/$CODENAME/main/binary-$ARCH/Packages.$EXT)
This commit is contained in:
Geoffrey Frogeye 2016-11-20 17:54:59 +01:00
parent 2803838314
commit 033f2ff159

View file

@ -4,8 +4,10 @@ ARCH=$(dpkg --print-architecture)
DEBLOC_DB=$HOME/.config/debloc/$ARCH DEBLOC_DB=$HOME/.config/debloc/$ARCH
DEBLOC_ROOT=$HOME/.debloc/$ARCH DEBLOC_ROOT=$HOME/.debloc/$ARCH
# TODO Configurable if [ -z $DEBIAN_MIRROR ]; then
DEBIAN_MIRROR=http://debian.polytech-lille.fr/debian DEBIAN_MIRROR=$(cat /etc/apt/sources.list | grep '^deb ' | grep main | grep -v security | grep -v updates | grep -v backports)
DEBIAN_MIRROR=$(echo $DEBIAN_MIRROR | head -1 | cut -d ' ' -f 2 | sed 's/\w\+:\/\///')
fi
mkdir -p $DEBLOC_DB &> /dev/null mkdir -p $DEBLOC_DB &> /dev/null
mkdir -p $DEBLOC_ROOT &> /dev/null mkdir -p $DEBLOC_ROOT &> /dev/null
@ -17,7 +19,11 @@ export QT_QPA_PLATFORM_PLUGIN_PATH="$DEBLOC_ROOT/usr/lib/x86_64-linux-gnu/qt5/pl
# Tell if a package exists # Tell if a package exists
function _debloc-exists { # package function _debloc-exists { # package
LANG=C apt-cache show $1 &> /dev/null if [ -f $DEBIAN_DB ]; then
grep "^Package: $1\$" $DEBIAN_DB --quiet
else
dpkg --status $1 &> /dev/null
fi
if [ $? == 0 ]; then if [ $? == 0 ]; then
return 1 return 1
else else
@ -29,12 +35,16 @@ function _debloc-exists { # package
# If not a virtual package, return the input # If not a virtual package, return the input
function _debloc-filterVirtual { # package function _debloc-filterVirtual { # package
pkg=$1 pkg=$1
LANG=C apt-cache policy $1 | grep "Candidate" | grep "(none)" > /dev/null if [[ -n $DEBIAN_DB && -f $DEBIAN_DB ]]; then
if [ $? == 0 ]; then
# TODO This is not really accurate
LANG=C apt-cache showpkg $pkg | tail -1 | cut -d ' ' -f 1
else
echo $pkg echo $pkg
else
LANG=C apt-cache policy $1 | grep "Candidate" | grep "(none)" > /dev/null
if [ $? == 0 ]; then
# TODO This is not really accurate
LANG=C apt-cache showpkg $pkg | tail -1 | cut -d ' ' -f 1
else
echo $pkg
fi
fi fi
return 0 return 0
} }
@ -50,19 +60,30 @@ function _debloc-locallyInstalled { # package
# Tell if a package is installed system-wide # Tell if a package is installed system-wide
function _debloc-globallyInstalled { # package function _debloc-globallyInstalled { # package
LANG=C apt-cache policy $1 | grep "Installed" | grep "(none)" > /dev/null dpkg --status $1 | grep '^Status:' | grep 'not-installed' --quiet
return $? if [ $? != 0 ]; then
return 1
else
return 0
fi
} }
# Get informations about a package # Get informations about a package
function _debloc-packageShow { # package function _debloc-packageShow { # package
LANG=C apt-cache show $1 | while read line; do pkg=$1
if [ "$line" == '' ]; then if [[ -n $DEBIAN_DB && -f $DEBIAN_DB ]]; then
break startline=$(grep "^Package: ${pkg}\$" $DEBIAN_DB --line-number | cut -d ':' -f 1)
fi sed -n $startline,$(expr $startline + 100)p $DEBIAN_DB | while read line; do
echo "$line" if [ -z "$line" ]; then
done return 0
return 0 fi
echo $line
done
return 1
else
dpkg --print-avail $pkg
return 0
fi
} }
# Get the path of a package # Get the path of a package
@ -127,6 +148,7 @@ function _debloc-install { # package
echo "→ Downloading" echo "→ Downloading"
url=${DEBIAN_MIRROR}/$(_debloc-packagePath $pkg) url=${DEBIAN_MIRROR}/$(_debloc-packagePath $pkg)
DEB_FILE=$(mktemp) &> /dev/null DEB_FILE=$(mktemp) &> /dev/null
echo $url
wget "$url" --quiet -O $DEB_FILE wget "$url" --quiet -O $DEB_FILE
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "→ Failed!" echo "→ Failed!"
@ -152,7 +174,7 @@ function _debloc-install { # package
# Get the dependencies of a package # Get the dependencies of a package
function _debloc-packageDeps { # package function _debloc-packageDeps { # package
LANG=C apt-cache show $1 | grep '^Depends:' | sed 's/Depends: //' | sed 's/, /\n/g' | cut -d ' ' -f 1 _debloc-packageShow $1 | grep '^Depends:' | sed 's/Depends: //' | sed 's/, /\n/g' | cut -d ' ' -f 1
return 0 return 0
} }