MK404-build.sh 21 KB

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