MK404-build.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #!/bin/bash
  2. # This bash script is used to compile automatically and run the MK404 simulator
  3. #
  4. # Supported OS: Linux64 bit
  5. #
  6. # Linux:
  7. # Linux Ubuntu
  8. # 1. Follow these instructions
  9. # 2. Open Ubuntu bash and get latest updates with 'sudo apt-get update'
  10. # 3. Install latest updates with 'sudo apt-get upgrade'
  11. #
  12. #
  13. # Version: 1.0.0-Build_14
  14. # Change log:
  15. # 11 Feb 2021, 3d-gussner, Inital
  16. # 11 Feb 2021, 3d-gussner, Optional flags to check for updates
  17. # 12 Feb 2021, 3d-gussner, Update cmake
  18. # 13 Feb 2021, 3d-gussner, Auto build SD cards
  19. # 18 Jun 2021, 3d-gussner, Documentation and version number
  20. # 18 Jun 2021, 3d-gussner, Added some arguments and checks
  21. # 18 Jun 2021, 3d-gussner, Default extrusion graphics to line. Thanks @vintagepc point it out
  22. # 18 Jun 2021, 3d-gussner, Added -g 3 and 4 for more details extrusion lines
  23. # 18 Jun 2021, 3d-gussner, Check for updates is default. Fix update if internet connection is lost.
  24. # 21 Jun 2021, 3d-gussner, Change board_flash argument to 'y' and firmware_version to 'f'
  25. # 25 Jan 2021, 3d-gussner, Allow upper and lower case in selection
  26. # Add update option to release OR devel
  27. #### Start: Failures
  28. failures()
  29. {
  30. case "$1" in
  31. 0) echo "$(tput setaf 2)MK404-build.sh finished with success$(tput sgr0)" ;;
  32. 2) echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)" ; echo "Please refer to the notes of MK404-build.sh$(tput sgr0)" ; exit 2 ;;
  33. 3) echo "$(tput setaf 1)This script doesn't support your Operating system!"; echo "Please use Linux 64-bit"; echo "Read the notes of MK404-build.sh$(tput sgr0)" ; exit 2 ;;
  34. 4) echo "$(tput setaf 1)Some packages are missing please install these!$(tput sgr0)" ; exit 4 ;;
  35. 5) echo "$(tput setaf 1)Wrong printer chosen.$(tput sgr0) Following Printers are supported: MK25, MK25S, MK3 and MK3S" ; exit 5 ;;
  36. 6) echo "$(tput setaf 1)Unsupported board flash size chosen.$(tput sgr0) Only '256', '384', '512', '1024' and '32M' are allowed." ; exit 6 ;;
  37. 7) echo "$(tput setaf 1)Unsupported board mem size chosen.$(tput sgr0) Only '8', '16', '32' and '64' are allowed." ; exit 7 ;;
  38. 8) echo "$(tput setaf 1)No firmware version file selected!$(tput sgr0)" ; echo "Add argument -f with path and hex filename to start MK404" ; exit 8 ;;
  39. 9) echo "$(tput setaf 1)Tried to determine MK404 printer from hex file, but failed!$(tput sgr0)" ; "Add argument -p with 'MK25', 'MK25S', 'MK3' or 'MK3S' to start MK404" ; exit 9 ;;
  40. 10) echo "$(tput setaf 1)Missing printer$(tput sgr0)" ; exit 10 ;;
  41. esac
  42. }
  43. #### End: Failures
  44. #### Start: Check options
  45. ##check_options()
  46. ##{
  47. while getopts c:f:g:m:n:p:u:x:y:?h flag
  48. do
  49. case "${flag}" in
  50. c) check_flag=${OPTARG};;
  51. f) firmware_version_flag=${OPTARG};;
  52. g) mk404_graphics_flag=${OPTARG};;
  53. h) help_flag=1;;
  54. m) mk404_flag=${OPTARG};;
  55. n) new_build_flag=${OPTARG};;
  56. p) mk404_printer_flag=${OPTARG};;
  57. u) update_flag=${OPTARG};;
  58. x) board_mem_flag=${OPTARG};;
  59. y) board_flash_flag=${OPTARG};;
  60. ?) help_flag=1;;
  61. esac
  62. done
  63. #Debug echos
  64. #echo "c: $check_flag"
  65. #echo "f: $firmware_version_flag"
  66. #echo "g: $mk404_graphics_flag"
  67. #echo "m: $mk404_flag"
  68. #echo "n: $new_build_flag"
  69. #echo "p: $mk404_printer_flag"
  70. #echo "u: $update_flag"
  71. #echo "x: $board_mem_flag"
  72. #echo "y: $board_flash_flag"
  73. # '?' 'h' argument usage and help
  74. if [ "$help_flag" == "1" ] ; then
  75. echo "***************************************"
  76. echo "* MK404-build.sh Version: 1.0.0-Build_14 *"
  77. echo "***************************************"
  78. echo "Arguments:"
  79. echo "$(tput setaf 2)-c$(tput sgr0) Check for update"
  80. echo "$(tput setaf 2)-f$(tput sgr0) Prusa-Firmware version"
  81. echo "$(tput setaf 2)-g$(tput sgr0) Start MK404 graphics"
  82. echo "$(tput setaf 2)-h$(tput sgr0) Help"
  83. echo "$(tput setaf 2)-m$(tput sgr0) Start MK404 sim"
  84. echo "$(tput setaf 2)-n$(tput sgr0) Force new build"
  85. echo "$(tput setaf 2)-p$(tput sgr0) MK404 Printer"
  86. echo "$(tput setaf 2)-u$(tput sgr0) Update MK404"
  87. echo "$(tput setaf 2)-x$(tput sgr0) Board memory size"
  88. echo "$(tput setaf 2)-y$(tput sgr0) Board flash size"
  89. echo "$(tput setaf 2)-?$(tput sgr0) Help"
  90. echo
  91. echo "Brief USAGE:"
  92. echo " $(tput setaf 2)./MK404-build.sh$(tput sgr0) [-c] [-f] [-g] [-m] [-n] [-p] [-u] [-v] [-x] [-h] [-?]"
  93. echo
  94. echo " -c : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  95. echo " -f : '$(tput setaf 2)path+file name$(tput sgr0)'"
  96. echo " -g : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' lite, '$(tput setaf 2)2$(tput sgr0)' fancy, '$(tput setaf 2)3$(tput sgr0)' lite with Quad_HR, '$(tput setaf 2)4$(tput sgr0)' fancy with Quad_HR"
  97. echo " -m : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes '$(tput setaf 2)2$(tput sgr0)' with MMU2"
  98. echo " -n : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' yes"
  99. echo " -p : '$(tput setaf 2)MK25$(tput sgr0)', '$(tput setaf 2)MK25S$(tput sgr0)', '$(tput setaf 2)MK3$(tput sgr0)' or '$(tput setaf 2)MK3S$(tput sgr0)'"
  100. echo " -u : '$(tput setaf 2)0$(tput sgr0)' no, '$(tput setaf 2)1$(tput sgr0)' release ', '$(tput setaf 2)2$(tput sgr0)' devel '"
  101. echo " -x : '$(tput setaf 2)8$(tput sgr0)',$(tput setaf 2)16$(tput sgr0)',$(tput setaf 2)32$(tput sgr0)' or '$(tput setaf 2)64$(tput sgr0)' Kb."
  102. echo " -y : '$(tput setaf 2)256$(tput sgr0)','$(tput setaf 2)384$(tput sgr0)','$(tput setaf 2)512$(tput sgr0)','$(tput setaf 2)1024$(tput sgr0)''$(tput setaf 2)32M$(tput sgr0)'"
  103. echo
  104. echo "Example:"
  105. echo " $(tput setaf 2)./MK404-build.sh -f 1$(tput sgr0)"
  106. echo " Will force an update and rebuild the MK404 SIM"
  107. echo
  108. echo " $(tput setaf 2)./MK404-build.sh -m 1 -g 1 -f ../../../../Prusa-Firmware/PF-build-hex/FW3100-Build4481/BOARD_EINSY_1_0a/FW3100-Build4481-1_75mm_MK3S-EINSy10a-E3Dv6full.hex$(tput sgr0)"
  109. echo " Will start MK404 with Prusa_MK3S and Prusa-Firmware 3.10.0-Build4481"
  110. exit 1
  111. fi
  112. #Check MK404 agruments
  113. #Set Check for updates as default
  114. check_flag=1
  115. #Start: Check mk404_printer_flag
  116. if [ ! -z $mk404_printer_flag ]; then
  117. if [[ "$mk404_printer_flag" == "MK3" || "$mk404_printer_flag" == "MK3S" || "$mk404_printer_flag" == "MK25" || "$mk404_printer_flag" == "MK25S" ]]; then
  118. MK404_PRINTER_TEMP=$mk404_printer_flag
  119. else
  120. failures 5
  121. fi
  122. fi
  123. #End: Check mk404_printer_flag
  124. #Start: Check if Build is selected with argument '-f'
  125. if [ ! -z "$board_flash_flag" ] ; then
  126. if [ "$board_flash_flag" == "256" ] ; then
  127. BOARD_FLASH="0x3FFFF"
  128. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  129. elif [ "$board_flash_flag" == "384" ] ; then
  130. BOARD_FLASH="0x5FFFF"
  131. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  132. elif [ "$board_flash_flag" == "512" ] ; then
  133. BOARD_FLASH="0x7FFFF"
  134. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  135. elif [ "$board_flash_flag" == "1024" ] ; then
  136. BOARD_FLASH="0xFFFFF"
  137. echo "Board flash size : $board_flash_flag Kb, $BOARD_FLASH (hex)"
  138. elif [[ "$board_flash_flag" == "32M" || "$board_flash_flag" == "32768" ]] ; then
  139. BOARD_FLASH="0x1FFFFFF"
  140. echo "Board flash size : 32 Mb, $BOARD_FLASH (hex)"
  141. else
  142. failures 6
  143. fi
  144. fi
  145. #End: Check if Build is selected with argument '-f'
  146. #Start: Check if Build is selected with argument '-x'
  147. if [ ! -z "$board_mem_flag" ] ; then
  148. if [ "$board_mem_flag" == "8" ] ; then
  149. BOARD_MEM="0x21FF"
  150. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  151. elif [ "$board_mem_flag" == "16" ] ; then
  152. BOARD_MEM="0x3DFF"
  153. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  154. elif [ "$board_mem_flag" == "32" ] ; then
  155. BOARD_MEM="0x7DFF"
  156. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  157. elif [ "$board_mem_flag" == "64" ] ; then
  158. BOARD_MEM="0xFFFF"
  159. echo "Board mem size : $board_mem_flag Kb, $BOARD_MEM (hex)"
  160. else
  161. failures 7
  162. fi
  163. fi
  164. #End: Check if Build is selected with argument '-x'
  165. #Start: Check if new build is selected
  166. if [ "$new_build_flag" == "1" ]; then
  167. check_flag=1
  168. fi
  169. if [[ "$update_flag" == "1" || "$update_flag" == "2" ]]; then
  170. check_flag=1
  171. fi
  172. #End: Check if new build is selected
  173. # Prepare run MK404
  174. #Check MK404_Printer
  175. if [ ! -z $firmware_version_flag ]; then
  176. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK3')
  177. if [ ! -z $MK404_PRINTER_TEMP ]; then
  178. MK404_PRINTER=MK3
  179. fi
  180. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK3S')
  181. if [ ! -z $MK404_PRINTER_TEMP ]; then
  182. MK404_PRINTER=MK3S
  183. fi
  184. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK25')
  185. if [ ! -z $MK404_PRINTER_TEMP ]; then
  186. MK404_PRINTER=MK25
  187. fi
  188. MK404_PRINTER_TEMP=$(echo $firmware_version_flag | sed 's/\(.*\)\///' | grep 'MK25S')
  189. if [ ! -z $MK404_PRINTER_TEMP ]; then
  190. MK404_PRINTER=MK25S
  191. fi
  192. elif [[ ! -z $new_build_flag || ! -z $update_flag || ! -z $check_flag ]]; then
  193. echo "continue"
  194. else
  195. failures 8
  196. fi
  197. if [[ -z $MK404_PRINTER && -z $new_build_flag && -z $update_flag && -z $check_flag ]]; then
  198. failures 9
  199. fi
  200. if [ ! -z $mk404_printer_flag ]; then
  201. if [ "$mk404_printer_flag" != "$MK404_PRINTER" ]; then
  202. echo "$(tput setaf 3)You defined a different printer type than the firmware!"
  203. echo "This can cause unexpected issues.$(tput sgr 0)"
  204. echo
  205. PS3="Select $(tput setaf 2)printer$(tput sgr 0) you want to use."
  206. select which in "$(tput setaf 2)$MK404_PRINTER$(tput sgr 0)" "$mk404_printer_flag"; do
  207. case $which in
  208. $MK404_PRINTER)
  209. echo "Set $MK404_PRINTER as printer"
  210. break
  211. ;;
  212. $mk404_printer_flag)
  213. echo "Set $(tput setaf 3)$mk404_printer_flag$(tput sgr 0) as printer"
  214. echo "$(tput setaf 3)This firmware file isn't correct for this printer!!!$(tput sgr 0)"
  215. echo
  216. MK404_PRINTER=$mk404_printer_flag
  217. read -p "Press Enter to continue."
  218. break
  219. ;;
  220. *)
  221. break
  222. ;;
  223. esac
  224. done
  225. fi
  226. fi
  227. if [[ -z $MK404_PRINTER && -z $new_build_flag && -z $update_flag && -z $check_flag ]]; then
  228. failures 10
  229. fi
  230. if [[ "$MK404_PRINTER" == "MK25" || "$MK404_PRINTER" == "MK25S" ]]; then
  231. MK404_PRINTER="${MK404_PRINTER}_mR13"
  232. else
  233. if [ "$mk404_flag" == "2" ]; then # Check if MMU2 is selected only for MK3/S
  234. MK404_PRINTER="${MK404_PRINTER}MMU2"
  235. fi
  236. fi
  237. # Run MK404 with 'debugcore' and/or 'bootloader-file'
  238. if [[ ! -z $MK404_DEBUG && "$MK404_DEBUG" == "atmega404" || ! -z $BOARD_MEM && "$BOARD_MEM" == "0xFFFF" ]]; then
  239. MK404_options="--debugcore"
  240. fi
  241. if [[ ! -z $MK404_DEBUG && "$MK404_DEBUG" == "atmega404_no_bootloader" || ! -z $BOARD_FLASH && "$BOARD_FLASH" != "0x3FFFF" ]]; then
  242. MK404_options='--debugcore --bootloader-file ""'
  243. fi
  244. # Run MK404 with graphics
  245. if [ ! -z "$mk404_graphics_flag" ]; then
  246. if [ ! -z "$MK404_options" ]; then
  247. MK404_options="${MK404_options} -g "
  248. else
  249. MK404_options=" -g "
  250. fi
  251. if [[ "$mk404_graphics_flag" == "1" || "$mk404_graphics_flag" == "lite" || "$mk404_graphics_flag" == "3" ]]; then
  252. MK404_options="${MK404_options}lite"
  253. elif [[ "$mk404_graphics_flag" == "2" || "$mk404_graphics_flag" == "fancy" || "$mk404_graphics_flag" == "4" ]]; then
  254. MK404_options="${MK404_options}fancy"
  255. else
  256. echo "$(tput setaf 1)Unsupported MK404 graphics option $mk404_graphics_flag$(tput sgr 0)"
  257. fi
  258. if [[ "$mk404_graphics_flag" == "3" || "$mk404_graphics_flag" == "4" ]]; then
  259. MK404_options="${MK404_options} --colour-extrusion --extrusion Quad_HR"
  260. else
  261. MK404_options="${MK404_options} --extrusion Line"
  262. fi
  263. fi
  264. if [ ! -z $firmware_version_flag ]; then
  265. MK404_firmware_file=" -f $firmware_version_flag"
  266. fi
  267. #End: Check MK404 agruments
  268. ##}
  269. #### End: Check for options/flags
  270. #### Start: Check if OSTYPE is supported
  271. check_OS()
  272. {
  273. OS_FOUND=$( command -v uname)
  274. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  275. linux*)
  276. TARGET_OS="linux"
  277. ;;
  278. *)
  279. TARGET_OS='unknown'
  280. ;;
  281. esac
  282. # Linux
  283. if [ $TARGET_OS == "linux" ]; then
  284. if [ $(uname -m) == "x86_64" ]; then
  285. echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
  286. Processor="64"
  287. #elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  288. # echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
  289. # Processor="32"
  290. else
  291. failures 2
  292. fi
  293. else
  294. failures 3
  295. fi
  296. sleep 2
  297. }
  298. #### End: Check if OSTYPE is supported
  299. #### Start: Check MK404 dependencies
  300. check_packages()
  301. {
  302. packages=(
  303. "libelf-dev"
  304. "gcc-7"
  305. "gcc-avr"
  306. "libglew-dev"
  307. "freeglut3-dev"
  308. "libsdl-sound1.2-dev"
  309. "libpng-dev"
  310. "cmake"
  311. "zip"
  312. "wget"
  313. "git"
  314. "build-essential"
  315. "lcov"
  316. "mtools"
  317. )
  318. for check_package in ${packages[@]}; do
  319. if dpkg-query -W -f'${db:Status-Abbrev}\n' $check_package 2>/dev/null \
  320. | grep -q '^.i $'; then
  321. echo "$(tput setaf 2)$check_package: Installed$(tput sgr0)"
  322. else
  323. echo "$(tput setaf 1)$check_package: Not installed use $(tput setaf 3)'sudo apt install $check_package'$(tput setaf 1) to install missing package$(tput sgr0)"
  324. not_installed=1;
  325. fi
  326. done
  327. if [ "$not_installed" = "1" ]; then
  328. failures 4
  329. fi
  330. }
  331. #### End: Check MK404 dependencies
  332. #### Start: Set build environment
  333. set_build_env_variables()
  334. {
  335. MK404_SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  336. MK404_URL="https://github.com/vintagepc/MK404.git"
  337. MK404_owner="vintagepc"
  338. MK404_project="MK404"
  339. MK404_PATH="$MK404_SCRIPT_PATH/../MK404/master"
  340. MK404_BUILD_PATH="$MK404_PATH/build"
  341. }
  342. #### End: Set build environment
  343. #### Start: List few useful data
  344. output_useful_data()
  345. {
  346. echo
  347. echo "Script path :" $MK404_SCRIPT_PATH
  348. echo "OS :" $TARGET_OS
  349. echo ""
  350. echo "MK404 path :" $MK404_PATH
  351. }
  352. #### End: List few useful data
  353. #### Start: Clone MK404 if needed
  354. get_MK404()
  355. {
  356. if [ ! -d $MK404_PATH ]; then
  357. #release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  358. #release_tag=$(basename $release_url)
  359. #git clone -b $release_tag -- https://github.com/$MK404_owner/$MK404_project.git $MK404_PATH
  360. git clone $MK404_URL $MK404_PATH
  361. fi
  362. }
  363. #### End: Clone MK404 if needed
  364. #### Start: Check for updates
  365. check_for_updates()
  366. {
  367. if [ "$check_flag" == "1" ]; then
  368. if [ -d $MK404_BUILD_PATH ]; then
  369. cd $MK404_BUILD_PATH
  370. MK404_current_version=$( command ./MK404 --version | grep "MK404" | cut -f 4 -d " ")
  371. cd $MK404_PATH
  372. else
  373. echo "Cannot check current version as it has not been build."
  374. fi
  375. # Get local Commit_Hash
  376. MK404_local_GIT_COMMIT_HASH=$(git log --pretty=format:"%H" -1)
  377. # Get local Commit_Number
  378. MK404_local_GIT_COMMIT_NUMBER=$(git rev-list HEAD --count)
  379. # Get latest release
  380. MK404_release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$MK404_owner/$MK404_project/releases/latest)
  381. MK404_release_tag=$(basename $MK404_release_url)
  382. # Get release Commit_Hash
  383. MK404_release_GIT_COMMIT_HASH=$(git ls-remote | grep "refs/tags/$MK404_release_tag" | cut -f 1)
  384. # Get release Commit_Number
  385. MK404_release_GIT_COMMIT_NUMBER=$(git rev-list $MK404_release_tag --count)
  386. # Get latest development Commit_Hash
  387. MK404_devel_GIT_COMMIT_HASH=$(git for-each-ref refs/remotes/origin/master | cut -d" " -f 1)
  388. # Get latest development Commit_Number
  389. MK404_devel_GIT_COMMIT_NUMBER=$(git rev-list refs/remotes/origin/master --count)
  390. # Output
  391. echo ""
  392. echo "Current version : $MK404_current_version"
  393. echo ""
  394. echo "Current local hash : $MK404_local_GIT_COMMIT_HASH"
  395. echo "Current local commit nr : $MK404_local_GIT_COMMIT_NUMBER"
  396. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_release_GIT_COMMIT_HASH" ]; then
  397. echo "$(tput setaf 1)"
  398. else
  399. echo "$(tput setaf 2)"
  400. fi
  401. echo "Latest release tag : $MK404_release_tag"
  402. echo "Latest release hash : $MK404_release_GIT_COMMIT_HASH"
  403. echo "Latest release commit nr: $MK404_release_GIT_COMMIT_NUMBER"
  404. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_devel_GIT_COMMIT_HASH" ]; then
  405. echo "$(tput setaf 1)"
  406. else
  407. echo "$(tput setaf 2)"
  408. fi
  409. echo "Latest devel hash : $MK404_devel_GIT_COMMIT_HASH"
  410. echo "Latest devel commit nr : $MK404_devel_GIT_COMMIT_NUMBER"
  411. echo "$(tput sgr 0)"
  412. # Check for updates
  413. if [ ! -z $MK404_release_GIT_COMMIT_HASH ]; then
  414. if [[ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_release_GIT_COMMIT_HASH" && -z "$update_flag" ]]; then
  415. echo "$(tput setaf 2)Update to release is availible.$(tput sgr 0)"
  416. read -t 10 -n 1 -p "$(tput setaf 3)Update to release now Y/n$(tput sgr 0)" update_answer
  417. if [[ "$update_answer" == "Y" || "$update_answer" == "y" ]]; then
  418. update_flag=1
  419. fi
  420. echo ""
  421. fi
  422. fi
  423. if [ ! -z $MK404_devel_GIT_COMMIT_HASH ]; then
  424. if [[ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_devel_GIT_COMMIT_HASH" && -z "$update_flag" ]]; then
  425. echo "$(tput setaf 2)Update to devel is availible.$(tput sgr 0)"
  426. read -t 10 -n 1 -p "$(tput setaf 3)Update to devel now Y/n$(tput sgr 0)" update_answer
  427. if [[ "$update_answer" == "Y" || "$update_answer" == "y" ]]; then
  428. update_flag=2
  429. fi
  430. echo ""
  431. fi
  432. fi
  433. fi
  434. }
  435. #### End: Check for updates
  436. #### Start: Fetch updates and force new build
  437. fetch_updates()
  438. {
  439. if [ "$update_flag" == "1" ]; then
  440. if [ ! -z $MK404_release_GIT_COMMIT_HASH ]; then
  441. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_release_GIT_COMMIT_HASH" ]; then
  442. echo ""
  443. git fetch --all
  444. read -t 5 -p "$(tput setaf 2)Updating MK404 to release!$(tput sgr 0)"
  445. echo ""
  446. git reset --hard $MK404_release_tag
  447. read -t 5 -p "$(tput setaf 2)Compiling MK404 release!$(tput sgr 0)"
  448. echo ""
  449. new_build_flag=1
  450. fi
  451. fi
  452. elif [ "$update_flag" == "2" ]; then
  453. if [ ! -z $MK404_devel_GIT_COMMIT_HASH ]; then
  454. if [ "$MK404_local_GIT_COMMIT_HASH" != "$MK404_devel_GIT_COMMIT_HASH" ]; then
  455. echo ""
  456. git fetch --all
  457. read -t 5 -p "$(tput setaf 2)Updating MK404 to devel!$(tput sgr 0)"
  458. echo ""
  459. git reset --hard origin/master
  460. read -t 5 -p "$(tput setaf 2)Compiling MK404 devel!$(tput sgr 0)"
  461. echo ""
  462. new_build_flag=1
  463. fi
  464. fi
  465. fi
  466. }
  467. #### End: Fetch updates and force new build
  468. #### Start: Prepare MK404 build
  469. prepare_MK404()
  470. {
  471. if [ ! -d $MK404_BUILD_PATH ]; then
  472. mkdir -p $MK404_BUILD_PATH
  473. fi
  474. }
  475. #### End: Prepare MK404 build
  476. #### Start: Build MK404
  477. build_MK404()
  478. {
  479. if [[ ! -f "$MK404_BUILD_PATH/Makefile" || "$new_build_flag" == "1" ]]; then
  480. # Init and update submodules
  481. if [ -d $MK404_BUILD_PATH ]; then
  482. rm -rf $MK404_BUILD_PATH
  483. mkdir -p $MK404_BUILD_PATH
  484. fi
  485. git submodule init
  486. git submodule update
  487. cmake -B$MK404_BUILD_PATH -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
  488. fi
  489. # Make MK404
  490. cd $MK404_BUILD_PATH
  491. if [[ ! -f "$MK404_BUILD_PATH/MK404" || "$new_build_flag" == "1" ]]; then
  492. make
  493. fi
  494. # Make SDcards
  495. if [[ ! -f "$MK404_BUILD_PATH/Prusa_MK3S_SDcard.bin" || "$new_build_flag" == "1" ]]; then
  496. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3S_SDcard.bin
  497. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3_SDcard.bin
  498. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25_13_SDcard.bin
  499. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK25S_13_SDcard.bin
  500. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3SMMU2_SDcard.bin
  501. cmake --build $MK404_BUILD_PATH --config Release --target Prusa_MK3MMU2_SDcard.bin
  502. fi
  503. }
  504. #### End: Build MK404
  505. #### Start: Run MK404 SIM
  506. run_MK404_SIM()
  507. {
  508. if [ ! -z $mk404_flag ]; then
  509. # Output some useful data
  510. echo "Printer : $MK404_PRINTER"
  511. echo "Options : $MK404_options"
  512. echo ""
  513. read -t 5 -p "Press $(tput setaf 2)Enter$(tput sgr 0) to start MK404"
  514. echo ""
  515. # Change to MK404 build folder
  516. cd $MK404_BUILD_PATH
  517. # Start MK404
  518. # default with serial output and terminal to manipulate it via terminal
  519. echo ""
  520. echo "./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options $MK404_firmware_file"
  521. sleep 5
  522. ./MK404 Prusa_$MK404_PRINTER -s --terminal $MK404_options $MK404_firmware_file || exit 10
  523. fi
  524. }
  525. #### End: Run MK404 SIM
  526. #### Check OS and needed packages
  527. echo "Check OS"
  528. check_OS
  529. check_packages
  530. #### Check for options/flags
  531. echo "Check for options"
  532. #### Prepare build environment
  533. echo "Prepare build env"
  534. set_build_env_variables
  535. output_useful_data
  536. get_MK404
  537. #
  538. cd $MK404_PATH
  539. check_for_updates
  540. fetch_updates
  541. prepare_MK404
  542. build_MK404
  543. run_MK404_SIM
  544. #### End of MK404 Simulator