Friday, November 1, 2013

Repack packages [Generate installation files from installed applications]: Ubuntu [Debian]

There is a way to repack installed packages from Ubuntu, so that the same package can be used to install application on other systems as well. Packages are nothing but installation files. Usually we end up downloading these packages for every new installation, in this post we will discuss how to avoid that.  

1) First of all we need to install fakeroot.


sudo apt-get install fakeroot
"Fakeroot" simulates the root environment for execution of commands which require root privileges otherwise. 

2) Install dpkg. dpkg is a package manager for Debian.

sudo apt-get install dpkg

3) Now next step is to repack the package.
This script requires 'package name' of application/library to repack. Usually name of packages and applications/libraries are same, but this is not true in every case. For example consider opencv which is collection of many libraries.

Package name can be confirmed using following command.

apt-cache search <package_name>
# for example
apt-cache search opencv

Having done that use following command to repack.

fakeroot -u dpkg-repack <package_name>


Entire Backup

The procedure explained above is good only if you need backup of select applications. To repack entire system you need better strategy since typing name of every single package is not that good idea. 

So to begin with, we first of all generate a list of installed packages and store that output to a text file.

dpkg --get-selections > backup.sh

The output file contains a list of packages. Every row begins with the name of package and the status of that package. We need to remove all the packages which are marked as deinstall from the list. For this you can use simple search and replace. 

Next step is to reformat this output file so that is can be as a bash script.  Delete all the occurrences of word "install" and remove all new-line characters from the file. Add "sudo fakeroot dpkg-repack " at the beginning of file and save this file as backup.sh . Change file permissions to make it executable and execute backup.sh from terminal. This will generate Debian packages for all the listed package names. 
The script should look like this,

sudo fakeroot -u dpkg-repack libjack0 libjasper-dev libjasper-java libjasper1 libjavascriptcoregtk-1.0-0 libjavascriptcoregtk-3.0-0 libjbig2dec0 libjetty-java libjline-java libjpeg-dev libjpeg-turbo8 libjpeg-turbo8-dev libjpeg8 libjpeg8-dev libjs-jquery libjsch-java libjson-glib-1.0-0 libjson0 libjte1 libjtidy-java libjudydebian1 libk5crypto3 libkadm5clnt-mit8 libkadm5srv-mit8 libkate-dev libkate1 libkateinterfaces4 libkatepartinterfaces4 libkcmutils4 libkdb5-6 libkde3support4 libkdeclarative5 libkdecore5 libkdesu5 libkdeui5 libkdewebkit5 libkdnssd4 libkemoticons4 libkeyutils1 libkfile4 libkhtml5 libkidletime4 libkio5 libkjsapi4 libkjsembed4 libklibc libkmediaplayer4 libkms1 libknewstuff2-4


No comments:

Post a Comment