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 9.1KB

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