从Cygwin删除不需要的依赖项


15

在Cygwin中,当我安装新软件包时,它将自动安装该软件包所需的所有依赖项。

以后,如果我选择删除该程序包,该如何删除不再随其安装的依赖项?

Answers:


8

好吧,这是我目前想出的解决方案。使用我对bash和Google的(非常)有限的知识。

#!/bin/bash
# Print a list of packages that no other package depends on

PackageCount=0
PackageIter=0

# Populate package array
declare -A Packages
PackageList=$(cygcheck.exe -c | cut -d' ' -f1 | tail -n +3)
for P in $PackageList; do
    Packages[${P,,}]=0
    ((PackageCount++))
done

# Determine the last mirror used
LastMirror=$(sed -n '/last-mirror/{n;p}' /etc/setup/setup.rc | tr -d '\t')
echo "[DEBUG] LastMirror = $LastMirror"

# Download the setup.ini file from the mirror server
echo "[DEBUG] Downloading setup.ini from mirror"
if which bzcat &>/dev/null; then
    wget --quiet "${LastMirror}$(uname -m)/setup.bz2" -O - | bzcat > setup.ini
else
    wget --quiet "${LastMirror}$(uname -m)/setup.ini" -O setup.ini
fi

for P in $PackageList; do
    ((PackageIter++))
    echo -ne "[DEBUG] Processing packages $((PackageIter * 100 / PackageCount))%\r"

    deps=$(sed -n "/^@ $P$/,/^requires/p" setup.ini | grep -i '^requires' | cut -d' ' -f2-)

    for dep in $deps; do
        if [[ ${Packages[${dep,,}]} ]]; then
            Packages[${dep,,}]=$((Packages[${dep,,}]+1))
        fi
    done
done

echo -e "\n== Packages =="

for P in $PackageList; do
    if [[ ${Packages[${P,,}]} == 0 ]]; then
        echo $P
    fi
done

rm setup.ini

我很想看看是否有人有更好的解决方案,或者有任何改进我的脚本的技巧。


我不知道您是否仍在网站上,但我编辑了脚本以修复N=$N+1错误-在bash中,这实际上将创建字符串而不是数学。将语句括起来(( ))可让您使用bash进行真正的数学运算(因为您必须在脚本的后面部分中找到)。另外,我没有更改此部分,但是您无需保留数组中元素数量的计数。代替$PackageCount,您可以${#PackageList}直接获取元素的数量。
piojo
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.