modified: nfig1.py
[GalaxyCodeBases.git] / etc / iOS / redeb.sh
blobe7ce7bea57781b6e6ff32e01444b8cb5ef97e370
1 #!/bin/sh
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
26 BASENAME="${0##*/}"
27 PWD_OLD="$PWD"
28 PACKAGE="$1"
29 TEMP="/tmp/$BASENAME-$$/$PACKAGE"
31 if [ $# -ne 1 ]
32 then
33 echo "Usage: $BASENAME <PACKAGE>"
35 exit 0
38 # See if such package is installed.
39 if [ ! -f "/var/lib/dpkg/info/$PACKAGE.list" ]
40 then
41 echo "No such package installed."
43 exit 1
46 # Create temporary directory.
47 mkdir -p "$TEMP"
48 cd "$TEMP"
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
54 done
56 # Copy files here.
57 tar -cf - $(cat filelist.tmp)|tar -xf -
59 # Create package-info.
60 mkdir DEBIAN
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
75 # Get package info
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)
79 # Clean up.
80 rm -f control.tmp filelist.tmp
82 # Create package.
83 cd ..
84 dpkg-deb -b "$TEMP" "$PWD_OLD/${PACKAGE}_${VERSION}_${ARCH}.deb"
86 # Clean up the rest.
87 rm -rf "$TEMP"