3 # http://modmyi.com/forums/general/713564-how-repack-dpkgs.html#post7205248
5 # redeb.sh - Command line utility for rewrapping installed Debian-packages
6 # Copyright (C) 2015 Ikem Krueger <ikem.krueger@gmail.com>
7 # Copyright (C) 2003 Tommi Saviranta <tsaviran@cs.helsinki.fi>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 # Version: redeb.sh v1.0.0 15-January-2015 ikem.krueger@gmail.com
29 TEMP
="/tmp/$BASENAME-$$/$PACKAGE"
33 echo "Usage: $BASENAME <PACKAGE>"
38 # See if such package is installed.
39 if [ ! -f "/var/lib/dpkg/info/$PACKAGE.list" ]
41 echo "No such package installed."
46 # Create temporary directory.
50 # Get file list for this package.
51 for FILE
in $
(cat "/var/lib/dpkg/info/$PACKAGE.list")
53 test -f "$FILE" && echo "$FILE">>filelist.tmp
57 tar -cf - $
(cat filelist.tmp
)|
tar -xf -
59 # Create package-info.
62 cp /var
/lib
/dpkg
/info
/$PACKAGE.
* DEBIAN
64 rm "DEBIAN/$PACKAGE.list"
66 TOTAL
=$
(wc -l /var
/lib
/dpkg
/available|cut
-d ' ' -f 1)
67 BEGIN
=$
(grep -nx "Package: $PACKAGE" /var
/lib
/dpkg
/available|cut
-d ':' -f 1)
69 tail -n $
(expr $TOTAL - $BEGIN + 1) /var
/lib
/dpkg
/available
>control.tmp
71 LENGTH
=$
(grep -nx "" control.tmp|cut
-d ':' -f 1|
head -n 1)
73 head -n $LENGTH control.tmp
>DEBIAN
/control
76 VERSION
=$
(grep -E "^Version:" DEBIAN
/control|cut
-d ' ' -f 2|cut
-d ':' -f 2)
77 ARCH
=$
(grep -E "^Architecture:" DEBIAN
/control|cut
-d ' ' -f 2)
80 rm -f control.tmp filelist.tmp
84 dpkg-deb
-b "$TEMP" "$PWD_OLD/${PACKAGE}_${VERSION}_${ARCH}.deb"