switch-target 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. checkAndRm () {
  3. lines=`find . -mindepth 1 -maxdepth 1 -name "_*" -print | sed 's/\.\///'`
  4. for line in $lines; do
  5. find "${line}" \( -type f -o -type l \) -print |
  6. while read l; do
  7. to=`echo $l | sed "s/^${line}\///"`
  8. if [ -h "${to}" ]; then
  9. rm -f "${to}"
  10. fi
  11. done
  12. done
  13. }
  14. none() {
  15. checkAndRm || exit 2
  16. rm -rf *.exe *.so BlackBox dev0 \
  17. System/Code/Kernel.ocf System/Sym/Kernel.osf Code/Kernel.ocf Sym/Kernel.osf \
  18. System/Code/Init.ocf System/Sym/Init.osf Code/Init.ocf Sym/Init.osf \
  19. System/Code/Config.ocf System/Sym/Config.osf Code/Config.ocf Sym/Config.osf \
  20. Host/Code/*.ocf Host/Sym/*.osf Lin/Code/*.ocf Lin/Sym/*.osf
  21. }
  22. mklinks () {
  23. find "${1}" -mindepth ${2} -maxdepth ${2} \( -type f -o -type l \) -print |
  24. while read l; do
  25. to=`echo $l | sed "s/^${line}\///"`
  26. mkdir -p `dirname "${to}"`
  27. ln -s "${3}"/${l} "${to}"
  28. done
  29. }
  30. dolinks () {
  31. lines1=`find . -mindepth 1 -maxdepth 1 -name "_*${1}*_" -print | sed 's/\.\///'`
  32. lines2=`find . -mindepth 1 -maxdepth 1 -name "__*${2}*" -print | sed 's/\.\///'`
  33. lines3=`find . -mindepth 1 -maxdepth 1 -name "_*"${1}"*_*${2}*" -print | sed 's/\.\///'`
  34. for line in $lines1 $lines2 $lines3; do
  35. find "${line}" -mindepth 1 -maxdepth 1 \( -type f -o -type l \) -print |
  36. while read l; do
  37. ln -s $l
  38. done
  39. mklinks "${line}" 3 ../..
  40. mklinks "${line}" 4 ../../..
  41. done
  42. }
  43. if [ $# -eq 1 ]; then
  44. if [ "${1}" = "none" ]; then
  45. none
  46. else
  47. none || exit 2
  48. dolinks "${1}" Interp
  49. fi
  50. elif [ $# -eq 2 ]; then
  51. none || exit 2
  52. dolinks "${1}" "${2}"
  53. else
  54. echo "usage: `basename $0` ( none | OS [ configuration ] )"
  55. echo " OS: Linux | OpenBSD"
  56. exit 1
  57. fi