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.

280 lines
7.5KB

  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then
  3. wdir=$PWD
  4. wdir_connect="$wdir/src-local/hybrid/connect"
  5. toolsok='ok'
  6. # create wdir connect dir
  7. if [ ! -d $wdir_connect ];then
  8. mkdir -p $wdir_connect
  9. fi
  10. #check for jq
  11. if ! command -v jq &> /dev/null
  12. then
  13. toolsok='no'
  14. echo "jq could not be found"
  15. exit
  16. fi
  17. # check version >15
  18. if ! command -v node &> /dev/null
  19. then
  20. toolsok='no'
  21. echo ""
  22. echo "No node found"
  23. echo ""
  24. echo "Install: https://github.com/nodesource/distributions"
  25. echo "Install it and try again!"
  26. echo ""
  27. echo "-----------USING UBUNTU------------"
  28. echo "curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -"
  29. echo "sudo apt-get install -y nodejs"
  30. echo ""
  31. exit
  32. else
  33. nodeversion=$(node -v | cut -d'.' -f1)
  34. nodeversion="${nodeversion#v}"
  35. if [ $nodeversion -lt 15 ];then
  36. echo ""
  37. echo "node version < 15"
  38. echo ""
  39. echo "Update: https://github.com/nodesource/distributions"
  40. echo "Update it and try again!"
  41. echo ""
  42. echo "-----------USING UBUNTU------------"
  43. echo "curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -"
  44. echo "sudo apt-get install -y nodejs"
  45. echo ""
  46. toolsok='no'
  47. exit
  48. fi
  49. fi
  50. #check for docker
  51. if ! command -v docker &> /dev/null
  52. then
  53. echo ""
  54. echo "Cannot find docker"
  55. echo ""
  56. echo "Install it and try again!"
  57. echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
  58. echo ""
  59. echo "-----------USING UBUNTU------------"
  60. echo "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
  61. echo "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\""
  62. echo "sudo apt update"
  63. echo "sudo apt install -y docker-ce"
  64. echo "sudo usermod -aG docker [USERNAME]"
  65. echo ""
  66. toolsok='no'
  67. exit
  68. else
  69. #check if docker UP
  70. dockerserverdown=$(docker info --format "{{json .}}" | jq .ServerErrors)
  71. if [[ $dockerversion == *denied* ]]; then
  72. echo ""
  73. echo "docker server is down"
  74. echo ""
  75. docker info --format "{{json .}}" | jq .ServerErrors
  76. echo ""
  77. echo "-----------USING UBUNTU------------"
  78. echo ""
  79. echo "Using the following commands you can enable and run docker server";
  80. echo "sudo systemctl enable docker"
  81. echo "sudo systemctl start docker"
  82. echo "sudo systemctl status docker"
  83. echo ""
  84. echo "After adding to the group (usermod command) your shell needs to be restarted. If you dont know what this means please just logout and log in again.";
  85. echo ""
  86. toolsok='no'
  87. exit
  88. fi
  89. #check docker version
  90. dockerversion=$(docker info --format "{{json .}}" | jq .ServerVersion | cut -d'.' -f1)
  91. if [[ ! -z $dockerversion && $dockerversion != 'null' ]] ;then
  92. dockerversion="${dockerversion#\"}"
  93. if [ $dockerversion -lt 19 ];then
  94. echo ""
  95. echo "docker version < 19"
  96. echo ""
  97. echo "Update docker and try again!"
  98. echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
  99. echo ""
  100. echo "-----------USING UBUNTU------------"
  101. echo "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
  102. echo "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\""
  103. echo "sudo apt update"
  104. echo "sudo apt install -y docker-ce"
  105. echo "sudo usermod -aG docker [USERNAME]"
  106. echo ""
  107. toolsok='no'
  108. exit
  109. fi
  110. else
  111. echo ""
  112. echo "-----------USING UBUNTU------------"
  113. echo ""
  114. echo "Using the following commands you can enable and run docker server";
  115. echo "sudo systemctl enable docker"
  116. echo "sudo systemctl start docker"
  117. echo "sudo systemctl status docker"
  118. echo ""
  119. echo "After adding to the group (usermod command) your shell needs to be restarted. If you dont know what this means please just logout and log in again.";
  120. echo ""
  121. toolsok='no'
  122. exit
  123. fi
  124. fi
  125. #check for docker-compose
  126. if ! command -v docker-compose &> /dev/null
  127. then
  128. echo ""
  129. echo "Cannot find docker-compose"
  130. echo "Install it and try again!"
  131. echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
  132. echo ""
  133. echo "-----------USING UBUNTU------------"
  134. echo ""
  135. echo "sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose"
  136. echo "sudo chmod +x /usr/local/bin/docker-compose"
  137. echo "sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose"
  138. echo ""
  139. toolsok='no'
  140. exit
  141. else
  142. dockercomposeversion=$(docker-compose -f $wdir/test/run.yml config --services)
  143. if [ $dockercomposeversion != 'swarmlabclient' ];then
  144. echo ""
  145. echo "Cannot find docker-compose"
  146. echo "Install it and try again!"
  147. echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
  148. echo ""
  149. echo "-----------USING UBUNTU------------"
  150. echo ""
  151. echo "sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose"
  152. echo "sudo chmod +x /usr/local/bin/docker-compose"
  153. echo "sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose"
  154. echo ""
  155. toolsok='no'
  156. exit
  157. fi
  158. fi
  159. #check for wireguard
  160. if ! command -v wg &> /dev/null
  161. then
  162. echo ""
  163. /bin/bash ./install/install-wg.sh
  164. echo ""
  165. # echo "Cannot find wg"
  166. # echo "Install it and try again!"
  167. # echo "https://www.wireguard.com/install/"
  168. # echo ""
  169. # echo "-----------USING UBUNTU------------"
  170. # echo ""
  171. # echo "sudo apt install wireguard"
  172. # echo ""
  173. toolsok='no'
  174. exit
  175. fi
  176. #check for pm2
  177. if ! command -v pm2 &> /dev/null
  178. then
  179. toolsok='no'
  180. echo "pm2 could not be found"
  181. echo "sudo npm install -g pm2"
  182. exit
  183. fi
  184. # npm install
  185. #if [ $toolsok == 'ok' ];then
  186. # npm install
  187. # npm audit fix
  188. #fi
  189. if [ $toolsok == 'ok' ];then
  190. cd src-local
  191. npm install
  192. npm audit fix
  193. cd $wdir
  194. fi
  195. if [ $toolsok == 'ok' ];then
  196. #cp -f $wdir/files/VuetableCssConfig.js $wdir/node_modules/vuetable-2/src/components/VuetableCssConfig.js
  197. #cp -f $wdir/files/serve.js $wdir/node_modules/@vue/cli-service/lib/commands/serve.js
  198. cp -f $wdir/files/status.sh $wdir/src-local/hybrid/connect/status.sh
  199. cp -f $wdir/files/get-swarmlab-ca $wdir/src-local/hybrid/connect/get-swarmlab-ca
  200. cp -f $wdir/files/get-base-ca $wdir/src-local/hybrid/connect/get-base-ca
  201. mkdir -p $wdir/src-local/instance
  202. mkdir -p $wdir/src-local/builders
  203. cat << FOE > $wdir/src-local/ecosystem.config.js
  204. module.exports = {
  205. "apps": [
  206. {
  207. "name" : "hybridserver",
  208. "autorestart" : true,
  209. "watch" : true,
  210. "cwd" : "$wdir/src-local",
  211. "script" : "./llo/new.js",
  212. "run_as_user" : "node",
  213. "args" : "start",
  214. "pid_file" : "$wdir/src-local/pid.pid",
  215. "log_type" : "json",
  216. "log_file" : "$wdir/src-local/logs/logfile",
  217. "error_file" : "$wdir/src-local/logs/errorfile",
  218. "out_file" : "$wdir/src-local/logs/outfile",
  219. "log_date_format": "YYYY-MM-DD HH:mm Z",
  220. "merge_logs" : true,
  221. "exec_mode" : "fork",
  222. "max_restarts": 10,
  223. "max_memory_restart": "500M",
  224. "restart_delay": 1000
  225. },
  226. ]
  227. }
  228. FOE
  229. fi
  230. sudo bash ./src-local/hybrid/connect/get-base-ca
  231. sudo bash ./src-local/hybrid/connect/get-swarmlab-ca
  232. #echo $nodeversion
  233. #echo $dockerversion
  234. #echo $dockercomposeversion
  235. #echo $wdir
  236. #echo $wdir_connect
  237. echo "-------------------------"
  238. echo " --------READY------- "
  239. echo "-------------------------"
  240. echo " Start Server: ./start.sh "
  241. echo ""
  242. echo " Stop Server: ./stop.sh "
  243. echo ""
  244. else
  245. echo ""
  246. echo "-------------------------"
  247. echo "Run ./install.sh as Non-Root User"
  248. echo "-------------------------"
  249. echo ""
  250. fi