Cygwin 离线安装程序?

Cygwin 离线安装程序?

我尝试从几台不同的计算机和网络下载了几次。当我尝试下载时,下载卡在了半途。我在哪里可以找到可靠的离线安装程序?

答案1

我有一个修改版 apt-cyg从本地存档运行安装程序。
它确实应该作为补丁提交,但一直没有时间清理它,所以就这样了。

特征

  • 离线安装
  • 设置镜像
  • 缓存包以便以后安装更快
  • 即使软件包已安装,也强制重新安装
  • 支持setup.ini / setup.bz2 /
  • 使用您选择的下载器来获取软件包(我们默认使用 rsync)
  • 扫描缓存以查找剩余内容,尽可能使用安装失败的 setup.exe 软件包。(只需确保从 setup.exe 安装时指定缓存文件夹即可)

下载

http://pastebin.com/SSTZ4ATL
或者参见这个答案的下半部分

用法:

假设您想要您的本地仓库,c:/archive/cygwin/或者/cygdrive/c/archive/cygwin/ 如果这很重要。

让我们设置一个 repo,无论下载速度如何。根据您居住的地方调整镜像,或者以最快的速度访问。

cat > /cygdrive/c/archive/cygwin/sync-with-cygwin-mirror.sh <<"EOF"
#!/bin/bash
#
###
# Choose mirror that is on http://www.cygwin.com/mirrors.html
#
# "ftp://ftp.jaist.ac.jp/pub/cygwin/"
# "ftp://ftp.sunet.se/pub/lang/cygwin/"
# "http://mirrors.kernel.org/sourceware/cygwin/"
#
# Old
# "http://sources.redhat.com/cygwin/mirrors.lst"
###
rsync --partial -va rsync://ftp.jaist.ac.jp/pub/cygwin/release/ /cygdrive/c/archive/cygwin/release/
#
#/cygdrive/c/archive/cygwin
EOF

然后运行以下命令

chmod +x /cygdrive/c/archive/cygwin/sync-with-cygwin-mirror.sh

从现在开始,只需简单操作/cygdrive/c/archive/cygwin/sync-with-cygwin-mirror.sh
即可将您的本地仓库更新至最新和最好的版本。

接下来,设置环境变量,这样setup.exe就不会混淆。

cat > /etc/setup/last-cache <<"EOF"
C:\archive\cygwin
EOF

设置默认镜像,以最快的速度运行

cat > /etc/setup/last-mirror <<"EOF"
ftp://ftp.iij.ad.jp/pub/cygwin
EOF

那就尝试一下吧!

apt-cyg find <pacakge name>
apt-cyg install <package name>

典型安装会话的示例输出(我--force在这里使用,因为这个包已经安装好了。你不需要它。只是为了展示如何使用,在这里)

$ apt-cyg install man --force
Working directory is /cygdrive/c/archive/cygwin
Mirror is ftp://ftp.iij.ad.jp/pub/cygwin
We are using the cache as package source.

Installing man
Found package man
DBG:pwd=[/cygdrive/c/archive/cygwin]pkg=[man]file=[man-1.6f-1.tar.bz2]mirror=[ftp://ftp.iij.ad.jp/pub/cygwin]install=[release/man/
man-1.6f-1.tar.bz2]
DBG:169:pwd=[/cygdrive/c/archive/cygwin/release/man]pkg=[man]file=[man-1.6f-1.tar.bz2]mirror=[ftp://ftp.iij.ad.jp/pub/cygwin]insta
ll=[release/man/man-1.6f-1.tar.bz2]
Checking md5hash [9a34daa8d8dfbf9222035b4f1952ab1d] == [9a34daa8d8dfbf9222035b4f1952ab1d]
Unpacking...
Package man requires the following packages, installing:
bash libgcc1 bzip2 coreutils gawk groff gzip less cygwin
Package bash is already installed, skipping
Package libgcc1 is already installed, skipping
Package bzip2 is already installed, skipping
Package coreutils is already installed, skipping
Package gawk is already installed, skipping
Package groff is already installed, skipping
Package gzip is already installed, skipping
Package less is already installed, skipping
Package cygwin is already installed, skipping
Package man installed

请注意因为我们已经有一个本地副本,所以它没有连接到网络,而是使用我们已知的副本。即使我们不知道我们是否拥有该包,只要包位于缓存的子目录中,apt-cyg 就会找到它,并使用 md5sum 哈希值来验证包是否损坏。

帮助:

apt-cyg: Installs and removes Cygwin packages.
  "apt-cyg install <package names>" to install packages
  "apt-cyg remove <package names>" to remove packages
  "apt-cyg update" to update setup.ini
  "apt-cyg show" to show installed packages
  "apt-cyg find <patterns>" to find packages matching patterns
  "apt-cyg describe <patterns>" to describe packages matching patterns
  "apt-cyg packageof <commands or files>" to locate parent packages
Options:
  --mirror, -m <url> : set mirror
  --cache, -c <dir>  : set cache
  --file, -f <file>  : read package names from file
  --noupdate, -u     : don't update setup.ini from mirror
  --localdiskcache   : Use local cache as source, if available. Used for offline instalation.
  --force            : Force re-installing package. USE WITH CAUTION AND CARE!
  --ForceUpdate      : Force re-initalizeing setup.ini.
  --help
  --version
  --find-setup-exe   :experemental

以下是源代码,以防 pastebin 宕机

来源

#!/bin/bash
# apt-cyg: install tool for cygwin similar to debian apt-get
# 
# Copyright (C) 2005-9, Stephen Jungels
# Modified by GreenFox
# 
# 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.
# 
# (http://www.fsf.org/licensing/licenses/gpl.html)

# this script requires some packages

WGET=`which wget 2> /dev/null`
BZIP2=`which bzip2 2> /dev/null`
TAR=`which tar 2> /dev/null`
GAWK=`which awk 2> /dev/null`
if test "-$WGET-" = "--" || test "-$BZIP2-" = "--" || test "-$TAR-" = "--" \
  || test "-$GAWK-" = "--"
then
  echo You must install wget, tar, gawk and bzip2 to use apt-cyg.
  exit 1
fi


function usage()
{
  echo apt-cyg: Installs and removes Cygwin packages.
  echo "  \"apt-cyg install <package names>\" to install packages"
  echo "  \"apt-cyg remove <package names>\" to remove packages"
  echo "  \"apt-cyg update\" to update setup.ini"
  echo "  \"apt-cyg show\" to show installed packages"
  echo "  \"apt-cyg find <patterns>\" to find packages matching patterns"
  echo "  \"apt-cyg describe <patterns>\" to describe packages matching patterns"
  echo "  \"apt-cyg packageof <commands or files>\" to locate parent packages"
  echo "Options:"
  echo "  --mirror, -m <url> : set mirror"
  echo "  --cache, -c <dir>  : set cache"
  echo "  --file, -f <file>  : read package names from file"
  echo "  --noupdate, -u     : don't update setup.ini from mirror"
  echo "  --localdiskcache   : Use local cache as source, if available. Used for offline instalation."
  echo "  --force            : Force re-installing package. USE WITH CAUTION AND CARE!"
  echo "  --ForceUpdate      : Force re-initalizeing setup.ini.  "
  echo "  --help"
  echo "  --version"
  echo "  --find-setup-exe   :experemental"
}



function version()
{
  echo "apt-cyg version 0.58 custombuild"
  echo "Written by Stephen Jungels"
  echo "Modified by GreenFox"
  echo "Copyright (c) 2005-2012.  Released under the GPL."
}

function findsetupexe()
{
  echo "Attempting to load setup.exe, or loading from network..."
  [ -e "${cache}/setup.exe" ] && echo "Try using [ ${cache}/setup.exe ]"
}

function findworkspace()
{
  # default working directory and mirror
  
  mirror="ftp://mirror.mcs.anl.gov/pub/cygwin"
  mirror="ftp://ftp.iij.ad.jp/pub/cygwin"
  cache="/cygdrive/c/archive/cygwin"
  # Note: path should be in unix format.
  
  # work wherever setup worked last, if possible
  
  if test -e /etc/setup/last-cache
  then
    tmp="`head -1 /etc/setup/last-cache`"
    cache="`cygpath -au "$tmp"`"
  fi
  
  if test -e /etc/setup/last-mirror
  then
    mirror="`head -1 /etc/setup/last-mirror`"
  fi
  if test "$localdiskcache" == "1"
  then
    echo Working directory is $cache
    echo Mirror is $mirror
    echo We are using the cache as package source.
    cd "$cache"
  else
    # Old method that uses network. Left for compatibility purpose.
    mirrordir="`echo "$mirror" | sed -e "s/:/%3a/g" -e "s:/:%2f:g"`"
    echo Working directory is $cache
    echo Mirror is $mirror
    mkdir -p "$cache/$mirrordir"
    cd "$cache/$mirrordir"
  fi
}


function getsetup() 
{
  if test "$noscripts" == "0" -a "$noupdate" == "0" -a "$localdiskcache" == "0"
  then
    touch "setup.ini"
    mv "setup.ini" "setup.ini-save"
    wget -N "$mirror/setup.bz2"
    if test -e "setup.bz2" && test $? -eq 0
    then
      bunzip2 "setup.bz2"
      mv "setup" "setup.ini"
      echo "Updated setup.ini"
    else
      wget -N "$mirror/setup.ini"
      if test -e setup.ini && test $? -eq 0
      then
        echo "Updated setup.ini"
      else
        mv "setup.ini-save" "setup.ini"
        echo "Error updating setup.ini, reverting"
      fi
    fi
  fi
}


function checkpackages()
{
  if test "-$packages-" = "--"
  then
    echo Nothing to do, exiting
    exit 0
  fi
}
function apt-cyg-func-install(){
  for pkg in $packages
    do
      already="`grep -c "^$pkg " /etc/setup/installed.db`"
      if test $already -ge 1 -a "$forceinstall" == "0"
      then
        echo "Package $pkg is already installed, skipping"
        continue
      fi
      echo ""
      echo Installing $pkg
      # look for package and save desc file
      mkdir -p "release/$pkg"
      cat setup.ini | awk > "release/$pkg/desc" -v package="$pkg" \
        'BEGIN{RS="\n\n@ "; FS="\n"} {if ($1 == package) {desc = $0; px++}} \
         END{if (px == 1 && desc != "") print desc; else print "Package not found"}' 
    
      desc=`cat "release/$pkg/desc"`
      if test "-$desc-" = "-Package not found-"
      then
        echo Package $pkg not found or ambiguous name, exiting
        rm -r "release/$pkg"
        exit 1
      fi
      echo Found package $pkg

      # download and unpack the bz2 file

      # pick the latest version, which comes first
      install=`cat "release/$pkg/desc" | awk '/^install: / { print $2; exit }'` 

      if test "-$install-" = "--"
      then
        echo "Could not find \"install\" in package description: obsolete package?"
        echo "Debug output of [$(realpath "release/$pkg/desc")]"
        echo "-----------------------------------------------------"
        cat "release/$pkg/desc"
        echo "-----------------------------------------------------"
        exit 1
      fi
      file=`basename $install`
      if test "$localdiskcache" == "1"
      then
############################################
# This section needs refactoring. TODO
############################################
        echo "DBG:pwd=[`pwd`]pkg=[$pkg]file=[$file]mirror=[$mirror]install=[$install]"
        cd "$cache"
        cd "release/$pkg"
        if ! test -e "$file"
        then
          # Scan dir for matching name
          echo "Scanning cache for leftover..."
          local leftover_file="`find "$cache" -name "$file" |head -n 1`";
          if test "$leftover_file" == "" ; then
            #
            echo "Package $pkg missing from cache. Downloading file from mirror $mirror."
            wget -nc $mirror/$install
            # The mirror might not have the file.TODO.
          else
            echo "Trying to use [$leftover_file] as alternative to [$file]"
            file="$leftover_file";
          fi
        fi
        echo "DBG:169:pwd=[`pwd`]pkg=[$pkg]file=[$file]mirror=[$mirror]install=[$install]"

          digest="`cat "desc" | awk '/^install: / { print $4; exit }'`";
          digactual="`md5sum "$file" | awk '{print $1}'`";
          echo "Checking md5hash [$digest] == [$digactual] "
          if test "$digest" != "$digactual" ;
          then
            echo "Package $pkg in cache data is broken, partial, or empty. Downloading file from mirror."
            wget -c $mirror/$install
          fi
          digactual=`md5sum $file | awk '{print $1}'`
############################################
      else
        cd "release/$pkg"
        wget -nc $mirror/$install
        digest=`cat "desc" | awk '/^install: / { print $4; exit }'` 
        digactual=`md5sum $file | awk '{print $1}'`
      fi
  
      if ! test $digest = $digactual
      then
        echo "MD5 sum did not match, exiting"
        exit 1
      fi
    
      echo "Unpacking..."
      #####
      # Dumps to root dir. We need to add code for chroot creating options
      ####
      cat "$file" | bunzip2 | tar > "/etc/setup/$pkg.lst" xvf - -C /
      gzip -f "/etc/setup/$pkg.lst"
      cd ../..
    
    
      # update the package database
    
      cat /etc/setup/installed.db | awk > /tmp/awk.$$ -v pkg="$pkg" -v bz=$file \
        '{if (ins != 1 && pkg < $1) {print pkg " " bz " 0"; ins=1}; print $0} \
         END{if (ins != 1) print pkg " " bz " 0"}'
      mv /etc/setup/installed.db /etc/setup/installed.db-save
      mv /tmp/awk.$$ /etc/setup/installed.db
    
    
      # recursively install required packages
    
      echo > /tmp/awk.$$ '/^requires: / {s=gensub("(requires: )?([^ ]+) ?", "\\2 ", "g", $0); print s}'
      requires=`cat "release/$pkg/desc" | awk -f /tmp/awk.$$`
    
      warn=0
      if ! test "-$requires-" = "--"
      then
        echo Package $pkg requires the following packages, installing:
        echo $requires
        for package in $requires
        do
          already=`grep -c "^$package " /etc/setup/installed.db`
          if test $already -ge 1
          then
            echo Package $package is already installed, skipping
            continue
          fi
          apt-cyg --noscripts install $package
          if ! test $? = 0 ; then warn=1; fi
        done
      fi
      if ! test $warn = 0
      then
        echo "Warning: some required packages did not install, continuing"
      fi
    
      # run all postinstall scripts
    
      pis=`ls "/etc/postinstall/*.sh" 2>/dev/null | wc -l`
      if test $pis -gt 0 && ! test $noscripts -eq 1
      then
        echo Running postinstall scripts
        for script in "/etc/postinstall/*.sh"
        do
          $script
          mv $script $script.done
        done
      fi
      
      echo Package $pkg installed
      done

}

function main(){
  # process options
  local noscripts=0
  local noupdate=0
  local file=""
  local dofile=0
  local command=""
  local filepackages=""
  local packages=""
  local localdiskcache=1
  local forceinstall=0

# use vars = [ noscripts noupdate localdiskcache forceinstall file dofile command packages ]
  while test $# -gt 0
  do
  case "$1" in
    --mirror|-m)
      echo "$2" > /etc/setup/last-mirror
      shift ; shift
    ;;
    --cache|-c)
      cygpath -aw "$2" > /etc/setup/last-cache
      shift ; shift
    ;;
    --noscripts)
      noscripts=1
      shift
    ;;
    --noupdate|-u)
      noupdate=1
      shift
    ;;
    --ForceUpdate)
      noupdate=0
      localdiskcache=0
      shift
    ;;
    --localdiskcache)
      localdiskcache=1
      shift
    ;;
    --force)
      forceinstall=1
      shift
    ;;
    --help)
      usage
      exit 0
    ;;
    --version)
      version
      exit 0
    ;;
    --find-setup-exe)
      findsetupexe
      exit 0
    ;;
    --file|-f)
      if ! test "-$2-" = "--"
      then
        file="$2"
        dofile=1
        shift
      else
        echo 1>&2 No file name provided, ignoring $1
      fi
      shift
    ;;
    update|show|find|describe|packageof|install|remove)
      if test "-$command-" = "--"
      then
        command=$1
      else
        packages="$packages $1"
      fi
      shift
    ;;
    *)
      packages="$packages $1"
      shift
    ;;
  esac
  done
  ######################################################
  # Done reading the options. Now process accordingly
  ######################################################
  if test $dofile = 1
  then
    if test -f "$file"
    then
      filepackages="$filepackages `cat "$file" | awk '{printf "%s ", $0}'`"
    else
      echo File $file not found, skipping
    fi
    packages="$packages $filepackages"
  fi

  case "$command" in
  update)
    findworkspace
    getsetup
  ;;
  show)
    echo 1>&2 The following packages are installed:
    cat /etc/setup/installed.db | awk '/[^ ]+ [^ ]+ 0/ {print $1}'
  ;;
  find)
    checkpackages
    findworkspace
    getsetup
    for pkg in $packages
    do
      echo ""
      echo Searching for installed packages matching $pkg:
      awk '/[^ ]+ [^ ]+ 0/ {if ($1 ~ query) print $1}' query="$pkg" /etc/setup/installed.db
      echo ""
      echo Searching for installable packages matching $pkg:
      cat setup.ini | awk -v query="$pkg" \
        'BEGIN{RS="\n\n@ "; FS="\n"; ORS="\n"} {if ($1 ~ query) {print $1}}'
    done
  ;;
  describe)
    checkpackages
    findworkspace
    getsetup
    for pkg in $packages
    do
      echo ""
      cat setup.ini | awk -v query="$pkg" \
        'BEGIN{RS="\n\n@ "; FS="\n"; ORS="\n"} {if ($1 ~ query) {print $0 "\n"}}'
    done
  ;;
  packageof)
    checkpackages
    for pkg in $packages
    do
      key=`which "$pkg" 2>/dev/null | sed "s:^/::"`
      if test "-$key-" = "--"
      then
        key="$pkg"
      fi
      for manifest in "/etc/setup/*.lst.gz"
      do
        found=`cat "$manifest" | gzip -d | grep -c "$key"`
        if test $found -gt 0
        then
          package=`echo "$manifest" | sed -e "s:/etc/setup/::" -e "s/.lst.gz//"`
          echo Found $key in the package $package
        fi
      done
    done
  ;;
  install)
    checkpackages
    findworkspace
    getsetup
    apt-cyg-func-install
    ;;
  remove)
    checkpackages
    for pkg in $packages
    do
      already=`grep -c "^$pkg " /etc/setup/installed.db`
      if test $already = 0
      then
        echo Package $pkg is not installed, skipping
        continue
      fi
      dontremove="cygwin coreutils gawk bzip2 tar wget bash"
      for req in $dontremove
      do
        if test "-$pkg-" = "-$req-"
        then
          echo apt-cyg cannot remove package $pkg, exiting
          exit 1
        fi
      done
      if ! test -e "/etc/setup/$pkg.lst.gz"
      then
        echo Package manifest missing, cannot remove $pkg.  Exiting
        exit 1
     fi
      echo Removing $pkg
      # run preremove scripts
      if test -e "/etc/preremove/$pkg.sh"
      then
        "/etc/preremove/$pkg.sh"
        rm "/etc/preremove/$pkg.sh"
      fi
      cat "/etc/setup/$pkg.lst.gz" | gzip -d | awk '/[^\/]$/ {print "rm -f \"/" $0 "\""}' | sh
      rm "/etc/setup/$pkg.lst.gz"
      rm -f /etc/postinstall/$pkg.sh.done
      cat /etc/setup/installed.db | awk > /tmp/awk.$$ -v pkg="$pkg" '{if (pkg != $1) print $0}'
      mv /etc/setup/installed.db /etc/setup/installed.db-save
      mv /tmp/awk.$$ /etc/setup/installed.db
      echo Package $pkg removed
    done
  ;;
  *)
    usage
  ;;
esac

}
main "$@"

答案2

我通常使用标准安装程序中的“下载到本地目录”选项,并在基本安装中选择我想要的软件包。这会下载我想要但不安装的软件包,我可以将该软件包目录复制到网络共享或拇指驱动器。添加 Cygwin 的副本安装程序到该本地目录,您就拥有了一个离线安装程序。

这种方法的缺点是您的离线软件包无法保持最新​​。但您可以随时重新运行安装程序以下载并安装更新的软件包。

答案3

尝试使用创建独立的 Cygwin 安装程序肌钙蛋白

答案4

我在使用 apt-cyg setup.ini 时遇到了一些问题

我必须改变 apt-cyg 中的 getsetup 方法才能使一切正常运行。

function getsetup()
{
  if test "$noscripts" == "0" -a "$noupdate" == "0"
  then
    touch setup.ini
    mv setup.ini setup.ini-save
    wget -N $mirror/setup.bz2
    if test -e setup.bz2 && test $? -eq 0
    then
      bunzip2 setup.bz2
      mv setup setup.ini
      echo Updated setup.ini
    else
      if [ `arch` == "x86_64" ]
      then
        echo using x86_64
        arch=x86_64
      else
        echo using x86
        arch=x86
      fi
      wget -N $mirror/$arch/setup.ini
      if test -e setup.ini && test $? -eq 0
      then
        echo Updated setup.ini
      else
        mv setup.ini-save setup.ini
        echo Error updating setup.ini, reverting
      fi
    fi
  fi
}

相关内容