在 Cygwin 中,当我安装新包时,它会自动安装该包所需的任何依赖项。
稍后如果我选择删除该包,我该如何删除它所安装的不再需要的依赖项?
答案1
好吧,这是我目前想到的解决方案。使用我对 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
我很想看看是否有人有更好的解决方案,或者有任何改进我的脚本的建议。