原文:https://www.imooc.com/article/247113

新建文件apt-cyg,写入下面内容

#!/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

执行命令:install apt-cyg /bin

cygwin使用apt-cyg相关推荐

  1. apt cyg 安装php,Cygwin的包管理器:apt

    本站文章除注明转载外,均为本站原创或者翻译. 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商: 本站部分原创和翻译文章提供markdown格式源码,欢迎使 ...

  2. cygwin php 环境变量设置,cygwin 配置

    cygwin 设置 HOME: 在Cygwin.bat 中的 bash --login -i 前添加 set HOME=XXX\cygwin\home\XXX cygwin 使用apt : 参考htt ...

  3. cygwin和mingw编译软件的疑问

    2019独角兽企业重金招聘Python工程师标准>>> 对于cygwin和mingw的区别已有基本了解.先已有mingw+msys环境,mingw版gcc在mingw官网下载,版本4 ...

  4. minGW, cygwin, GnuWin32【C++的跨平台交叉编译问题】

    这几天在整C++的跨平台交叉编译问题,总算告一段落,把具体涉及的内容整理如下: 首先,三个的官方网站分别是: minGW:http://www.mingw.org cygwin:  http://ww ...

  5. Windows中使用包管理器(类似于apt/yum的) - Chocolatey

    Windows中使用包管理器 - Chocolatey简介 李俊才 的 CSDN 博客 邮箱 :291148484@163.com CSDN 主页:https://blog.csdn.net/qq_2 ...

  6. Cygwin的安装及csh的配置和使用(批量下载FNL数据方法)

    安装软件 (1)软件下载官网:Cygwin (2)软件安装教程(不建议安装在C盘)(下面两个网址都是安装教程): Cygwin安装教程_Errol's Blog-CSDN博客_cygwin安装 --- ...

  7. MSYS2 Mingw Cygwin对比

    系列文章目录 文章目录 系列文章目录 前言 一.MSYS2 是什么? 前言 Mingw 仅支持 32-bit 程序,现在一般用 Mingw-w64,既支持 32 也支持 64-bit Mingw-W6 ...

  8. Cygwin环境使用第三方ARMGCC编译eCos系统

    第三方ARMGCC通常是基于Mingw32的,使用的是Windows路径,如C:\ecos\packages\infra\current\src\startup.cxx:而eCos配置工具生成的Mak ...

  9. Cygwin的简介以及使用方法

    0:简介 1:下载和安装 2:使用 简介 Cygwin是一个运行于Windows下的免费的UNIX的子系统,使用一个Dll(动态链接库)来 实现,这样,我们可以开发出Cygwin下的UNIX工具,使用 ...

  10. apt apt-get_Windows用户准备好进行apt-get吗?

    apt apt-get 它能做什么(What it does) Chocolatey lets you install Windows applications quickly from the co ...

最新文章

  1. kibana操作elasticsearch:多字段查询(multi_match)
  2. 一、认识Python
  3. 堆元素插入 二叉堆一般用数组来表示。typedef struct _otherInfo{ int i; int j;}OtherInfo;-icoding-C-数据结构
  4. spring roo_使用Spring Roo进行快速云开发–第1部分:Google App Engine(GAE)
  5. 关于Office 中的墨迹功能(可作word电子签名)
  6. kaggle:PUBG Finish Placement Prediction
  7. linux mkdir 参数,Linux基础命令之 mkdir
  8. C#关于委托(基础)
  9. 多元统计分析及R语言建模(第四版)--第二章多元数据的数学表达式及R使用课后习题
  10. easypoi excel:Cannot add merged region X to sheet because it overlaps with an existing merged region
  11. 如何手动启动消防广播_消防应急广播应如何规范设置?
  12. e430c参数 thinkpad_联想ThinkPad E430c(33651E1)
  13. spring boot 在fastdfs文件上传大小限制
  14. Python入门学习笔记(五)——文件、文件系统
  15. Nazo前三十三关攻略
  16. web开发需要用什么软件
  17. CSDN 去除图片水印
  18. python—成绩管理系统考试题目:小学五年级学生小明、小王、小丽、小花的语文、英语、数学成绩如……
  19. linux命令的使用:配置静态ip,查看网关,dns服务器ip,关闭防火墙,selinux
  20. FlyBanner+RecyclerView显示+MVP

热门文章

  1. BZOJ 5442 [Ceoi2018]Global warming
  2. POI excel单元格中内容换行
  3. 图像分类经典卷积神经网络—SENet论文翻译(纯中文版)—Squeeze-and-Excitation Networks(挤压和激励网络)
  4. 【5G核心网】 NGAP 消息
  5. Data‘ object has no attribute ‘has_isolated_nodes
  6. 在电梯里你的一举一动
  7. 依图科技创始人:如何对AI技术和产业发展更全面的理解?
  8. 机顶盒ttl无法输入_中兴机顶盒B8601.1T TTL后跑码无法输入指令
  9. android7.1 科大讯飞语音引擎设置为首选引擎
  10. win10九月十五更新补丁导致共享打印机无法连接