install.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 [ -d "Hikka/hikka" ]; then
  41. cd Hikka || {
  42. printf "\rError: Install git package and re-run installer"
  43. exit 6
  44. }
  45. DIR_CHANGED="yes"
  46. fi
  47. if [ -f ".setup_complete" ]; then
  48. # If hikka is already installed by this script
  49. PYVER=""
  50. if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
  51. PYVER="3"
  52. fi
  53. printf "\rExisting installation detected"
  54. clear
  55. "python$PYVER" -m hikka "$@"
  56. exit $?
  57. elif [ "$DIR_CHANGED" = "yes" ]; then
  58. cd ..
  59. fi
  60. ##############################################################################
  61. echo "Installing..." >hikka-install.log
  62. if echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/debian_version' ]; then
  63. PKGMGR="apt install -y"
  64. runout dpkg --configure -a
  65. runout apt update
  66. PYVER="3"
  67. elif echo "$OSTYPE" | grep -qE '^linux-gnu.*' && [ -f '/etc/arch-release' ]; then
  68. PKGMGR="pacman -Sy --noconfirm"
  69. PYVER="3"
  70. elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
  71. runout apt update
  72. PKGMGR="apt install -y"
  73. PYVER=""
  74. elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
  75. if ! command -v brew >/dev/null; then
  76. ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
  77. fi
  78. PKGMGR="brew install"
  79. PYVER="3"
  80. else
  81. printf "\r\033[1;31mUnrecognised OS.\e[0m Please follow 'Manual installation' at \033[0;94mhttps://github.com/hikariatama/Hikka/#-installation\e[0m"
  82. exit 1
  83. fi
  84. ##############################################################################
  85. runout "$SUDO_CMD $PKGMGR python$PYVER" git || {
  86. errorout "Core install failed."
  87. exit 2
  88. }
  89. printf "\r\033[K\033[0;32mPreparation complete!\e[0m"
  90. printf "\n\r\033[0;34mInstalling linux packages...\e[0m"
  91. if echo "$OSTYPE" | grep -qE '^linux-gnu.*'; then
  92. runout "$SUDO_CMD $PKGMGR python$PYVER-dev"
  93. runout "$SUDO_CMD $PKGMGR python$PYVER-pip"
  94. runout "$SUDO_CMD $PKGMGR python3 python3-pip git python3-dev \
  95. libwebp-dev libz-dev libjpeg-dev libopenjp2-7 libtiff5 \
  96. ffmpeg imamgemagick libffi-dev libcairo2"
  97. elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
  98. runout "$SUDO_CMD $PKGMGR openssl libjpeg-turbo libwebp libffi libcairo build-essential libxslt libiconv git ncurses-utils"
  99. elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
  100. runout "$SUDO_CMD$ $PKGMGR jpeg webp"
  101. fi
  102. printf "\r\033[K\033[0;32mPackages installed!\e[0m"
  103. printf "\n\r\033[0;34mCloning repo...\e[0m"
  104. ##############################################################################
  105. # shellcheck disable=SC2086
  106. ${SUDO_CMD}rm -rf Hikka
  107. # shellcheck disable=SC2086
  108. runout ${SUDO_CMD}git clone https://github.com/hikariatama/Hikka/ || {
  109. errorout "Clone failed."
  110. exit 3
  111. }
  112. cd Hikka || {
  113. printf "\r\033[0;33mRun: \033[1;33mpkg install git\033[0;33m and restart installer"
  114. exit 7
  115. }
  116. printf "\r\033[K\033[0;32mRepo cloned!\e[0m"
  117. printf "\n\r\033[0;34mInstalling python dependencies...\e[0m"
  118. # shellcheck disable=SC2086
  119. runin "$SUDO_CMD python$PYVER" -m pip install --upgrade pip setuptools wheel --user
  120. # shellcheck disable=SC2086
  121. runin "$SUDO_CMD python$PYVER" -m pip install -r requirements.txt --upgrade --user --no-warn-script-location --disable-pip-version-check || {
  122. errorin "Requirements failed!"
  123. exit 4
  124. }
  125. rm -f ../hikka-install.log
  126. touch .setup_complete
  127. printf "\r\033[K\033[0;32mDependencies installed!\e[0m"
  128. printf "\n\033[0;32mStarting...\e[0m\n\n"
  129. ${SUDO_CMD}"python$PYVER" -m hikka "$@" || {
  130. printf "\033[1;31mPython scripts failed\e[0m"
  131. exit 5
  132. }