Skip to content

Instantly share code, notes, and snippets.

@Montandalar
Created November 3, 2021 12:56
Show Gist options
  • Save Montandalar/6efae9c6b792d159f13ea5a41fdf886b to your computer and use it in GitHub Desktop.
Save Montandalar/6efae9c6b792d159f13ea5a41fdf886b to your computer and use it in GitHub Desktop.
# Remove any dependencies from a deb file
# Mostly useful for installing foreign packages. Use at own risk; without
# dependencies your package may break easily.
if [ -z "$1" ]; then
echo "No argument given"
exit 1
fi
debfile="$1"
if [ ! -f "$debfile" ]; then
echo "No such file: $debfile"
exit 2
fi
ar t "$debfile" || ( \
echo "Not in ar format? $debfile" && \
exit 3)
ctrlfile=$(ar t "$1" | grep control)
if [ -z "$ctrlfile" ]; then
echo "No control data file in deb: $debfile"
exit 4
fi
ar xf "$debfile" "$ctrlfile"
gzip -fd "$ctrlfile"
ctrlbare=$(echo "$ctrlfile" | sed 's,.gz$,,')
tar xf $ctrlbare './control' || \
(echo "Couldn't extract control out of $ctrlbare ?" && exit 5)
sed control -e '/^Depends:/d' -i
tar f "$ctrlbare" --delete './control'
tar f "$ctrlbare" --append './control'
gzip "$ctrlbare"
cp "$debfile" "${debfile}.bak"
ar d "$debfile" "$ctrlfile"
ar ra debian-binary "$debfile" "$ctrlfile"
dpkg-deb -I "$debfile"
rm -f 'control' "$ctrlbare"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment