Cygwin下安装包管理器apt-cyg

news/2025/1/15 12:44:58/

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

http://www.ppmy.cn/news/812211.html

相关文章

c#制作简单安装包 以Revit插件为例

Revit插件安装包整体制作流程&#xff1a; 1.安装程序 1.1前端&#xff1a;制作安装页面(winfomr和wpf均可&#xff0c;根据需要创建页面&#xff0c;如欢迎页面&#xff0c;安装许可协议页面&#xff0c;Revit版本选择页面&#xff0c;安装地址选择页面&#xff0c;安装进度页…

mysql5.6.17 安装包_Mysql5.6.17 zip版本安装

1.把 mysql解压到自定义 D:\mysql-5.6.17-W64 2.我的电脑--属性--高级--环境变量--系统变量--新建系统环境变量 变量名&#xff1a;MYSQL_HOME 变量值&#xff1a;D:\mysql-5.6.17-W64 3.向原系统环境变量 Path 中添加;%MYSQL_HOME%\bin 4.cmd--进到D:\mysql-5.6.17-W64\bin目录…

Inno Setup 创建Revit安装包

之前通过NSIS打包文件后来发现Inno Setup,使用了一下发现相较于NSIS个人感觉Inno稍微好一点&#xff0c;整个操作界面会比NSIS要简洁许多&#xff0c;有汉化版可以添加我这里用的是英文原版 向导设置 安装后创建新的文件向导 File-> New 点击Next进入设置界面 因为打包的安…

Oracle客户端安装INS-30131

前几天在Windows中安装Oracle客户端时&#xff0c;报错INS-30131&#xff0c;在网上查阅了很多文章&#xff0c;其解决方法大部分是修改磁盘的共享权限&#xff0c;尝试在不同的机子上使用这种方法解决&#xff0c;大部分成功了&#xff0c;但个别机子仍然无法成功解决&#xf…

revit二次开发——制作插件安装包,自动写addin文件

目录 准备工作安装包制作1、新建项目&#xff0c;选中Setup Project2、进入项目&#xff0c;在Application Folder里添加要打包的文件2.1 文件夹说明2.2添加卸载程序2.3依赖框架 3、以上配置完成&#xff0c;编译Setup项目即可在“Setup项目/Release”生成安装包。 自定义安装程…

图像检索:INS视觉检索

INS is a image retrieval system for instance search. The system can be used to retrieve same object, near-duplicate object, and copy detection, and developing the system is just for interest in my free time. I’ll improve the system contiously. 十一时期&am…

创建 VSTO 外接程序的windows安装包

一、创建Excel VSTO 外接程序的新项目 (一)新建解决方案和Excel VSTO 外接程序项目 创建一个Excel VSTO外接程序的新项目&#xff0c;选择“Excel VSTO外接程序(Visual Basic)”模板&#xff0c;命名为“外接程序安装”。VS将显示解决方案名称为“外接程序安装”&#xff0c;…

NSIS安装包脚本

!addincludedir "include"Var MSG ;MSG变量必须定义&#xff0c;而且在最前面&#xff0c;否则WndProc::onCallback不工作&#xff0c;插件中需要这个消息变量,用于记录消息信息 Var Dialog ;Dialog变量也需要定义&#xff0c;他可能是NSIS默认的对话框变量用于…