LoginSignup
2
1

More than 5 years have passed since last update.

debファイルを端末から抽出する

Posted at

Debianで、パッケージをインストールしてから消してしまっている場合。パッケージが削除されたか、何らかの理由でアップグレードしたくない場合に、再インストールにはパッケージを再生成する必要があります。

正攻法

dpkg-repackをインストールします。

# apt-get install dpkg-repack
$ fakeroot -u dpkg-repack PKGNAME

Perlがない環境の場合

redeb.shを使います。
cf: http://modmyi.com/forums/general/713564-how-repack-dpkgs.html

#!/bin/sh
#
# redeb.sh - Command line utility for rewrapping installed Debian-packages
# Copyright (C) 2003 Tommi Saviranta <tsaviran@cs.helsinki.fi>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# Version: redeb.sh v0.1.1 7-May-2003 tsaviran@cs.helsinki.fi

if [ $# -ne 1 ]; then
echo "Usage: $0 PACKAGE"
exit 0
fi

# See if such package is installed.
if [ ! -f /var/lib/dpkg/info/$1.list ]; then
echo "No such package installed."
exit 1
fi

# Create temporary directory.
mkdir "_${1}_"
cd "_${1}_"

# Get file list for this package.
for FILE in `cat "/var/lib/dpkg/info/${1}.list"`; do
test -f "$FILE" && echo "$FILE" >>filelist
done

# Copy files here.
tar -cf - `cat filelist` | tar -xf -

# Create package-info.
mkdir DEBIAN
cp /var/lib/dpkg/info/${1}.* DEBIAN
for FILE in `ls -1 DEBIAN`; do
REAL=`echo "$FILE" | cut -d '.' -f 2`
mv "DEBIAN/$FILE" "DEBIAN/$REAL"
done
test -f DEBIAN/list && rm -f DEBIAN/list

if true; then
    #Since iOS Cydia doesn't touch apt/dpkg cache stuff, dpkg status might be better here.
    dpkg --status $1|grep -v ^Status: >DEBIAN/control
else
    BEGPOS=`grep -nx "Package: $1" /var/lib/dpkg/available | cut -d ':' -f 1`
    TOTLENGTH=`wc -l /var/lib/dpkg/available | cut -d ' ' -f 1`
    tail -n `expr $TOTLENGTH - $BEGPOS + 1` /var/lib/dpkg/available >_control_
    LENGTH=`grep -nx "" _control_ | cut -d ':' -f 1 | head -n 1`
    head -n $LENGTH _control_ >DEBIAN/control
fi

# Get package info
VERSION=`grep -E "^Version:" DEBIAN/control | cut -d ' ' -f 2 | cut -d ':' -f 2`
ARCH=`grep -E "^Architecture:" DEBIAN/control | cut -d ' ' -f 2`

# Clean up.
rm -f _control_ filelist

# Create package.
cd ..
dpkg-deb -b "_${1}_" "${1}_${VERSION}_${ARCH}.deb"

# Clean up the rest.
rm -rf "_${1}_"

あとがき

動機からしてDebianではありませんが、気にしないようにしましょう。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1