install.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Performs a local install. This will replace any previous carbon installs
  8. # without prompting.
  9. STANDARD_LIBRARIES=()
  10. while [[ $# -gt 0 ]]; do
  11. case "$1" in
  12. --carbon)
  13. CARBON="$2"
  14. shift
  15. shift
  16. ;;
  17. --install_path)
  18. INSTALL_PATH="$2"
  19. shift
  20. shift
  21. ;;
  22. *)
  23. STANDARD_LIBRARIES+=("$1")
  24. echo $1
  25. shift
  26. ;;
  27. esac
  28. done
  29. # If the install path is relative, change it to be based on the working dir.
  30. if [[ ! "${INSTALL_PATH}" = /* ]]; then
  31. INSTALL_PATH="${BUILD_WORKING_DIRECTORY}/${INSTALL_PATH}"
  32. fi
  33. # Prepare the install script to run.
  34. SCRIPT=$(cat <<EOF
  35. # Ensure directories exist.
  36. mkdir -p "${INSTALL_PATH}/bin"
  37. mkdir -p "${INSTALL_PATH}/lib/carbon/data"
  38. # Install files to lib.
  39. install -m 755 "${CARBON}" "${INSTALL_PATH}/lib/carbon/carbon"
  40. for f in $(printf " %q" "${STANDARD_LIBRARIES[@]}"); do
  41. install -m 644 "\${f}" "${INSTALL_PATH}/lib/carbon/data/"
  42. done
  43. # Add symlinks in bin.
  44. ln -fs "../lib/carbon/carbon" \
  45. "${INSTALL_PATH}/bin/carbon-explorer"
  46. EOF
  47. )
  48. # Only use sudo if the target directory isn't user-owned.
  49. ACCESS_PATH="${INSTALL_PATH}"
  50. while [[ ! -e "${ACCESS_PATH}" ]]; do
  51. ACCESS_PATH="$(dirname "${ACCESS_PATH}")"
  52. done
  53. if [[ -O "${ACCESS_PATH}" ]]; then
  54. echo "Installing files..."
  55. echo "${SCRIPT}" | /bin/bash -eux -
  56. else
  57. echo "Installing files using sudo..."
  58. echo "${SCRIPT}" | sudo -- /bin/bash -eux -
  59. fi
  60. echo "All done."