rebuild-wekan.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!/bin/bash
  2. echo "Recommended for development: Debian 12 amd64, directly to SSD disk or dual boot, not VM. Works fast."
  3. echo "Note1: If you use other locale than en_US.UTF-8 , you need to additionally install en_US.UTF-8"
  4. echo " with 'sudo dpkg-reconfigure locales' , so that MongoDB works correctly."
  5. echo " You can still use any other locale as your main locale."
  6. echo "Note2: Console output is also logged to ../wekan-log.txt"
  7. function pause(){
  8. read -p "$*"
  9. }
  10. echo
  11. PS3='Please enter your choice: '
  12. options=("Install Wekan dependencies" "Build Wekan" "Run Meteor for dev on http://localhost:4000" "Run Meteor for dev on http://localhost:4000 with trace warnings, and warnings using old Meteor API that will not exist in Meteor 3.0" "Run Meteor for dev on http://localhost:4000 with bundle visualizer" "Run Meteor for dev on http://CURRENT-IP-ADDRESS:4000" "Run Meteor for dev on http://CURRENT-IP-ADDRESS:4000 with MONGO_URL=mongodb://127.0.0.1:27019/wekan" "Run Meteor for dev on http://CUSTOM-IP-ADDRESS:PORT" "Save Meteor dependency chain to ../meteor-deps.txt" "Quit")
  13. select opt in "${options[@]}"
  14. do
  15. case $opt in
  16. "Install Wekan dependencies")
  17. if [[ "$OSTYPE" == "linux-gnu" ]]; then
  18. echo "Linux";
  19. # Debian, Ubuntu, Mint
  20. sudo apt install -y build-essential gcc g++ make git curl wget p7zip-full zip unzip unp npm p7zip-full
  21. #curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  22. #sudo apt-get install -y nodejs
  23. #sudo apt-get install -y npm
  24. # Volta Node and NPM install manager, made with Rust https://volta.sh
  25. # Volta uses home directory also with "npm -g install", no sudo needed.
  26. # Volta install script is broken, so using n.
  27. #curl https://get.volta.sh | bash
  28. #export VOLTA_HOME="$HOME/.volta"
  29. #export PATH="$VOLTA_HOME/bin:$PATH"
  30. #volta install node@14
  31. # npm nodejs
  32. #curl -0 -L https://npmjs.org/install.sh | sudo sh
  33. #sudo chown -R $(id -u):$(id -g) $HOME/.npm
  34. sudo npm -g install n
  35. # Using custom Node.js mirror with n Node.js version manager
  36. # - Custom source: https://github.com/tj/n#custom-source
  37. # - sudo -E uses existing environment variables, so that this can be used in build script:
  38. # https://github.com/tj/n/issues/584#issuecomment-523640742
  39. export N_NODE_MIRROR=https://github.com/wekan/node-v14-esm/releases/download
  40. sudo -E n 14.21.4
  41. sudo npm -g uninstall node-pre-gyp
  42. # Latest fibers for Meteor sudo mkdir -p /usr/local/lib/node_modules/fibers/.node-gyp sudo npm -g install fibers
  43. sudo npm -g install @mapbox/node-pre-gyp
  44. # Install Meteor, if it's not yet installed
  45. sudo npm -g install meteor@2.14 --unsafe-perm
  46. #sudo chown -R $(id -u):$(id -g) $HOME/.npm $HOME/.meteor
  47. elif [[ "$OSTYPE" == "darwin"* ]]; then
  48. echo "macOS"
  49. softwareupdate --install-rosetta --agree-to-license
  50. brew install npm
  51. # Install n for home directory version of Node.js 14.21.4
  52. npm -g install n
  53. directory_name="~/.n"
  54. if [ ! -d "$directory_name" ]; then
  55. mkdir "$directory_name"
  56. echo "Directory '$directory_name' created."
  57. else
  58. echo "Directory '$directory_name' already exists."
  59. fi
  60. directory_name="~/.npm"
  61. if [ ! -d "$directory_name" ]; then
  62. mkdir "$directory_name"
  63. echo "Directory '$directory_name' created."
  64. else
  65. echo "Directory '$directory_name' already exists."
  66. fi
  67. if awk '/node-v14-esm/{found=1; exit} END{exit !found}' ~/.zshrc; then
  68. echo "The text node-v14-esm alread exists in .zshrc"
  69. else
  70. echo "The text node-v14-esm does not exist in .zshrc, adding for install node v14"
  71. echo "export N_NODE_MIRROR=https://github.com/wekan/node-v14-esm/releases/download" >> ~/.zshrc
  72. export N_NODE_MIRROR="https://github.com/wekan/node-v14-esm/releases/download"
  73. fi
  74. if awk '/export N_PREFIX/{found=1; exit} END{exit !found}' ~/.zshrc; then
  75. echo "The text export N_PREFIX for local ~/.n directory already exists in .zshrc"
  76. else
  77. # echo "The text export N_PREFIX for local ~/.n directory does not exist in .zshrc, adding."
  78. echo "export N_PREFIX=~/.n" >> ~/.zshrc
  79. export N_PREFIX=~/.n
  80. fi
  81. npm config set prefix '~/.npm'
  82. n 14.21.4
  83. npm -g uninstall node-pre-gyp
  84. npm -g install @mapbox/node-pre-gyp
  85. npm -g install meteor@2.14
  86. export PATH=~/.meteor:$PATH
  87. exit;
  88. elif [[ "$OSTYPE" == "cygwin" ]]; then
  89. # POSIX compatibility layer and Linux environment emulation for Windows
  90. echo "TODO: Add Cygwin";
  91. exit;
  92. elif [[ "$OSTYPE" == "msys" ]]; then
  93. # Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
  94. echo "TODO: Add msys on Windows";
  95. exit;
  96. elif [[ "$OSTYPE" == "win32" ]]; then
  97. # I'm not sure this can happen.
  98. echo "TODO: Add Windows";
  99. exit;
  100. elif [[ "$OSTYPE" == "freebsd"* ]]; then
  101. echo "TODO: Add FreeBSD";
  102. exit;
  103. else
  104. echo "Unknown"
  105. echo ${OSTYPE}
  106. exit;
  107. fi
  108. break
  109. ;;
  110. "Build Wekan")
  111. echo "Building Wekan."
  112. #if [[ "$OSTYPE" == "darwin"* ]]; then
  113. # echo "sed at macOS";
  114. # sed -i '' 's/api\.versionsFrom/\/\/api.versionsFrom/' ~/repos/wekan/packages/meteor-useraccounts-core/package.js
  115. #else
  116. # echo "sed at ${OSTYPE}"
  117. # sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' ~/repos/wekan/packages/meteor-useraccounts-core/package.js
  118. #fi
  119. #cd ..
  120. #sudo chown -R $(id -u):$(id -g) $HOME/.npm $HOME/.meteor
  121. rm -rf .build/bundle node_modules .meteor/local .build
  122. meteor npm install --production
  123. meteor build .build --directory --platforms=web.browser
  124. rm -rf .build/bundle/programs/web.browser.legacy
  125. (cd .build/bundle/programs/server && rm -rf node_modules && chmod u+w *.json && meteor npm install --production)
  126. (cd .build/bundle/programs/server/node_modules/fibers && node build.js)
  127. (cd .build/bundle/programs/server/npm/node_modules/meteor/accounts-password && meteor npm remove bcrypt && meteor npm install bcrypt --production)
  128. # Cleanup
  129. cd .build/bundle
  130. find . -type d -name '*-garbage*' | xargs rm -rf
  131. find . -name '*phantom*' | xargs rm -rf
  132. find . -name '.*.swp' | xargs rm -f
  133. find . -name '*.swp' | xargs rm -f
  134. cd ../..
  135. # Add fibers multi arch
  136. #cd .build/bundle/programs/server/node_modules/fibers/bin
  137. #curl https://releases.wekan.team/fibers-multi.7z -o fibers-multi.7z
  138. #7z x fibers-multi.7z
  139. #rm fibers-multi.7z
  140. #cd ../../../../../../..
  141. echo Done.
  142. break
  143. ;;
  144. "Run Meteor for dev on http://localhost:4000")
  145. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  146. #---------------------------------------------------------------------
  147. # Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  148. #WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings"
  149. WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://localhost:4000 meteor run --exclude-archs web.browser.legacy,web.cordova --port 4000 2>&1 | tee ../wekan-log.txt
  150. #---------------------------------------------------------------------
  151. break
  152. ;;
  153. "Run Meteor for dev on http://localhost:4000 with trace warnings, and warnings using old Meteor API that will not exist in Meteor 3.0")
  154. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  155. #---------------------------------------------------------------------
  156. # Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  157. WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings" WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://localhost:4000 meteor run --exclude-archs web.browser.legacy,web.cordova --port 4000 2>&1 | tee ../wekan-log.txt
  158. #---------------------------------------------------------------------
  159. break
  160. ;;
  161. "Run Meteor for dev on http://localhost:4000 with bundle visualizer")
  162. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  163. #---------------------------------------------------------------------
  164. #Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  165. #WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings"
  166. WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://localhost:4000 meteor run --exclude-archs web.browser.legacy,web.cordova --port 4000 --extra-packages bundle-visualizer --production 2>&1 | tee ../wekan-log.txt
  167. #---------------------------------------------------------------------
  168. break
  169. ;;
  170. "Run Meteor for dev on http://CURRENT-IP-ADDRESS:4000")
  171. if [[ "$OSTYPE" == "darwin"* ]]; then
  172. IPADDRESS=$(ifconfig | grep broadcast | grep 'inet ' | cut -d: -f2 | awk '{ print $2}' | cut -d '/' -f 1 | grep '192.')
  173. else
  174. IPADDRESS=$(ip a | grep 'noprefixroute' | grep 'inet ' | cut -d: -f2 | awk '{ print $2}' | cut -d '/' -f 1 | grep '192.')
  175. fi
  176. echo "Your IP address is $IPADDRESS"
  177. #---------------------------------------------------------------------
  178. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  179. #---------------------------------------------------------------------
  180. #Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  181. #WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings"
  182. WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://$IPADDRESS:4000 meteor run --exclude-archs web.browser.legacy,web.cordova --port 4000 2>&1 | tee ../wekan-log.txt
  183. #---------------------------------------------------------------------
  184. break
  185. ;;
  186. "Run Meteor for dev on http://CURRENT-IP-ADDRESS:4000 with MONGO_URL=mongodb://127.0.0.1:27019/wekan")
  187. if [[ "$OSTYPE" == "darwin"* ]]; then
  188. IPADDRESS=$(ifconfig | grep broadcast | grep 'inet ' | cut -d: -f2 | awk '{ print $2}' | cut -d '/' -f 1 | grep '192.')
  189. else
  190. IPADDRESS=$(ip a | grep 'noprefixroute' | grep 'inet ' | cut -d: -f2 | awk '{ print $2}' | cut -d '/' -f 1 | grep '192.')
  191. fi
  192. echo "Your IP address is $IPADDRESS"
  193. #---------------------------------------------------------------------
  194. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  195. #---------------------------------------------------------------------
  196. #Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  197. #WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings"
  198. MONGO_URL=mongodb://127.0.0.1:27019/wekan WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://$IPADDRESS:4000 meteor run --exclude-archs web.browser.legacy,web.cordova --port 4000 2>&1 | tee ../wekan-log.txt
  199. #---------------------------------------------------------------------
  200. break
  201. ;;
  202. "Run Meteor for dev on http://CUSTOM-IP-ADDRESS:PORT")
  203. ip address
  204. echo "From above list, what is your IP address?"
  205. read IPADDRESS
  206. echo "On what port you would like to run Wekan?"
  207. read PORT
  208. echo "ROOT_URL=http://$IPADDRESS:$PORT"
  209. #---------------------------------------------------------------------
  210. #Not in use, could increase RAM usage: NODE_OPTIONS="--max_old_space_size=4096"
  211. #---------------------------------------------------------------------
  212. #Logging of terminal output to console and to ../wekan-log.txt at end of this line: 2>&1 | tee ../wekan-log.txt
  213. #WARN_WHEN_USING_OLD_API=true NODE_OPTIONS="--trace-warnings"
  214. WRITABLE_PATH=.. WITH_API=true RICHER_CARD_COMMENT_EDITOR=false ROOT_URL=http://$IPADDRESS:$PORT meteor run --exclude-archs web.browser.legacy,web.cordova --port $PORT 2>&1 | tee ../wekan-log.txt
  215. #---------------------------------------------------------------------
  216. break
  217. ;;
  218. "Save Meteor dependency chain to ../meteor-deps.txt")
  219. meteor list --tree > ../meteor-deps.txt
  220. echo "Saved Meteor dependency chain to ../meteor-deps.txt"
  221. #---------------------------------------------------------------------
  222. break
  223. ;;
  224. "Quit")
  225. break
  226. ;;
  227. *) echo invalid option;;
  228. esac
  229. done