Skip to content

Instantly share code, notes, and snippets.

@phts
Last active August 29, 2015 14:05
Show Gist options
  • Save phts/59c121b89e0480a5b606 to your computer and use it in GitHub Desktop.
Save phts/59c121b89e0480a5b606 to your computer and use it in GitHub Desktop.
Modify files in deb package
#!/bin/bash
# From http://ubuntuforums.org/showthread.php?t=636724
DEBFILE="$1"
TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "$DEBFILE" .deb`.modfied.deb
if [[ -e "$OUTPUT" ]]; then
echo "$OUTPUT exists."
rm -r "$TMPDIR"
exit 1
fi
dpkg-deb -x "$DEBFILE" "$TMPDIR"
dpkg-deb --control "$DEBFILE" "$TMPDIR"/DEBIAN
if [[ ! -e "$TMPDIR"/DEBIAN/control ]]; then
echo DEBIAN/control not found.
rm -r "$TMPDIR"
exit 1
fi
CONTROL="$TMPDIR"/DEBIAN/control
MOD=`stat -c "%y" "$CONTROL"`
nano "$CONTROL"
chmod 775 "$TMPDIR"/DEBIAN/postinst
if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then
echo Not modfied.
else
echo Building new deb...
dpkg -b "$TMPDIR" "$OUTPUT"
fi
rm -r "$TMPDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment