Cygwin默认没有yum、npm、composer等类似的包管理器,如果需要安装扩展包需要重新打开安装程序,非常麻烦,不过apt-cyg开源程序解决了这个问题。
安装步骤:
$ wget -c https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
$ install apt-cyg /bin# 安装pkg-config
$ apt-cyg install pkg-config
apt-cyg其实是一段脚本,如果下载不下来,可以拷贝以下脚本,另存为apt-cyg,然后拷贝{cygwin64_dir}\home\{user_dir}
目录下:
#!/bin/bash
# apt-cyg: install tool for Cygwin similar to debian apt-get
#
# The MIT License (MIT)
#
# Copyright (c) 2013 Trans-code Design
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.if [ ${BASH_VERSINFO}${BASH_VERSINFO[1]} -lt 42 ]
thenecho 'Bash version 4.2+ required'exit
fiusage="\
NAMEapt-cyg - package manager utilitySYNOPSISapt-cyg [operation] [options] [targets]DESCRIPTIONapt-cyg is a package management utility that tracks installed packages on aCygwin system. Invoking apt-cyg involves specifying an operation with anypotential options and targets to operate on. A target is usually a packagename, file name, URL, or a search string. Targets can be provided as commandline arguments.OPERATIONSinstallInstall package(s).removeRemove package(s) from the system.updateDownload a fresh copy of the master package list (setup.ini) from theserver defined in setup.rc.downloadRetrieve package(s) from the server, but do not install/upgrade anything.showDisplay information on given package(s).dependsProduce a dependency tree for a package.rdependsProduce a tree of packages that depend on the named package.listSearch each locally-installed package for names that match regexp. If nopackage names are provided in the command line, all installed packages willbe queried.listallThis will search each package in the master package list (setup.ini) fornames that match regexp.categoryDisplay all packages that are members of a named category.listfilesList all files owned by a given package. Multiple packages can be specifiedon the command line.searchSearch for downloaded packages that own the specified file(s). The path canbe relative or absolute, and one or more files can be specified.searchallSearch cygwin.com to retrieve file information about packages. The providedtarget is considered to be a filename and searchall will return thepackage(s) which contain this file.mirrorSet the mirror; a full URL to a location where the database, packages, andsignatures for this repository can be found. If no URL is provided, displaycurrent mirror.cacheSet the package cache directory. If a file is not found in cache directory,it will be downloaded. Unix and Windows forms are accepted, as well asabsolute or regular paths. If no directory is provided, display currentcache.OPTIONS--nodepsSpecify this option to skip all dependency checks.--versionDisplay version and exit.
"version="\
apt-cyg version 1The MIT License (MIT)Copyright (c) 2005-9 Stephen Jungels
"function wget {if command wget -h &>/dev/nullthencommand wget "$@"elsewarn wget is not installed, using lynx as fallbackset "${*: -1}"lynx -source "$1" > "${1##*/}"fi
}function find-workspace {# default working directory and mirror# work wherever setup worked last, if possiblecache=$(awk 'BEGIN {RS = "\n\\<"FS = "\n\t"}$1 == "last-cache" {print $2}' /etc/setup/setup.rc)mirror=$(awk '/last-mirror/ {getlineprint $1}' /etc/setup/setup.rc)mirrordir=$(sed 's / %2f gs : %3a g' <<< "$mirror")mkdir -p "$cache/$mirrordir/$arch"cd "$cache/$mirrordir/$arch"if [ -e setup.ini ]thenreturn 0elseget-setupreturn 1fi
}function get-setup {touch setup.inimv setup.ini setup.ini-savewget -N $mirror/$arch/setup.bz2if [ -e setup.bz2 ]thenbunzip2 setup.bz2mv setup setup.iniecho Updated setup.inielseecho Error updating setup.ini, revertingmv setup.ini-save setup.inifi
}function check-packages {if [[ $pks ]]thenreturn 0elseecho No packages found.return 1fi
}function warn {printf '\e[1;31m%s\e[m\n' "$*" >&2
}function apt-update {if find-workspacethenget-setupfi
}function apt-category {check-packagesfind-workspacefor pkg in "${pks[@]}"doawk '$1 == "@" {pck = $2}$1 == "category:" && $0 ~ query {print pck}' query="$pks" setup.inidone
}function apt-list {local sbqfor pkg in "${pks[@]}"dolet sbq++ && echoawk 'NR>1 && $1~pkg && $0=$1' pkg="$pkg" /etc/setup/installed.dbdonelet sbq && returnawk 'NR>1 && $0=$1' /etc/setup/installed.db
}function apt-listall {check-packagesfind-workspacelocal sbqfor pkg in "${pks[@]}"dolet sbq++ && echoawk '$1~pkg && $0=$1' RS='\n\n@ ' FS='\n' pkg="$pkg" setup.inidone
}function apt-listfiles {check-packagesfind-workspacelocal pkg sbqfor pkg in "${pks[@]}"do(( sbq++ )) && echoif [ ! -e /etc/setup/"$pkg".lst.gz ]thendownload "$pkg"figzip -cd /etc/setup/"$pkg".lst.gzdone
}function apt-show {find-workspacecheck-packagesfor pkg in "${pks[@]}"do(( notfirst++ )) && echoawk '$1 == query {printfd++}END {if (! fd)print "Unable to locate package " query}' RS='\n\n@ ' FS='\n' query="$pkg" setup.inidone
}function apt-depends {find-workspacecheck-packagesfor pkg in "${pks[@]}"doawk '@include "join"$1 == "@" {apg = $2}$1 == "requires:" {for (z=2; z<=NF; z++)reqs[apg][z-1] = $z}END {prpg(ENVIRON["pkg"])}function smartmatch(small, large, values) {for (each in large)values[large[each]]return small in values}function prpg(fpg) {if (smartmatch(fpg, spath)) returnspath[length(spath)+1] = fpgprint join(spath, 1, length(spath), " > ")if (isarray(reqs[fpg]))for (each in reqs[fpg])prpg(reqs[fpg][each])delete spath[length(spath)]}' setup.inidone
}function apt-rdepends {find-workspacefor pkg in "${pks[@]}"doawk '@include "join"$1 == "@" {apg = $2}$1 == "requires:" {for (z=2; z<=NF; z++)reqs[$z][length(reqs[$z])+1] = apg}END {prpg(ENVIRON["pkg"])}function smartmatch(small, large, values) {for (each in large)values[large[each]]return small in values}function prpg(fpg) {if (smartmatch(fpg, spath)) returnspath[length(spath)+1] = fpgprint join(spath, 1, length(spath), " < ")if (isarray(reqs[fpg]))for (each in reqs[fpg])prpg(reqs[fpg][each])delete spath[length(spath)]}' setup.inidone
}function apt-download {check-packagesfind-workspacelocal pkg sbqfor pkg in "${pks[@]}"do(( sbq++ )) && echodownload "$pkg"done
}function download {local pkg digest digactualpkg=$1# look for package and save desc fileawk '$1 == pc' RS='\n\n@ ' FS='\n' pc=$pkg setup.ini > descif [ ! -s desc ]thenecho Unable to locate package $pkgexit 1fi# download and unpack the bz2 or xz file# pick the latest version, which comes firstset -- $(awk '$1 == "install:"' desc)if (( ! $# ))thenecho 'Could not find "install" in package description: obsolete package?'exit 1fidn=$(dirname $2)bn=$(basename $2)# check the md5digest=$4case ${#digest} in32) hash=md5sum ;;128) hash=sha512sum ;;esacmkdir -p "$cache/$mirrordir/$dn"cd "$cache/$mirrordir/$dn"if ! test -e $bn || ! $hash -c <<< "$digest $bn"thenwget -O $bn $mirror/$dn/$bn$hash -c <<< "$digest $bn" || exitfitar tf $bn | gzip > /etc/setup/"$pkg".lst.gzcd ~-mv desc "$cache/$mirrordir/$dn"echo $dn $bn > /tmp/dwn
}function apt-search {check-packagesecho Searching downloaded packages...for pkg in "${pks[@]}"dokey=$(type -P "$pkg" | sed s./..)[[ $key ]] || key=$pkgfor manifest in /etc/setup/*.lst.gzdoif gzip -cd $manifest | grep -q "$key"thenpackage=$(sed 's,/etc/setup/,,s,.lst.gz,,' <<< $manifest)echo $packagefidonedone
}function apt-searchall {cd /tmpfor pkg in "${pks[@]}"doprintf -v qs 'text=1&arch=%s&grep=%s' $arch "$pkg"wget -O matches cygwin.com/cgi-bin2/package-grep.cgi?"$qs"awk 'NR == 1 {next}mc[$1]++ {next}/-debuginfo-/ {next}/^cygwin32-/ {next}{print $1}' FS=-[[:digit:]] matchesdone
}function apt-install {check-packagesfind-workspacelocal pkg dn bn requires wr package sbq scriptfor pkg in "${pks[@]}"doif grep -q "^$pkg " /etc/setup/installed.dbthenecho Package $pkg is already installed, skippingcontinuefi(( sbq++ )) && echoecho Installing $pkgdownload $pkgread dn bn </tmp/dwnecho Unpacking...cd "$cache/$mirrordir/$dn"tar -x -C / -f $bn# update the package databaseawk 'ins != 1 && pkg < $1 {print pkg, bz, 0ins = 1}1END {if (ins != 1) print pkg, bz, 0}' pkg="$pkg" bz=$bn /etc/setup/installed.db > /tmp/awk.$$mv /etc/setup/installed.db /etc/setup/installed.db-savemv /tmp/awk.$$ /etc/setup/installed.db[ -v nodeps ] && continue# recursively install required packagesrequires=$(awk '$1=="requires", $0=$2' FS=': ' desc)cd ~-wr=0if [[ $requires ]]thenecho Package $pkg requires the following packages, installing:echo $requiresfor package in $requiresdoif grep -q "^$package " /etc/setup/installed.dbthenecho Package $package is already installed, skippingcontinuefiapt-cyg install --noscripts $package || (( wr++ ))donefiif (( wr ))thenecho some required packages did not install, continuingfi# run all postinstall scripts[ -v noscripts ] && continuefind /etc/postinstall -name '*.sh' | while read scriptdoecho Running $script$scriptmv $script $script.donedoneecho Package $pkg installeddone
}function apt-remove {check-packagescd /etccygcheck awk bash bunzip2 grep gzip mv sed tar xz > setup/essential.lstfor pkg in "${pks[@]}"doif ! grep -q "^$pkg " setup/installed.dbthenecho Package $pkg is not installed, skippingcontinuefiif [ ! -e setup/"$pkg".lst.gz ]thenwarn Package manifest missing, cannot remove $pkg. Exitingexit 1figzip -dk setup/"$pkg".lst.gzawk 'NR == FNR {if ($NF) ess[$NF]next}$NF in ess {exit 1}' FS='[/\\\\]' setup/{essential,$pkg}.lstesn=$?if [ $esn = 0 ]thenecho Removing $pkgif [ -e preremove/"$pkg".sh ]thenpreremove/"$pkg".shrm preremove/"$pkg".shfimapfile dt < setup/"$pkg".lstfor each in ${dt[*]}do[ -f /$each ] && rm /$eachdonefor each in ${dt[*]}do[ -d /$each ] && rmdir --i /$eachdonerm -f setup/"$pkg".lst.gz postinstall/"$pkg".sh.doneawk -i inplace '$1 != ENVIRON["pkg"]' setup/installed.dbecho Package $pkg removedfirm setup/"$pkg".lstif [ $esn = 1 ]thenwarn apt-cyg cannot remove package $pkg, exitingexit 1fidone
}function apt-mirror {if [ "$pks" ]thenawk -i inplace '1/last-mirror/ {getlineprint "\t" pks}' pks="$pks" /etc/setup/setup.rcecho Mirror set to "$pks".elseawk '/last-mirror/ {getlineprint $1}' /etc/setup/setup.rcfi
}function apt-cache {if [ "$pks" ]thenvas=$(cygpath -aw "$pks")awk -i inplace '1/last-cache/ {getlineprint "\t" vas}' vas="${vas//\\/\\\\}" /etc/setup/setup.rcecho Cache set to "$vas".elseawk '/last-cache/ {getlineprint $1}' /etc/setup/setup.rcfi
}if [ -p /dev/stdin ]
thenmapfile -t pks
fi# process options
until [ $# = 0 ]
docase "$1" in--nodeps)nodeps=1shift;;--noscripts)noscripts=1shift;;--version)printf "$version"exit;;update)command=$1shift;;list | cache | remove | depends | listall | download | listfiles |\show | mirror | search | install | category | rdepends | searchall )if [[ $command ]]thenpks+=("$1")elsecommand=$1fishift;;*)pks+=("$1")shift;;esac
doneset -aif type -t apt-$command | grep -q function
thenreadonly arch=${HOSTTYPE/i6/x}apt-$command
elseprintf "$usage"
fi