Remove unneeded dependencies from Cygwin

16

6

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?

Josh

Posted 2013-03-23T14:02:10.253

Reputation: 678

Answers

8

Well, here is my current solution I came up with. Using my (very) limited knowledge of bash and 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

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

Josh

Posted 2013-03-23T14:02:10.253

Reputation: 678

1I don't know if you're still on the site, but I edited your script to fix a N=$N+1 error--in bash, this will actually create a string rather than math. Surrounding the statement in (( )) lets you do real math in bash (as you must have discovered later in the script). Also, I didn't change this part, but you don't need to keep a count of the number of elements in an array. Instead of $PackageCount, you can access ${#PackageList} to get the number of elements directly. – piojo – 2017-08-05T01:20:29.380

0

This feature seems to be built into later versions of Cygwin. Simply run the installer, sort packages by category, and browse to the Orphaned category. This category gathers packages which have become orphaned since being installed. These packages are kept by default, but toggling them to be uninstalled removes them. Alternatively, you can install them by passing the -o option to the command-line version of setup:

-o --delete-orphans       remove orphaned packages

Hashim

Posted 2013-03-23T14:02:10.253

Reputation: 6 967