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.

symlink-tester.sh 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env sh
  2. usage() {
  3. echo usage: $0 path/to/sonar-scanner
  4. exit 1
  5. }
  6. test -f "$1" && test -x "$1" || usage
  7. scanner=$1
  8. if type mktemp &>/dev/null; then
  9. tempdir=`mktemp -d`
  10. tempdir=`cd "$tempdir"; pwd -P`
  11. else
  12. tempdir=/tmp/"`basename "$0"`-$$"
  13. mkdir -p "$tempdir"
  14. fi
  15. cleanup() {
  16. rm -fr "$tempdir"
  17. }
  18. trap 'cleanup; exit 1' 1 2 3 15
  19. trap 'cleanup; exit 0' 0
  20. abspath() {
  21. (cd "`dirname "$1"`"; echo $PWD/"`basename "$1"`")
  22. }
  23. verify() {
  24. printf '%s -> ' "$1"
  25. shift
  26. "$@" &>/dev/null && echo ok || echo failed
  27. }
  28. relpath_to_root() {
  29. (
  30. cd "$1"
  31. relpath=.
  32. while test "$PWD" != /; do
  33. cd ..
  34. relpath=$relpath/..
  35. done
  36. echo $relpath
  37. )
  38. }
  39. ln -s "`abspath "$scanner"`" "$tempdir"/scanner
  40. verify 'launch from abs symlink to abs path' "$tempdir"/scanner -h
  41. ln -s "`relpath_to_root "$tempdir"``abspath "$scanner"`" "$tempdir"/scanner-rel
  42. verify 'symlink to rel path is valid' test -e "$tempdir"/scanner-rel
  43. verify 'launch from abs symlink to rel path' "$tempdir"/scanner-rel -h
  44. mkdir "$tempdir/x"
  45. ln -s ../scanner "$tempdir"/x/scanner
  46. verify 'symlink to rel symlink is valid' test -f "$tempdir"/x/scanner
  47. verify 'launch from abs symlink that is rel symlink to abs path' "$tempdir"/x/scanner -h