Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

windows - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 "
 pause "}' ${lista} >> cyg-reinstall-${A}.bat

# execution permission for the script
chmod +x cyg-reinstall-${A}.bat

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[5] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...