Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Cygwin when I install a new package it automatically installs any dependencies needed for that package.

Later if I choose to remove that package, how can I remove the dependencies it installed with it, which are no longer needed?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Well, here is my current solution I came up with. Using my (very) limited knowledge of bash and Google.

#!/bin/sh
# 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=$PackageCount+1
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"
wget --quiet "${LastMirror}setup.ini" -O setup.ini

for P in $PackageList; do
    PackageIter=$PackageIter+1
    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

I'd love to see if anyone has a better solution, or any tips to improve my script.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.