uninstall.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash -eu
  2. #
  3. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. # Exceptions. See /LICENSE for license information.
  5. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. #
  7. # Removes files added by install.sh.
  8. while [[ $# -gt 0 ]]; do
  9. case "$1" in
  10. --install_path)
  11. INSTALL_PATH="$2"
  12. shift
  13. shift
  14. ;;
  15. *)
  16. echo "Unexpected argument: $1"
  17. exit 1
  18. ;;
  19. esac
  20. done
  21. # If the install path is relative, change it to be based on the working dir.
  22. if [[ ! "${INSTALL_PATH}" = /* ]]; then
  23. INSTALL_PATH="${BUILD_WORKING_DIRECTORY}/${INSTALL_PATH}"
  24. fi
  25. # Prepare the uninstall script to run.
  26. # TODO: As more files are added, consider sharing better with install.sh. Maybe
  27. # still keep deleting legacy (no longer installed) files.
  28. SCRIPT=$(cat <<EOF
  29. # Clean up deliberately installed files.
  30. rm -f "${INSTALL_PATH}/bin/carbon-explorer"
  31. rm -rf "${INSTALL_PATH}/lib/carbon"
  32. # Clean up higher level directories in case we created them.
  33. rmdir -p "${INSTALL_PATH}/bin" || true
  34. rmdir -p "${INSTALL_PATH}/lib" || true
  35. EOF
  36. )
  37. # Only use sudo if the target directory isn't user-owned.
  38. ACCESS_PATH="${INSTALL_PATH}"
  39. while [[ ! -e "${ACCESS_PATH}" ]]; do
  40. ACCESS_PATH="$(dirname "${ACCESS_PATH}")"
  41. done
  42. if [[ -O "${ACCESS_PATH}" ]]; then
  43. echo "Uninstalling files..."
  44. echo "${SCRIPT}" | /usr/bin/bash -eux -
  45. else
  46. echo "Uninstalling files using sudo..."
  47. echo "${SCRIPT}" | sudo -- /usr/bin/bash -eux -
  48. fi
  49. echo "All done."