unlink.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. ############################################################################
  3. # tools/unlink.sh
  4. #
  5. # Licensed to the Apache Software Foundation (ASF) under one or more
  6. # contributor license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright ownership. The
  8. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance with the
  10. # License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. # License for the specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. ############################################################################
  21. link=$1
  22. # Verify that arguments were provided
  23. if [ -z "${link}" ]; then
  24. echo "Missing link argument"
  25. exit 1
  26. fi
  27. # Check if something already exists at the link path
  28. if [ -e "${link}" ]; then
  29. # Yes, is it a symbolic link? If so, then remove it
  30. if [ -h "${link}" ]; then
  31. rm -f "${link}"
  32. else
  33. # If the path is a directory and contains the "fake link" mark, then
  34. # treat it like a soft link (i.e., remove the directory)
  35. if [ -d "${link}" -a -f "${link}/.fakelnk" ]; then
  36. rm -rf "${link}"
  37. else
  38. # It is something else (like a file) or directory that does
  39. # not contain the "fake link" mark
  40. echo "${link} already exists but is not a symbolic link"
  41. exit 1
  42. fi
  43. fi
  44. fi