Skip to content

Instantly share code, notes, and snippets.

@tehsausage
Last active August 6, 2020 10:19
Show Gist options
  • Save tehsausage/a045a7e31053972b744cdfe4f9140d34 to your computer and use it in GitHub Desktop.
Save tehsausage/a045a7e31053972b744cdfe4f9140d34 to your computer and use it in GitHub Desktop.
debian package checkpoint-based metapackaging
Scripts to generate meta-packages based on packages installed between two checkpoints.
Step 1) Run 'pkg-snap-before.sh'
Step 2) Install packages
Step 3) Run 'pkg-snap-after.sh'
Step 4) Run 'pkg-snap-generate.sh my-meta-package' to generate and install.
Example session:
$ pkg-snap-before.sh
Snapshotted 587 packages
$ sudo apt install libfarstream-0.2-dev libgstreamer1.0-dev
[ ... ]
Setting up gir1.2-gstreamer-1.0:amd64 (1.16.2-2) ...
Setting up libgstreamer1.0-dev:amd64 (1.16.2-2) ...
Setting up gir1.2-farstream-0.2:amd64 (0.2.8-5) ...
Setting up libfarstream-0.2-dev (0.2.8-5) ...
$ pkg-snap-after.sh
Snapshotted 589 packages
New packages: 2
libfarstream-0.2-dev
libgstreamer1.0-dev
Run pkg-snap-generate.sh <pkg-name> to generate and install meta-package.
$ pkg-snap-generate.sh foobar-deps
[ ... ]
Package: foobar-deps
Depends: libfarstream-0.2-dev,libgstreamer1.0-dev,
Ready to install meta-package 'foobar-deps'.
Continue? [Y/n]
[ ... ]
Setting up foobar-deps (1.0) ...
Marking dependencies as auto-installed...
libfarstream-0.2-dev set to automatically installed.
libgstreamer1.0-dev set to automatically installed.
=================================
To edit already installed meta-packages:
Step 1) Run 'pkg-snap-pop.sh my-meta-package'
Step 2) Install/uninstall packages as desireed
Step 3) Run 'pkg-snap-generate.sh my-meta-package' to re-generate and re-install the meta-package
#!/bin/sh
[ -e "/tmp/pkg-snap/before.txt" ] || { echo "Run pkg-snap-before.sh first"; exit 1; }
apt-mark showmanual > /tmp/pkg-snap/after.txt
COUNT=`wc -l /tmp/pkg-snap/after.txt | cut -f 1 -d ' '`
echo "Snapshotted $COUNT packages"
comm --nocheck-order -1 -3 /tmp/pkg-snap/before.txt /tmp/pkg-snap/after.txt > /tmp/pkg-snap/new.txt
NEWCOUNT=`wc -l /tmp/pkg-snap/new.txt | cut -f 1 -d ' '`
echo "New packages: $NEWCOUNT"
echo ""
cat /tmp/pkg-snap/new.txt
if [ $NEWCOUNT -ne 0 ]; then
echo ""
echo "Run pkg-snap-generate.sh <pkg-name> to generate and install meta-package."
fi
#!/bin/sh
mkdir -p /tmp/pkg-snap/
apt-mark showmanual > /tmp/pkg-snap/before.txt
COUNT=`wc -l /tmp/pkg-snap/before.txt | cut -f 1 -d ' '`
echo "Snapshotted $COUNT packages"
#!/bin/sh
[ "$#" -eq 1 ] || { echo "Usage: $0 <pkg-name>"; exit 1; }
[ -e "/tmp/pkg-snap/before.txt" ] || { echo "Run pkg-snap-before.sh first"; exit 1; }
[ -e "/tmp/pkg-snap/after.txt" ] || { echo "Run pkg-snap-after.sh first"; exit 1; }
[ -e "/tmp/pkg-snap/new.txt" ] || comm --nocheck-order -1 -3 /tmp/pkg-snap/before.txt /tmp/pkg-snap/after.txt > /tmp/pkg-snap/new.txt
CONTROL=/tmp/pkg-snap/equivs-control
DEPLIST=`cat /tmp/pkg-snap/new.txt | tr '\n' ','`
PKGNAME=$1
if [ "$DEPLIST" = "" ]; then
echo "No packages to install."
echo "Install some packages and run pkg-snap-after.sh first."
exit 1
fi
echo "Package: $PKGNAME" > $CONTROL
echo "Description: pkg-snap generated meta-package" >> $CONTROL
echo "Depends: $DEPLIST" >> $CONTROL
rm /tmp/pkg-snap/*.deb
( cd /tmp/pkg-snap/; equivs-build $CONTROL; exit $? ) || exit $?
echo ""
cat $CONTROL
echo ""
echo "Ready to install meta-package '$PKGNAME'."
while true; do
read -p "Continue? [Y/n] " yn
case $yn in
[Nn]* ) exit 1;;
* ) break;;
esac
done
echo ""
echo "Installing meta-package..."
sudo apt-get install /tmp/pkg-snap/*.deb && { echo "Marking dependencies as auto-installed..."; sudo apt-mark auto `cat /tmp/pkg-snap/new.txt`; }
#!/bin/sh
[ "$#" -eq 1 ] || { echo "Usage: $0 <pkg-name>"; exit 1; }
PKGNAME="$1"
PKGINFO=`apt-cache show "$PKGNAME"`
[ $? -eq 0 ] || { echo "Package '$PKGNAME' not found"; exit $?; }
NAMELINE=`echo "$PKGINFO" | grep '^Package:' -m 1`
[ $? -eq 0 ] || exit $?
PKGNAME=`echo "$NAMELINE" | sed 's/^Package: //'`
[ $? -eq 0 ] || exit $?
DESCLINE=`echo "$PKGINFO" | grep '^Description\(:\|-en\)' -m 1 || echo "Description: "`
DEPLINE=`echo "$PKGINFO" | grep '^Depends:' -m 1`
[ $? -eq 0 ] || exit $?
DEPS=`echo "$DEPLINE" | sed 's/^Depends: //' | sed 's/, /\n/g'`
[ $? -eq 0 ] || exit $?
echo "Package found: $PKGNAME"
echo "$DESCLINE"
echo ""
echo "Dependencies:"
echo "$DEPS"
echo ""
echo "Ready to uninstall meta-package and mark dependencies."
while true; do
read -p "Continue? [Y/n] " yn
case $yn in
[Nn]* ) exit 1;;
* ) break;;
esac
done
echo ""
echo "Uninstalling meta-package..."
sudo apt-get -y remove "$PKGNAME"
echo ""
pkg-snap-before.sh
echo ""
echo "Marking dependencies as manually-installed..."
sudo apt-mark manual `echo $DEPS`
echo ""
pkg-snap-after.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment