install.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/bash
  2. runin() {
  3. # Runs the arguments, piping stderr to logfile
  4. { "$@" 2>>../hikka-install.log || return $?; } | while read -r line; do
  5. printf "%s\n" "$line" >>../hikka-install.log
  6. done
  7. }
  8. runout() {
  9. # Runs the arguments, piping stderr to logfile
  10. { "$@" 2>>hikka-install.log || return $?; } | while read -r line; do
  11. printf "%s\n" "$line" >>hikka-install.log
  12. done
  13. }
  14. errorin() {
  15. cat ../hikka-install.log
  16. }
  17. errorout() {
  18. cat hikka-install.log
  19. }
  20. SUDO_CMD=""
  21. if [ ! x"$SUDO_USER" = x"" ]; then
  22. if command -v sudo >/dev/null; then
  23. SUDO_CMD="sudo -u $SUDO_USER "
  24. fi
  25. fi
  26. ##############################################################################
  27. clear
  28. clear
  29. printf "\n\e[1;35;47m \e[0m"
  30. printf "\n\e[1;35;47m █ █ █ █▄▀ █▄▀ ▄▀█ \e[0m"
  31. printf "\n\e[1;35;47m █▀█ █ █ █ █ █ █▀█ \e[0m"
  32. printf "\n\e[1;35;47m \e[0m"
  33. printf "\n\n\e[3;34;40m Installing...\e[0m\n\n"
  34. ##############################################################################
  35. printf "\r\033[0;34mPreparing for installation...\e[0m"
  36. touch hikka-install.log
  37. if [ ! x"$SUDO_USER" = x"" ]; then
  38. chown "$SUDO_USER:" hikka-install.log
  39. fi
  40. if [ ! x"" = x"$DYNO" ] && ! command -v python >/dev/null; then
  41. # We are running in a heroku dyno without python, time to get ugly!
  42. runout git clone https://github.com/heroku/heroku-buildpack-python || {
  43. printf "Bootstrap download failed!"
  44. exit 1
  45. }
  46. rm -rf .heroku .cache .profile.d requirements.txt runtime.txt .env
  47. mkdir .cache .env
  48. echo "python-3.9.6" >runtime.txt
  49. echo "pip" >requirements.txt
  50. STACK=heroku-18 runout bash heroku-buildpack-python/bin/compile /app /app/.cache /app/.env ||
  51. {
  52. printf "Bootstrap install failed!"
  53. exit 1
  54. }
  55. rm -rf .cache
  56. export PATH="/app/.heroku/python/bin:$PATH" # Prefer the bootstrapped python, incl. pip, over the system one.
  57. fi
  58. if [ -d "Hikka/hikka" ]; then
  59. cd Hikka || {
  60. printf "\rError: Install git package and re-run installer"
  61. exit 6
  62. }
  63. DIR_CHANGED="yes"
  64. fi
  65. if [ -f ".setup_complete" ] || [ -d "hikka" -a ! x"" = x"$DYNO" ]; then
  66. # If hikka is already installed by this script, or its in Heroku and installed
  67. PYVER=""
  68. if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
  69. PYVER="3"
  70. fi
  71. printf "\rExisting installation detected"
  72. clear
  73. "python$PYVER" -m hikka "$@"
  74. exit $?
  75. elif [ "$DIR_CHANGED" = "yes" ]; then
  76. cd ..
  77. fi
  78. ##############################################################################
  79. echo "Installing..." >hikka-install.log
  80. if echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then
  81. PKGMGR="apt install -y"
  82. runout dpkg --configure -a
  83. runout apt update
  84. PYVER="3"
  85. elif echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/arch-release' ]; then
  86. PKGMGR="pacman -Sy --noconfirm"
  87. PYVER="3"
  88. elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
  89. runout apt update
  90. PKGMGR="apt install -y"
  91. PYVER=""
  92. elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
  93. if ! command -v brew >/dev/null; then
  94. ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
  95. fi
  96. PKGMGR="brew install"
  97. PYVER="3"
  98. else
  99. printf "\r\033[1;31mUnrecognised OS.\e[0m Please follow 'Manual installation' at \033[0;94mhttps://github.com/hikariatama/Hikka/#-installation\e[0m"
  100. exit 1
  101. fi
  102. ##############################################################################
  103. runout "$SUDO_CMD $PKGMGR python$PYVER" git || {
  104. errorout "Core install failed."
  105. exit 2
  106. }
  107. printf "\r\033[K\033[0;32mPreparation complete!\e[0m"
  108. printf "\n\r\033[0;34mInstalling linux packages...\e[0m"
  109. if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
  110. runout "$SUDO_CMD $PKGMGR python$PYVER-dev"
  111. runout "$SUDO_CMD $PKGMGR python$PYVER-pip"
  112. runout "$SUDO_CMD $PKGMGR python3 python3-pip git python3-dev \
  113. libwebp-dev libz-dev libjpeg-dev libopenjp2-7 libtiff5 \
  114. ffmpeg imamgemagick libffi-dev libcairo2"
  115. elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
  116. runout "$SUDO_CMD $PKGMGR openssl libjpeg-turbo libwebp libffi libcairo build-essential libxslt libiconv git ncurses-utils"
  117. elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
  118. runout "$SUDO_CMD$ $PKGMGR jpeg webp"
  119. fi
  120. runout "$SUDO_CMD $PKGMGR neofetch dialog"
  121. printf "\r\033[K\033[0;32mPackages installed!\e[0m"
  122. printf "\n\r\033[0;34mCloning repo...\e[0m"
  123. ##############################################################################
  124. # shellcheck disable=SC2086
  125. ${SUDO_CMD}rm -rf Hikka
  126. # shellcheck disable=SC2086
  127. runout ${SUDO_CMD}git clone https://github.com/hikariatama/Hikka/ || {
  128. errorout "Clone failed."
  129. exit 3
  130. }
  131. cd Hikka || {
  132. printf "\r\033[0;33mRun: \033[1;33mpkg install git\033[0;33m and restart installer"
  133. exit 7
  134. }
  135. printf "\r\033[K\033[0;32mRepo cloned!\e[0m"
  136. printf "\n\r\033[0;34mInstalling python dependencies...\e[0m"
  137. # shellcheck disable=SC2086
  138. runin "$SUDO_CMD python$PYVER" -m pip install --upgrade pip setuptools wheel --user
  139. # shellcheck disable=SC2086
  140. runin "$SUDO_CMD python$PYVER" -m pip install -r requirements.txt --upgrade --user --no-warn-script-location --disable-pip-version-check || {
  141. errorin "Requirements failed!"
  142. exit 4
  143. }
  144. rm -f ../hikka-install.log
  145. touch .setup_complete
  146. printf "\r\033[K\033[0;32mDependencies installed!\e[0m"
  147. printf "\n\033[0;32mStarting...\e[0m\n\n"
  148. ${SUDO_CMD}"python$PYVER" -m hikka "$@" || {
  149. printf "\033[1;31mPython scripts failed\e[0m"
  150. exit 5
  151. }