DownloadUpdates.sh cleanup doesn't delete superseded patches

DownloadUpdates.sh cleanup doesn't delete superseded patches

Postby jthornsen » 13.03.2015, 19:01

Hello,

I have been using wsusoffline for several months and just now realized that superseded patches are not being deleted from the client folder.
I am currently running wsusoffline v9.4.2

I looked thru the subversion repo and found that in wsusoffline 8.0, the cleanup function changed so that it simply echos text to a file (../temp/cleanup.txt) instead of actually deleting the superseded patches from the client directory.

Is there a reason why this change was made? How can I set up my cron jobs so that superseded patches will automatically be deleted from the client directory?

wsusoffline 7.5
Code: Select all

cleanup()
{
file="$1"
path="$2"
rm -f ../temp/cleanup.txt
touch ../temp/cleanup.txt
for i in $(ls -l "$path" | tr -s " " | cut -d " " -f 9 | grep "\b"); do
  result=$(grep "${i}" "${file}")
  if [ "$result" == "" ] && [ "$i" != "ie6setup" ]; then
    echo "$i" >> ../temp/cleanup.txt
  fi
done
currentpath=$(pwd)
cd "$path"
rm -f `cat "$currentpath/../temp/cleanup.txt"`
cd "$currentpath"
}


wsusoffline 8.0
Code: Select all
cleanup()
{
file="$1"
path="$2"
rm -f ../temp/cleanup.txt
touch ../temp/cleanup.txt
for i in $(ls "$path"); do
  test "$i" == "ie6setup" && continue
  grep "${i}" "${file}" || echo "$i"
  echo rm -f ${path}/"$i"
done > ../temp/cleanup.txt
    }
jthornsen
 
Posts: 2
Joined: 13.03.2015, 18:51

Re: DownloadUpdates.sh cleanup doesn't delete superseded pat

Postby jthornsen » 13.03.2015, 19:55

I have temporarily fixed this issue on my machine by re-writing the cleanup function as follows. I would appreciate if this fix could be incorporated into the official product.

I'm not sure if it's even necessary to output to ../temp/cleanup.txt, but I left it there anyway.

Code: Select all
    cleanup()
    {
    file="$1"
    path="$2"
    rm -f ../temp/cleanup.txt
    touch ../temp/cleanup.txt
    for i in $(ls "$path"); do
      test "$i" == "ie6setup" && continue
      grep -q "${i}" "${file}" && continue
      echo "Deleting superseded update ${path}/$i"
      echo "${path}/$i" >> ../temp/cleanup.txt
      rm -f "${path}/$i"
    done
        }
jthornsen
 
Posts: 2
Joined: 13.03.2015, 18:51

Re: DownloadUpdates.sh cleanup doesn't delete superseded pat

Postby hbuhrmester » 14.03.2015, 16:53

This will be dangerous, it directories are nested, as with the notorious "dotnet" directory:

Code: Select all
$ find ../client/dotnet/ -maxdepth 1 -type d
../client/dotnet/
../client/dotnet/x86-glb
../client/dotnet/x64-glb


Then the cleanup function will happily (with rm -f) delete whole subdirectories:

Code: Select all
Deleting superseded update ../client/dotnet/x64-glb
Deleting superseded update ../client/dotnet/x86-glb


So maybe it works, if we add another check:

Code: Select all
cleanup()
{
    file="$1"
    path="$2"
    rm -f ../temp/cleanup.txt
    touch ../temp/cleanup.txt
    for i in $(ls "$path"); do
        test "$i" == "ie6setup" && continue
        test -d "${path}/$i" && continue
        grep -q "${i}" "${file}" && continue
        echo "Deleting superseded update ${path}/$i"
        echo "${path}/$i" >> ../temp/cleanup.txt
        rm "${path}/$i"
    done
}


Greetings,
Hartmut
hbuhrmester
 
Posts: 232
Joined: 11.10.2013, 20:59


Return to Linux

Who is online

Users browsing this forum: No registered users and 1 guest