install 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. function is_root {
  3. if [ ${EUID:-$(id -u)} -eq 0 ]; then
  4. return 0
  5. fi
  6. return 1
  7. }
  8. function lognecho {
  9. for STR in "${@}"; do
  10. logger "${STR}"
  11. echo "${STR}"
  12. done
  13. }
  14. function yn {
  15. read -p "Procced? [y/n]: " CHOICE
  16. case ${CHOICE} in
  17. y)
  18. return 0
  19. ;;
  20. n)
  21. return 1
  22. ;;
  23. *)
  24. yn
  25. ;;
  26. esac
  27. }
  28. is_root
  29. if [ $? -ne 0 ]; then
  30. lognecho "Root is required. Run with sudo:" "$ sudo ${SNAP_NAME}.install"
  31. exit 1
  32. fi
  33. if snapctl is-connected components; then
  34. if [ -n ${CONNECT-} ]; then
  35. if [ -d "$SNAP_DATA/custom_components/hacs" ]; then
  36. lognecho "${SNAP_NAME} is already installed. Re-installing it will overwrite current installation."
  37. yn
  38. if [ $? -ne 0 ]; then
  39. exit 1
  40. fi
  41. fi
  42. fi
  43. lognecho "Installing ${SNAP_NAME} into your Home Assistant installation: ${SNAP_DATA}"
  44. cd "${SNAP_DATA}"
  45. export haPath="${SNAP_DATA}"
  46. ${SNAP}/hacs
  47. if [ $? -ne 0 ]; then
  48. lognecho "Installation of ${SNAP_DATA} failed!"
  49. else
  50. lognecho "Installation of ${SNAP_DATA} successful."
  51. fi
  52. else
  53. lognecho "${SNAP_NAME}:components is not connected, connect with:" "$ snap connect ${SNAP_NAME}:components home-assistant-snap:components"
  54. exit 1
  55. fi