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.

176 lines
4.7 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Cleanup
  6. # Copyright (C) 2006 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. #
  18. # Cleanup the build environment
  19. #
  20. nocheck=0
  21. downclean=0
  22. buildclean=0
  23. cacheclean=0
  24. while [ "$1" ] ; do
  25. case "$1" in
  26. -build)
  27. buildclean=1 ;;
  28. -cache)
  29. cacheclean=1 ;;
  30. -full)
  31. buildclean=1 ; cacheclean=1 ;;
  32. -nocheck)
  33. nocheck=1 ;;
  34. -download)
  35. downclean=1 ;;
  36. -*)
  37. echo "Usage: $0 [ -build ] [ -cache ] [ -full ] [ -nocheck ] [ -download ]"
  38. echo " ${0//[a-zA-Z\/.]/ } [ dir(s) ]"
  39. exit 1 ;;
  40. *)
  41. break ;;
  42. esac
  43. shift
  44. done
  45. # Cleanup download/* and quit
  46. #
  47. if [ $downclean -eq 1 ]; then
  48. echo "Searching for obsolete downloads (this may take some time) ..."
  49. ./scripts/Download -list-unknown | cut -d ' ' -f 3 |
  50. while read fn; do
  51. [ "$fn" ] && rm -v "$fn"
  52. done
  53. exit
  54. fi
  55. # Remove src.*
  56. #
  57. for x in tmp src.* build/*/TOOLCHAIN/src.*; do
  58. if [ -d "$x" -o -L "$x" ] ; then
  59. if [ "$#" != 0 ] ; then
  60. delme=0
  61. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  62. [ "$delme" = 0 ] && continue
  63. fi
  64. delme=1
  65. for y in build.pid; do
  66. if [ $delme = 1 -a -f "$x/$y" ] ; then
  67. if [ "`fuser "$x/$y"`" ] ; then
  68. echo "Found active $y in $x: Not removing!"
  69. delme=0
  70. fi
  71. fi
  72. done
  73. if [ $delme = 1 ] ; then
  74. echo "removing $x .."
  75. rm -rf "$x"
  76. fi
  77. fi
  78. done
  79. # Remove build/*
  80. #
  81. fullhelp=0
  82. for x in build/* ; do
  83. if [ -d "$x" ] ; then
  84. if [ "$#" != 0 ] ; then
  85. delme=0
  86. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  87. [ "$delme" = 0 ] && continue
  88. fi
  89. # handle (c)cache pools first
  90. if [ ${x/build\/ccache/} != $x ]; then
  91. if [ $cacheclean = 1 ]; then
  92. echo "removing $x ..."
  93. rm -rf "$x"
  94. else
  95. echo "Not removing $x (cache)."
  96. fullhelp=1
  97. fi
  98. continue
  99. fi
  100. if [ $buildclean = 1 ] ; then
  101. for y in proc TOOLCHAIN/loop TOOLCHAIN/config TOOLCHAIN/download; do
  102. umount -d -f "$x/$y" > /dev/null 2>&1
  103. umount -d -f -l "$x/$y" > /dev/null 2>&1
  104. rmdir "$x/$y" > /dev/null 2>&1
  105. if [ -d "$x/$y" ] ; then
  106. echo "Found $y in $x: Not removing!"
  107. delme=0
  108. fi
  109. done
  110. if [ "$delme" != 0 ] ; then
  111. echo "removing $x ..."
  112. rm -rf "$x"
  113. fi
  114. else
  115. echo "Not removing $x (build)."
  116. fullhelp=1
  117. fi
  118. fi
  119. done
  120. [ $fullhelp -eq 1 ] &&
  121. echo -e "\nUse '$0 -build' to remove builds and '$0 -cache'
  122. to also flush the cache."
  123. [ "$nocheck" = 1 ] && exit 0
  124. echo -e "\nSearching for lingering temp/backup files (this may take some time) ..."
  125. sderootdirs="scripts/. bin/. etc/. lib/. misc/. doc/. src/. package/. architecture/. target/."
  126. # Remove temp/backup files
  127. #
  128. bash scripts/xfind.sh $sderootdirs -type f \( -name '*~' -o \
  129. -name 'a.out' -o -name 'core.*' -o -name 'core' \) | xargs rm -vf
  130. # Print warnings for 'lingering' files
  131. # (we have to distinguish between the targets and the rest)
  132. #
  133. sderootdirs=${sderootdirs% target/.}
  134. bash scripts/xfind.sh ${sderootdirs} \( \
  135. \( -name 'DEADJOE' -o -name '*-[xX]' -o -name '.[^.]*' \
  136. -o -name '*.orig' -o -name '*.rej' -o -name '*#*' \
  137. -o -name '*.mine' -o -name '*.r[1-9][0-9]*' \
  138. -o -name TRANS.TBL -o -name '*.cksum-err' -o -name x \
  139. -o -name '*[.-]old' -o -name a.out -o -name '*~' \
  140. -o -name '*.incomplete' -o -name '*.ckext-err' \) \
  141. -printf 'WARNING: Found %p\n' \
  142. \) -o \( \
  143. \( ! -type d ! -type f \) \
  144. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  145. \)
  146. # for targets we tolerate .files
  147. bash scripts/xfind.sh target/. \
  148. \( \
  149. \( -name 'DEADJOE' -o -name '*-[xX]' \
  150. -o -name '*.orig' -o -name '*.rej' -o -name '*#*' \
  151. -o -name '*.mine' -o -name '*.r[1-9][0-9]*' \
  152. -o -name TRANS.TBL -o -name '*.cksum-err' -o -name x \
  153. -o -name '*[.-]old' -o -name a.out -o -name '*~' \
  154. -o -name '*.incomplete' -o -name '*.ckext-err' \) \
  155. -printf 'WARNING: Found %p\n' \
  156. \) -o \( \
  157. \( ! -type d ! -type f \) \
  158. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  159. \)
  160. exit 0