Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin save package selections for later reinstall

I was wondering if there is a way to save the current package selections for cygwin for a later reinstall or porting on a different system.

It would be really great to:

  • run a command to export a list of installed packages on an existing system
  • pass the list to the installer on another system in a way such as setup-x86_64.exe --list list.txt

I don't think the setup has such a switch, so even any type of script or batch working in this direction would be just fine.

Since the number of needed packages is very high, it should be unattended in order to consider it as a good solution!

What would be the best way to accomplish a quick reinstall like this?

like image 861
Marco Avatar asked Oct 19 '17 12:10

Marco


People also ask

Where is Cygwin packages stored?

Once you have an existing Cygwin installation, the setup.exe chooser is also used to manage your Cygwin installation. Information on installed packages is kept in the /etc/setup/ directory of your Cygwin installation; if setup.exe cannot find this directory it will act as if you have no Cygwin installation.

How do I use apt get in Cygwin?

cyg-apt: downloading: http://cygwin.mirrors.pair.com/setup-2.bz2 cyg-apt: downloading: http://cygwin.mirrors.pair.com/setup-2.ini cyg-apt: bad URL http://cygwin.mirrors.pair.com/setup-2.ini, exiting. The file is available in the source repository.

How do I add a environment variable in Cygwin?

From the Start menu, select Parameters > Control Panel > System. Select the Advanced tab and click Environment variables. Edit the PATH environment variable to add the Cygwin installation directory, for example c:\cygwin\bin; and click OK.


1 Answers

The list of installed packages is available with cygcheck. Setup does not accept a list option but you can specific the list with -P

The following code, when used with -A option will create a crafted cyg-reinstall-${Arch}.bat batch file to install all packages existing in a system.

#!/bin/bash
# Create a batch file to reinstall using setup-{ARCH}.exe
# all packages reported as incomplete

print_error=1

if [ $# -eq 1 ]
  then
    if [ $1 == "-I" ]
    then
      lista=$(mktemp)
      cygcheck -c | grep "Incomplete" > $lista
      print_error=0
    fi
    if [ $1 == "-A" ]
    then
      lista=$(mktemp)
      cygcheck -cd | sed -e "1,2d" > $lista
      print_error=0
    fi
fi

if [ $# -eq 2 ]
  then
    if [ $1 == "-f" ]
    then
      lista=$2
      print_error=0
    fi
fi

# error message if options are incorrect.
if [ $print_error -eq 1 ]
then
        echo -n "Usage : " $(basename $0)
        echo " [ -A | -I | -f filelist ]"
        echo "  create cyg-reinstall-{ARC}.bat from"
        echo "  options"
        echo "    -A  :  All packages as reported by cygcheck"
        echo "    -I  :  incomplete packages as reported by cygcheck"
        echo "    -f  :  packages in filelist (one per raw)"
        exit 1
fi

if [ $(arch) == "x86_64" ]
then
  A="x86_64"
else
  A="x86"
fi
# writing header
echo -n -e "setup-${A}.exe  " > cyg-reinstall-${A}.bat

# option  -x remove and  -P install
# for re-install packages we need both
if [ $1 == "-I" ]
then
  awk 'BEGIN{printf(" -x ")} NR==1{printf $1}{printf ",%s", $1}' ${lista} >> cyg-reinstall-${A}.bat
fi

awk 'BEGIN{printf(" -P ")} NR==1{printf $1}{printf ",%s", $1} END { printf "\r\n pause "}' ${lista} >> cyg-reinstall-${A}.bat

# execution permission for the script
chmod +x cyg-reinstall-${A}.bat
like image 156
matzeri Avatar answered Oct 27 '22 01:10

matzeri