OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.9 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-cleanup
  6. # Copyright (C) 2006 - 2008 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. #Description: Cleanup the build environment
  18. [ -n "$SDEROOT" ] ||
  19. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  20. . $SDEROOT/lib/libsde.in
  21. nocheck=0
  22. downclean=0
  23. buildclean=0
  24. cacheclean=0
  25. cleanup_usage() {
  26. cat <<EOT
  27. Usage: sde cleanup [ -build ] [ -cache ] [ -full ] [ -nocheck ] [ -download ]
  28. sde cleanup [ dir(s) ]
  29. EOT
  30. }
  31. while [ "$1" ] ; do
  32. case "$1" in
  33. -build)
  34. buildclean=1 ;;
  35. -cache)
  36. cacheclean=1 ;;
  37. -full)
  38. buildclean=1 ; cacheclean=1 ;;
  39. -nocheck)
  40. nocheck=1 ;;
  41. -download)
  42. downclean=1 ;;
  43. -*) cleanup_usage
  44. exit 1 ;;
  45. *)
  46. break ;;
  47. esac
  48. shift
  49. done
  50. # Cleanup download/* and quit
  51. #
  52. if [ $downclean -eq 1 ]; then
  53. echo "Searching for obsolete downloads (this may take some time) ..."
  54. $SDEROOT/bin/sde-cleanup-download
  55. fi
  56. # Remove src.*
  57. #
  58. for x in tmp src.* build/*/TOOLCHAIN/src.*; do
  59. if [ -d "$x" -o -L "$x" ] ; then
  60. if [ "$#" != 0 ] ; then
  61. delme=0
  62. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  63. [ "$delme" = 0 ] && continue
  64. fi
  65. delme=1
  66. for y in build.pid; do
  67. if [ $delme = 1 -a -f "$x/$y" ] ; then
  68. if [ "`fuser "$x/$y"`" ] ; then
  69. echo "Found active $y in $x: Not removing!"
  70. delme=0
  71. fi
  72. fi
  73. done
  74. if [ $delme = 1 ] ; then
  75. echo "removing $x .."
  76. rm -rf "$x"
  77. fi
  78. fi
  79. done
  80. # Remove build/*
  81. #
  82. fullhelp=0
  83. for x in build/* ; do
  84. if [ -d "$x" ] ; then
  85. if [ "$#" != 0 ] ; then
  86. delme=0
  87. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  88. [ "$delme" = 0 ] && continue
  89. fi
  90. # handle (c)cache pools first
  91. if [ ${x/build\/ccache/} != $x ]; then
  92. if [ $cacheclean = 1 ]; then
  93. echo "removing $x ..."
  94. rm -rf "$x"
  95. else
  96. echo "Not removing $x (cache)."
  97. fullhelp=1
  98. fi
  99. continue
  100. fi
  101. if [ $buildclean = 1 ] ; then
  102. for y in proc TOOLCHAIN/loop TOOLCHAIN/config TOOLCHAIN/download; do
  103. umount -d -f "$x/$y" > /dev/null 2>&1
  104. umount -d -f -l "$x/$y" > /dev/null 2>&1
  105. rmdir "$x/$y" > /dev/null 2>&1
  106. if [ -d "$x/$y" ] ; then
  107. echo "Found $y in $x: Not removing!"
  108. delme=0
  109. fi
  110. done
  111. if [ "$delme" != 0 ] ; then
  112. echo "removing $x ..."
  113. rm -rf "$x"
  114. fi
  115. else
  116. echo "Not removing $x (build)."
  117. fullhelp=1
  118. fi
  119. fi
  120. done
  121. [ $fullhelp -eq 1 ] &&
  122. echo -e "\nUse '$0 -build' to remove builds and '$0 -cache'
  123. to also flush the cache."
  124. [ "$nocheck" = 1 ] || exec $SDEROOT/bin/sde-clean-linger