clean-old 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! /bin/sh
  2. # clean old distfiles
  3. # This script actually produces another shell-script that you may edit
  4. # before executing.
  5. # $OpenBSD: clean-old,v 1.5 2008/05/16 17:06:54 espie Exp $
  6. #
  7. # Copyright (c) 2000 Marc Espie.
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions
  11. # are met:
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. # notice, this list of conditions and the following disclaimer in the
  16. # documentation and/or other materials provided with the distribution.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
  19. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
  22. # PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. set -e
  30. : ${PORTSDIR=/usr/ports}
  31. : ${DISTDIR=${PORTSDIR}/distfiles}
  32. : ${TMPDIR=/tmp}
  33. : ${MAKE=make}
  34. TMP1=`mktemp $TMPDIR/list.XXXXXXXXXX` || exit 1
  35. #trap 'rm -f $TMP1 $TMP2' 0 1 2 3 5 10 15
  36. TMP2=`mktemp ${TMPDIR}/list.XXXXXXXXXX` || exit 1
  37. {
  38. cd $PORTSDIR
  39. ${MAKE} show=MAKESUMFILES ECHO_MSG=:
  40. if cd 2>/dev/null $PORTSDIR/mystuff
  41. then
  42. find . -type f -name Makefile|while read i
  43. do
  44. if fgrep -q bsd.port.mk $i
  45. then
  46. ( cd `dirname $i`
  47. ${MAKE} show=MAKESUMFILES ECHO_MSG=: || true
  48. )
  49. fi
  50. done
  51. fi
  52. }|tr ' ' "\n"|sort -u >$TMP1
  53. cd $DISTDIR
  54. find . -type f -print|sed -e 's,^\./,,' |grep -v '^Makefile$' |sort -u >$TMP2
  55. echo "#! /bin/sh"
  56. echo "cd $DISTDIR"
  57. diff -u $TMP1 $TMP2|tail +3|grep '^\+'| \
  58. sed -e 's,^\+,rm ,' -e 's,[[&()],\\&,g' -e 's,],\\&,g'
  59. rm $TMP1 $TMP2