install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/sh
  2. # Lyrebird installer script. If running as root then will install at /usr/local/{bin,share},
  3. # otherwise will install at ~/.local/{bin,share}.
  4. VERSION="1.1"
  5. VERBOSE=${VERBOSE:-1}
  6. DRYRUN=${DRYRUN:-0}
  7. # Initial setup
  8. if [ $DRYRUN = 1 ]; then DRYRUN_INFO=" (dryrun)"; fi
  9. ECHO_PREFIX="[lyrebird]$DRYRUN_INFO"
  10. info_echo() {
  11. echo "$ECHO_PREFIX $1"
  12. }
  13. warning_echo() {
  14. echo "[warning]$DRYRUN_INFO $1"
  15. }
  16. verbose_echo() {
  17. if [ $VERBOSE = 1 ]; then
  18. echo "$ECHO_PREFIX $1"
  19. fi
  20. }
  21. if [ "$(id -u)" -eq 0 ]; then
  22. INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
  23. else
  24. INSTALL_PREFIX="${INSTALL_PREFIX:-$HOME/.local}"
  25. fi
  26. verbose_echo "Installing Lyrebird to prefix: ${INSTALL_PREFIX}"
  27. BIN_PATH="$INSTALL_PREFIX/bin"
  28. SHARE_PATH="$INSTALL_PREFIX/share/lyrebird"
  29. DESKTOP_PATH="$INSTALL_PREFIX/share/applications"
  30. python_version_check() {
  31. PYTHON_VERSION=$(python3 --version | grep -Po '3\.\d+')
  32. PYTHON_MIN_MINOR=7
  33. PYTHON_MINOR=${PYTHON_VERSION#*.}
  34. invalid_python() {
  35. info_echo "Lyrebird requires Python version 3.7 or higher"
  36. }
  37. if [ -z $PYTHON_VERSION ]; then
  38. invalid_python
  39. exit 1
  40. elif [ "$PYTHON_MINOR" -lt "$PYTHON_MIN_MINOR" ]; then
  41. invalid_python
  42. exit 1
  43. fi
  44. }
  45. python_version_check
  46. # Removing previous versions
  47. remove_deprecated_install() {
  48. if [ -d "$1" ] || [ -f "$1" ] ; then
  49. if [ $2 -eq 1 ] && [ "$(id -u)" -ne 0 ]; then
  50. warning_echo "Deprecated install location found, cannot remove without root access: $1"
  51. return
  52. fi
  53. info_echo "Removing old install location: $1"
  54. if [ $DRYRUN != 1 ]; then rm -rf $1; fi
  55. fi
  56. }
  57. remove_deprecated_install "/usr/local/bin/lyrebird/" 1
  58. if [ "$(id -u)" -ne 0 ]; then
  59. remove_deprecated_install "/usr/local/share/applications/Lyrebird.desktop" 1
  60. remove_deprecated_install "/usr/local/share/applications/lyrebird.desktop" 1
  61. fi
  62. if [ -d "/etc/lyrebird/" ]; then
  63. warning_echo "/etc/lyrebird/ is now deprecated, please relocate contents to ~/.config/lyrebird/ and delete"
  64. fi
  65. # Required pip3 modules space separated
  66. REQUIRED_PIP_MODULES="toml"
  67. # Create all of the directories if they don't exist
  68. if [ ! -d "$BIN_PATH" ]; then
  69. verbose_echo "Creating binary path: $BIN_PATH"
  70. if [ $DRYRUN != 1 ]; then
  71. mkdir -p "$BIN_PATH"
  72. chmod -R 755 "$BIN_PATH"
  73. fi
  74. fi
  75. if [ ! -d "$SHARE_PATH" ]; then
  76. verbose_echo "Creating share path: $SHARE_PATH"
  77. if [ $DRYRUN != 1 ]; then
  78. mkdir -p "$SHARE_PATH"
  79. chmod -R 755 "$SHARE_PATH"
  80. fi
  81. fi
  82. if [ ! -d "$DESKTOP_PATH" ]; then
  83. verbose_echo "Creating desktop path: $DESKTOP_PATH"
  84. if [ $DRYRUN != 1 ]; then
  85. mkdir -p "$DESKTOP_PATH"
  86. fi
  87. fi
  88. install_python_modules() {
  89. verbose_echo "Installing Python modules: $REQUIRED_PIP_MODULES"
  90. if [ $DRYRUN != 1 ]; then
  91. # Var not included in quotes so it installs each module
  92. pip3 install --prefix $INSTALL_PREFIX $REQUIRED_PIP_MODULES
  93. fi
  94. }
  95. install_binary_source() {
  96. verbose_echo "Copying app/ to: $SHARE_PATH"
  97. if [ $DRYRUN != 1 ]; then cp -rf app "$SHARE_PATH"; fi
  98. verbose_echo "Copying icon.png to: $SHARE_PATH"
  99. if [ $DRYRUN != 1 ]; then cp icon.png "$SHARE_PATH"; fi
  100. verbose_echo "Copying app.py to: $SHARE_PATH"
  101. if [ $DRYRUN != 1 ]; then cp app.py "$SHARE_PATH"; fi
  102. verbose_echo "Copying lyrebird to: $BIN_PATH"
  103. if [ $DRYRUN != 1 ]; then cp lyrebird "$BIN_PATH/lyrebird"; fi
  104. verbose_echo "Setting permissions 755 recursively for: $SHARE_PATH"
  105. if [ $DRYRUN != 1 ]; then chmod -R 755 "$SHARE_PATH"; fi
  106. }
  107. install_desktop() {
  108. verbose_echo "Copying lyrebird.desktop to: $DESKTOP_PATH"
  109. if [ $DRYRUN != 1 ]; then BIN_PATH=$BIN_PATH SHARE_PATH=$SHARE_PATH envsubst < lyrebird.desktop > $DESKTOP_PATH/lyrebird.desktop; fi
  110. verbose_echo "Setting permission 644 for: $DESKTOP_PATH/lyrebird.desktop"
  111. if [ $DRYRUN != 1 ]; then chmod -R 644 "$DESKTOP_PATH/lyrebird.desktop"; fi
  112. }
  113. verbose_space() { if [ $VERBOSE = 1 ]; then echo; fi }
  114. install_python_modules
  115. verbose_space
  116. install_binary_source
  117. verbose_space
  118. install_desktop
  119. verbose_space
  120. info_echo "Installed Lyrebird v$VERSION"