2
0

init_mamba.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/bin/bash
  2. # License
  3. # Copyright (c) 2022 cmdr2 and contributors
  4. # Section I
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. # The above copyright notice and this permission notice shall be included in all
  12. # copies or substantial portions of the Software.
  13. # The person obtaining a copy of the Software meets the Use-based restrictions
  14. # as referenced in Section II paragraph 1.
  15. # The person obtaining a copy of the Software accepts that the Model or
  16. # Derivatives of the Model (as defined in the "CreativeML Open RAIL-M" license
  17. # accompanying this License) are subject to Section II paragraph 1.
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. # SOFTWARE.
  25. # Section II
  26. # 1. Use-based restrictions. The restrictions set forth in Attachment A are
  27. # considered Use-based restrictions. Therefore the person obtaining a copy of the
  28. # Software cannot use the Software for the specified restricted uses. The person
  29. # obtaining a copy of the Software may use the Software only for lawful purposes.
  30. # 2. Except as set forth herein, the authors or copyright holders claim no rights
  31. # in the results of operating the Software. The person obtaining a copy of the
  32. # Software is accountable for the results of operating the Software and its
  33. # subsequent uses.
  34. # 3. If any provision of this License is held to be invalid, illegal or
  35. # unenforceable, the remaining provisions shall be unaffected thereby and
  36. # remain valid as if such provision had not been set forth herein.
  37. # END OF TERMS AND CONDITIONS
  38. # Attachment A
  39. # Use Restrictions
  40. # The person obtaining a copy of the Software agrees not to use the Software:
  41. # - In any way that violates any applicable national, federal, state, local
  42. # or international law or regulation;
  43. # - For the purpose of exploiting, harming or attempting to exploit or harm
  44. # minors in any way;
  45. # - To generate or disseminate verifiably false information and/or content
  46. # with the purpose of harming others;
  47. # - To generate or disseminate personal identifiable information that can
  48. # be used to harm an individual;
  49. # - To defame, disparage or otherwise harass others;
  50. # - For fully automated decision making that adversely impacts an
  51. # individual’s legal rights or otherwise creates or modifies a binding,
  52. # enforceable obligation;
  53. # - For any use intended to or which has the effect of discriminating
  54. # against or harming individuals or groups based on online or offline
  55. # social behavior or known or predicted personal or personality
  56. # characteristics;
  57. # - To exploit any of the vulnerabilities of a specific group of persons
  58. # based on their age, social, physical or mental characteristics, in order
  59. # to materially distort the behavior of a person pertaining to that group
  60. # in a manner that causes or is likely to cause that person or another
  61. # person physical or psychological harm;
  62. # - For any use intended to or which has the effect of discriminating
  63. # against individuals or groups based on legally protected characteristics
  64. # or categories;
  65. # - To provide medical advice and medical results interpretation;
  66. # - To generate or disseminate information for the purpose to be used for
  67. # administration of justice, law enforcement, immigration or asylum
  68. # processes, such as predicting an individual will commit fraud/crime
  69. # commitment (e.g. by text profiling, drawing causal relationships between
  70. # assertions made in documents, indiscriminate and arbitrarily-targeted
  71. # use).
  72. # This script will install git and conda (if not found on the PATH variable)
  73. # using micromamba (an 8mb static-linked single-file binary, conda replacement).
  74. # For users who already have git and conda, this step will be skipped.
  75. # This enables a user to install this project without manually installing conda and git.
  76. fail() {
  77. echo
  78. echo "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
  79. echo
  80. if [ "$1" != "" ]; then
  81. echo ERROR: $1
  82. else
  83. echo An error occurred.
  84. fi
  85. cat <<EOF
  86. Error downloading TTS Generation WebUI. Sorry about that, please try to:
  87. 1. Run this installer again.
  88. 2. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.gg/V8BKTVRtJ9
  89. 3. If that doesn't solve the problem, please file an issue at https://github.com/rsxdalv/tts-generation-webui/issues
  90. Thanks!
  91. EOF
  92. read -p "Press any key to continue"
  93. exit 1
  94. }
  95. set -o pipefail
  96. OS_NAME=$(uname -s)
  97. case "${OS_NAME}" in
  98. Linux*) OS_NAME="linux";;
  99. Darwin*) OS_NAME="osx";;
  100. *) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit
  101. esac
  102. OS_ARCH=$(uname -m)
  103. case "${OS_ARCH}" in
  104. x86_64*) OS_ARCH="64";;
  105. arm64*) OS_ARCH="arm64";;
  106. aarch64*) OS_ARCH="arm64";;
  107. *) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit
  108. esac
  109. if ! which curl; then fail "'curl' not found. Please install curl."; fi
  110. if ! which tar; then fail "'tar' not found. Please install tar."; fi
  111. if ! which bzip2; then fail "'bzip2' not found. Please install bzip2."; fi
  112. if pwd | grep ' '; then fail "The installation directory's path contains a space character. Conda will fail to install. Please change the directory."; fi
  113. # https://mamba.readthedocs.io/en/latest/installation.html
  114. if [ "$OS_NAME" == "linux" ] && [ "$OS_ARCH" == "arm64" ]; then OS_ARCH="aarch64"; fi
  115. # config
  116. export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba"
  117. INSTALL_ENV_DIR="$(pwd)/installer_files/env"
  118. LEGACY_INSTALL_ENV_DIR="$(pwd)/installer"
  119. MICROMAMBA_DOWNLOAD_URL="https://micro.mamba.pm/api/micromamba/${OS_NAME}-${OS_ARCH}/latest"
  120. umamba_exists="F"
  121. # figure out whether git and conda needs to be installed
  122. if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi
  123. PACKAGES_TO_INSTALL="python=3.10.11 conda-forge::nodejs=22.9.0 conda pip==23.3.2 conda-forge::uv=0.4.17"
  124. if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi
  125. if "$MAMBA_ROOT_PREFIX/micromamba" --version &>/dev/null; then umamba_exists="T"; fi
  126. # (if necessary) install git and conda into a contained environment
  127. if [ "$PACKAGES_TO_INSTALL" != "" ]; then
  128. # download micromamba
  129. if [ "$umamba_exists" == "F" ]; then
  130. echo "Downloading micromamba from $MICROMAMBA_DOWNLOAD_URL to $MAMBA_ROOT_PREFIX/micromamba"
  131. mkdir -p "$MAMBA_ROOT_PREFIX"
  132. curl -L "$MICROMAMBA_DOWNLOAD_URL" | tar -xvj -O bin/micromamba > "$MAMBA_ROOT_PREFIX/micromamba"
  133. if [ "$?" != "0" ]; then
  134. echo
  135. echo "EE micromamba download failed"
  136. echo "EE If the lines above contain 'bzip2: Cannot exec', your system doesn't have bzip2 installed"
  137. echo "EE If there are network errors, please check your internet setup"
  138. fail "micromamba download failed"
  139. fi
  140. chmod u+x "$MAMBA_ROOT_PREFIX/micromamba"
  141. # test the mamba binary
  142. echo "Micromamba version:"
  143. "$MAMBA_ROOT_PREFIX/micromamba" --version
  144. fi
  145. # create the installer env
  146. echo "Checking if the Micromamba/Conda environment is already installed"
  147. if [ ! -e "$INSTALL_ENV_DIR" ]; then
  148. echo "Creating the Micromamba/Conda environment in $INSTALL_ENV_DIR"
  149. "$MAMBA_ROOT_PREFIX/micromamba" create -y --prefix "$INSTALL_ENV_DIR" || fail "unable to create the install environment"
  150. echo "Packages to install:$PACKAGES_TO_INSTALL"
  151. "$MAMBA_ROOT_PREFIX/micromamba" install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL
  152. if [ "$?" != "0" ]; then
  153. fail "Installation of the packages '$PACKAGES_TO_INSTALL' failed."
  154. fi
  155. else
  156. echo "Micromamba/Conda environment already installed in $INSTALL_ENV_DIR, skipping installation"
  157. fi
  158. if [ ! -e "$INSTALL_ENV_DIR" ]; then
  159. fail "There was a problem while installing $PACKAGES_TO_INSTALL using micromamba. Cannot continue."
  160. fi
  161. fi