If you want to go from 32 to 64 bit [Cygwin](http://www.cygwin.com) but keep all the packages ((At least those that are available.)), you might find yourself in a spot where you would like to export the list of cygwin packages and also be able to install cygwin with all these packages again. I will tell you how. Open your Cygwin shell and enter
grep " 1$" /etc/setup/installed.db | awk '{print $1}' > packagelist
This will dump a list of all *selected* packages and is the kind contribution of Yamakuzure-san. Earlier, I had proposed the following command:
cygcheck -c -d | sed -e "1,2d" -e 's/ .*$//' > packagelist
which will simply dump a list of *installed* packages, including all the dependencies (possibly cluttering up your cygwin backup file). In the comments below you'll see that my command worked better in one case. If you decide to try both, leave a comment about how they performed for you.
To install Cygwin 64 from such a package file, download [setup-x86_64](http://cygwin.com/setup-x86_64.exe). Of course, this will also work with the old [setup-x86.exe](http://cygwin.com/setup-x86.exe) if you are reading this just for the sake backing up your cygwin install configuration. Execute the installer with the command line parameters
./setup-x86_64 -P `awk 'NR==1{printf $1}{printf ",%s", $1}' packagelist`
The **awk** command reads your file and turns it into a comma-separated list, then this string is passed as the argument to the **-P** option of the installer. It may not be documented with great detail in the [Cygwin installer command-line options](http://cygwin.com/faq/faq.html#faq.setup.cli), but CSV is exactly what the **-P** option expects.
Since you might want to use **cygcheck** to backup your cygwin-install, you might not have **awk** and a bash shell at your disposal at the time of install. However, you should certainly have some kind of python installed already. Here is a python script that will read your packages correctly and install cygwin with them selected:
from urllib import request
import sys, getopt, subprocess
build = 'x86'
packagefile = 'packagelist'
opts, args = getopt.getopt(sys.argv[1:],'',['64','packages='])
for o,a in opts:
if o == '--64': build = 'x86_64'
if o == '--packages':
packagefile = a
setupfile = "setup-%s.exe" % build
packages = ','.join([ x.strip() for x in open(packagefile).readlines()])
r = request.urlopen("http://cygwin.com/%s" % setupfile)
open(setupfile,'wb').write(r.read())
subprocess.call([setupfile, '-P', packages ])
In fact, it first downloads the current setup executable from the cygwin server and then launches it. It accepts the option --64
to install 64 bit cygwin and the option --packages=packagelist
to select a file with a list of packages.
/etc/setup/installed.db
and all you need to do is just swap out the$1
for$2
so it lists the actual package version, like so:sed
is not really required,awk
is capable of doing the job by itself (no need for piping):