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.

143 lines
3.0 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 - 2009 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. #Alias: clean
  19. [ -n "$SDEROOT" ] ||
  20. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  21. . $SDEROOT/lib/libsde.in
  22. nocheck=0
  23. downclean=0
  24. buildclean=0
  25. cacheclean=0
  26. cleanup_usage() {
  27. cat <<EOT
  28. Usage: sde cleanup [ --build ] [ --cache ] [ --full ] [ --nocheck ] [ --download ]
  29. sde cleanup [ dir(s) ]
  30. EOT
  31. }
  32. while [ "$1" ] ; do
  33. case "$1" in
  34. -build|--build)
  35. buildclean=1 ;;
  36. -cache|--cache)
  37. cacheclean=1 ;;
  38. -full|--full)
  39. buildclean=1 ; cacheclean=1 ;;
  40. -nocheck|--nochek)
  41. nocheck=1 ;;
  42. -download|--download)
  43. downclean=1 ;;
  44. -*) cleanup_usage
  45. exit 1 ;;
  46. *)
  47. break ;;
  48. esac
  49. shift
  50. done
  51. # Cleanup download/* and quit
  52. #
  53. if [ $downclean -eq 1 ]; then
  54. echo "Searching for obsolete downloads (this may take some time) ..."
  55. $SDEROOT/bin/sde-cleanup-download
  56. fi
  57. # Remove src.*
  58. #
  59. for x in tmp src.* build/*/TOOLCHAIN/src.*; do
  60. if [ -d "$x" -o -L "$x" ] ; then
  61. if [ "$#" != 0 ] ; then
  62. delme=0
  63. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  64. [ "$delme" = 0 ] && continue
  65. fi
  66. delme=1
  67. for y in build.pid; do
  68. if [ $delme = 1 -a -f "$x/$y" ] ; then
  69. if [ "`fuser "$x/$y"`" ] ; then
  70. echo "Found active $y in $x: Not removing!"
  71. delme=0
  72. fi
  73. fi
  74. done
  75. if [ $delme = 1 ] ; then
  76. echo "removing $x .."
  77. rm -rf "$x"
  78. fi
  79. fi
  80. done
  81. # Remove build/*
  82. #
  83. fullhelp=0
  84. for x in build/* ; do
  85. if [ -d "$x" ] ; then
  86. if [ "$#" != 0 ] ; then
  87. delme=0
  88. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  89. [ "$delme" = 0 ] && continue
  90. fi
  91. # handle (c)cache pools first
  92. if expr "$x" : 'build/\.\?ccache' > /dev/null; then
  93. if [ $cacheclean = 1 ]; then
  94. echo "removing $x ..."
  95. rm -rf "$x"
  96. else
  97. echo "Not removing $x (cache)."
  98. fullhelp=1
  99. fi
  100. continue
  101. fi
  102. if [ $buildclean = 1 ] ; then
  103. for y in proc TOOLCHAIN/loop TOOLCHAIN/config TOOLCHAIN/download; do
  104. umount -d -f "$x/$y" > /dev/null 2>&1
  105. umount -d -f -l "$x/$y" > /dev/null 2>&1
  106. rmdir "$x/$y" > /dev/null 2>&1
  107. if [ -d "$x/$y" ] ; then
  108. echo "Found $y in $x: Not removing!"
  109. delme=0
  110. fi
  111. done
  112. if [ "$delme" != 0 ] ; then
  113. echo "removing $x ..."
  114. rm -rf "$x"
  115. fi
  116. else
  117. echo "Not removing $x (build)."
  118. fullhelp=1
  119. fi
  120. fi
  121. done
  122. if [ $fullhelp -eq 1 ]; then
  123. cat <<-EOT
  124. Use '$0 --build' to remove builds
  125. and '$0 --cache' to also flush the cache.
  126. EOT
  127. fi
  128. [ "$nocheck" = 1 ] || exec $SDEROOT/bin/sde-cleanup-linger