You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i.lin.sh 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/bash
  2. # Default values
  3. DEFAULT_REPOSERVER="http://git.bbh"
  4. DEFAULT_DEFAULTREPOOWNER="chess"
  5. DEFAULT_INSTANCENAME="cihsr"
  6. DEFAULT_INSTANCETYPE="development"
  7. DEFAULT_GITUSER="pb"
  8. DEFAULT_GITEMAIL="chess@bbh.org.in"
  9. # Prompt for user input with default values
  10. echo "Enter repo server URL (default: $DEFAULT_REPOSERVER):"
  11. read reposervername
  12. REPOSERVER=${reposervername:-$DEFAULT_REPOSERVER}
  13. echo "Enter default repo owner (default: $DEFAULT_DEFAULTREPOOWNER):"
  14. read defaultrepoownername
  15. DEFAULTREPOOWNER=${defaultrepoownername:-$DEFAULT_DEFAULTREPOOWNER}
  16. REPOOWNER=$DEFAULTREPOOWNER
  17. echo "Enter instance name (default: $DEFAULT_INSTANCENAME):"
  18. read instancename
  19. INSTANCENAME=${instancename:-$DEFAULT_INSTANCENAME}
  20. echo "Enter instance type (default: $DEFAULT_INSTANCETYPE):"
  21. read instancetypename
  22. INSTANCETYPE=${instancetypename:-$DEFAULT_INSTANCETYPE}
  23. echo "Enter Git user name (default: $DEFAULT_GITUSER):"
  24. read GITUSERID
  25. GITUSER=${GITUSERID:-$DEFAULT_GITUSER}
  26. echo "Enter Git user email (default: $DEFAULT_GITEMAIL):"
  27. read GITEMAILID
  28. GITEMAIL=${GITEMAILID:-$DEFAULT_GITEMAIL}
  29. # Prompt for skipping prerequisites
  30. echo "Do you want to skip prerequisite installations? (yes/no, default: no)"
  31. read skipprereqs
  32. SKIPPREREQS=${skipprereqs:-"no"}
  33. # Prompt for skipping dev prerequisites
  34. echo "Do you want to skip development prerequisite installations? (yes/no, default: no)"
  35. read skipdevprereqs
  36. SKIPDEVPREREQS=${skipdevprereqs:-"no"}
  37. # Prompt for ROOT folder, with two options: current directory or /var/chess/$INSTANCENAME/$INSTANCETYPE
  38. echo "Enter the ROOT folder location (default: current directory):"
  39. echo "1) Current directory"
  40. echo "2) /var/chess/$INSTANCENAME/$INSTANCETYPE"
  41. read rootfolder
  42. if [ "$rootfolder" == "2" ]; then
  43. ROOT=/var/chess/$INSTANCENAME/$INSTANCETYPE
  44. else
  45. ROOT=$(pwd) # Default to current directory if user chooses 1
  46. fi
  47. # If ROOT is not the current directory, create the necessary directories and change to ROOT
  48. if [ "$ROOT" != "$(pwd)" ]; then
  49. sudo mkdir -p /var/chess
  50. sudo chown $USER:$USER /var/chess
  51. mkdir -p /var/chess/$INSTANCENAME
  52. sudo chown $USER:$USER /var/chess/$INSTANCENAME
  53. mkdir -p $ROOT
  54. sudo chown $USER:$USER $ROOT
  55. # Change to ROOT directory
  56. cd $ROOT || { echo "Failed to change to ROOT directory $ROOT"; exit 1; }
  57. fi
  58. # Platform-specific installation
  59. if [ -f /etc/os-release ]; then
  60. . /etc/os-release
  61. OS_NAME=$NAME
  62. OS_VERSION=$VERSION_ID
  63. fi
  64. # Function to check if a package is installed
  65. is_package_installed() {
  66. local package=$1
  67. if command -v $package &>/dev/null; then
  68. return 0 # Package is installed
  69. else
  70. return 1 # Package is not installed
  71. fi
  72. }
  73. # Function to install packages based on the package manager
  74. install_package() {
  75. local package=$1
  76. if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
  77. sudo apt update
  78. sudo apt install -y $package || { echo "Failed to install $package"; exit 1; }
  79. elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
  80. # Prefer dnf for CentOS 8 and above
  81. if command -v dnf &>/dev/null; then
  82. sudo dnf install -y $package || { echo "Failed to install $package"; exit 1; }
  83. else
  84. sudo yum install -y $package || { echo "Failed to install $package"; exit 1; }
  85. fi
  86. else
  87. echo "Unsupported OS $OS_NAME"
  88. exit 1
  89. fi
  90. }
  91. # Install prerequisites
  92. if [ "$SKIPPREREQS" = "yes" ]; then
  93. echo "Skipping prerequisites for first run"
  94. else
  95. # Create group and add user (skip failure)
  96. sudo groupadd chessprod || echo "Group 'chessprod' already exists or failed to create, proceeding..."
  97. sudo usermod -a -G chessprod $USER || echo "Failed to add user $USER to chessprod group or already a member, proceeding..."
  98. # Install Git if not already installed
  99. if ! is_package_installed "git"; then
  100. install_package "git"
  101. fi
  102. git config --global user.name "$GITUSER"
  103. git config --global user.email "$GITEMAIL"
  104. git config --global credential.helper store
  105. # Install Python 2 if not installed
  106. if ! is_package_installed "python2"; then
  107. install_package "python2"
  108. fi
  109. # Install build tools based on OS type
  110. if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
  111. install_package "build-essential"
  112. elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
  113. install_package "gcc"
  114. install_package "make"
  115. install_package "glibc-devel"
  116. install_package "gcc-c++"
  117. fi
  118. # Installing Node.js and NVM
  119. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  120. sleep 2
  121. # Add NVM configuration to .bash_profile
  122. echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bash_profile
  123. echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bash_profile
  124. echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.bash_profile
  125. # Source .bash_profile to apply NVM setup
  126. source ~/.bash_profile
  127. # Install Node.js
  128. nvm install v16.19.1
  129. node --version
  130. npm --version
  131. # Install code editor (VSCode)
  132. if [[ "$OS_NAME" == "Ubuntu" ]] || [[ "$OS_NAME" == "Debian" ]]; then
  133. # VSCode installation for Debian-based systems (Ubuntu/Debian)
  134. install_package "wget"
  135. wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
  136. sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
  137. sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
  138. rm -f packages.microsoft.gpg
  139. sudo apt install apt-transport-https
  140. sudo apt update
  141. sudo apt install code -y
  142. elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
  143. # VSCode installation for CentOS-based systems (CentOS 8 / RHEL)
  144. sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
  145. sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
  146. sudo dnf check-update
  147. sudo dnf install code -y
  148. fi
  149. fi
  150. # Install OpenJDK 11 (Java) for both Debian/Ubuntu and CentOS/RHEL systems
  151. if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
  152. install_package "openjdk-11-jre-headless"
  153. elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
  154. # Install Java 11 on CentOS/RHEL-based systems
  155. sudo dnf install java-11-openjdk -y || { echo "Failed to install Java 11"; exit 1; }
  156. fi
  157. # MySQL Installation for CentOS (without debconf-set-selections)
  158. if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
  159. sudo dnf install mysql-server -y
  160. sudo systemctl start mysqld
  161. sudo systemctl enable mysqld
  162. MYSQL_ROOT_PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log | tail -n 1 | awk '{print $NF}')
  163. echo "MySQL root temporary password: $MYSQL_ROOT_PASSWORD"
  164. # Secure MySQL installation
  165. sudo mysql_secure_installation
  166. else
  167. # If on Ubuntu/Debian, you can use debconf-set-selections
  168. sudo debconf-set-selections <<EOF
  169. mysql-server mysql-server/lowercase-table-names select Enabled
  170. EOF
  171. sudo apt install mysql-server -y
  172. sudo systemctl start mysql
  173. fi
  174. git clone $REPOSERVER/$REPOOWNER/bbhverse
  175. cd bbhverse
  176. npm i
  177. cd ..
  178. git clone $REPOSERVER/$REPOOWNER/serververse
  179. git clone $REPOSERVER/$REPOOWNER/global-this
  180. git clone $REPOSERVER/$REPOOWNER/elxr.git
  181. # Install npm dependencies and link
  182. cd elxr
  183. npm i
  184. npm link
  185. cd ..
  186. sudo ln -s $ROOT/elxr/bin/elxr $(npm bin -g)/elxr
  187. elxr use $INSTANCENAME
  188. elxr install
  189. echo "Module configuration generated for: $INSTANCENAME"
  190. echo "module.exports = { instanceName : '$INSTANCENAME', reposerver: '$REPOSERVER', gitUser: '$GITUSER', gitEmail: '$GITEMAIL' }" > installchoices.js
  191. echo "Setup completed successfully!"