My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/env bash
  2. #
  3. # mfconfig init source dest
  4. # mfconfig manual source dest
  5. #
  6. # The MarlinFirmware/Configurations layout could be broken up into branches,
  7. # but this makes management more complicated and requires more commits to
  8. # perform the same operation, so this uses a single branch with subfolders.
  9. #
  10. # init - Initialize the repo with a base commit and changes:
  11. # - Source will be an 'import' branch containing all current configs.
  12. # - Create an empty 'BASE' branch from 'init-repo'.
  13. # - Add Marlin config files, but reset all to defaults.
  14. # - Commit this so changes will be clear in following commits.
  15. # - Add changed Marlin config files and commit.
  16. #
  17. # manual - Manually import changes from the Marlin repo
  18. # - Replace 'default' configs with those from the Marlin repo.
  19. # - Wait for manual propagation to the rest of the configs.
  20. # - Run init with the given 'source' and 'dest'
  21. #
  22. REPOHOME="`dirname ~/Projects/Maker/Firmware/.`"
  23. MARLINREPO="$REPOHOME/MarlinFirmware"
  24. CONFIGREPO="$REPOHOME/Configurations"
  25. CEXA=config/examples
  26. CDEF=config/default
  27. BC=Configuration.h
  28. AC=Configuration_adv.h
  29. COMMIT_STEPS=0
  30. #cd "$CONFIGREPO" 2>/dev/null || { echo "Can't find Configurations repo!" ; exit 1; }
  31. ACTION=${1:-init}
  32. IMPORT=${2:-"import-2.0.x"}
  33. EXPORT=${3:-"bugfix-2.0.x"}
  34. echo -n "Doing grhh ... " ; grhh ; echo
  35. if [[ $ACTION == "manual" ]]; then
  36. #
  37. # Copy the latest default configs from MarlinFirmware/Marlin
  38. # or one of the import branches here, then use them to construct
  39. # a 'BASE' branch with only defaults as a starting point.
  40. #
  41. echo "- Updating '$IMPORT' from Marlin..."
  42. git checkout $IMPORT || exit
  43. # Reset from the latest complete state
  44. #git reset --hard bugfix-2.0.x
  45. cp "$MARLINREPO/Marlin/"Configuration*.h "$CDEF/"
  46. #git add . && git commit -m "Changes from Marlin ($(date '+%Y-%m-%d %H:%M'))."
  47. echo "- Fix up the import branch and come back."
  48. read -p "- Ready to init [y/N] ?" INIT_YES
  49. echo
  50. [[ $INIT_YES == 'Y' || $INIT_YES == 'y' ]] || { echo "Done." ; exit ; }
  51. ACTION='init'
  52. fi
  53. if [[ $ACTION == "init" ]]; then
  54. #
  55. # Copy all configs from a source such as MarlinFirmware/Marlin
  56. # or one of the import branches here, then use them to construct
  57. # a 'BASE' branch with only defaults as a starting point.
  58. #
  59. SED=$(which gsed sed | head -n1)
  60. echo "- Initializing BASE branch..."
  61. # Use the import branch as the source
  62. git checkout $IMPORT || exit
  63. # Copy to a temporary location
  64. TEMP=$( mktemp -d ) ; cp -R config $TEMP
  65. # Strip all #error lines
  66. IFS=$'\n'; set -f
  67. for fn in $( find $TEMP/config -type f -name "Configuration.h" ); do
  68. $SED -i~ -e "20,30{/#error/d}" "$fn"
  69. rm "$fn~"
  70. done
  71. unset IFS; set +f
  72. # Make sure we're not on the 'BASE' branch...
  73. git checkout init-repo >/dev/null 2>&1 || exit
  74. # Create 'BASE' as a copy of 'init-repo' (README, LICENSE, etc.)
  75. git branch -D BASE 2>/dev/null
  76. git checkout init-repo -b BASE || exit
  77. # Copy all config files into place
  78. echo "- Copying all configs from fresh $IMPORT..."
  79. cp -R "$TEMP/config" .
  80. # Delete anything that's not a Configuration file
  81. find config -type f \! -name "Configuration*" -exec rm "{}" \;
  82. # DEBUG: Commit the original config files for comparison
  83. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Commit for comparison" >/dev/null
  84. # Init Cartesian/SCARA/TPARA configurations to default
  85. echo "- Initializing Cartesian/SCARA/TPARA configs to default state..."
  86. find "$CEXA" -name $BC ! -path */delta/* -print0 \
  87. | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
  88. find "$CEXA" -name $AC ! -path */delta/* -print0 \
  89. | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
  90. # DEBUG: Commit the reset for review
  91. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Cartesian/SCARA/TPARA configs..." >/dev/null
  92. # Create base Delta configurations
  93. cp "$CDEF"/* "$CEXA/delta/generic"
  94. # DEBUG: Commit the reset for review
  95. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Generic Delta..." >/dev/null
  96. cp -R "$TEMP/$CEXA/delta/generic"/Conf* "$CEXA/delta/generic"
  97. # DEBUG: Commit Generic Delta changes for review
  98. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Apply Generic Delta..." >/dev/null
  99. # Reset all Delta configs to the generic version
  100. find "$CEXA/delta" -name $BC ! -path */generic/* -print0 \
  101. | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$BC" "$F" ; done
  102. find "$CEXA/delta" -name $AC ! -path */generic/* -print0 \
  103. | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$AC" "$F" ; done
  104. # DEBUG: Commit the Delta reset for review
  105. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Delta configs..." >/dev/null
  106. # Reset all SCARA configs to the default cartesian
  107. find "$CEXA/SCARA" -name $BC \
  108. | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
  109. find "$CEXA/SCARA" -name $AC \
  110. | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
  111. # DEBUG: Commit the SCARA reset for review
  112. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset SCARA..." >/dev/null
  113. # Reset all TPARA configs to the default cartesian
  114. find "$CEXA/TPARA" -name $BC \
  115. | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
  116. find "$CEXA/TPARA" -name $AC \
  117. | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
  118. # DEBUG: Commit the TPARA reset for review
  119. ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset TPARA..." >/dev/null
  120. # Update the %VERSION% in the README.md file
  121. VERS=$( echo $EXPORT | $SED 's/release-//' )
  122. eval "${SED} -E -i~ -e 's/%VERSION%/$VERS/g' README.md"
  123. rm -f README.md~
  124. # NOT DEBUGGING: Commit the 'BASE', ready for customizations
  125. ((COMMIT_STEPS)) || git add . >/dev/null && git commit --amend --no-edit >/dev/null
  126. # Create a new branch from 'BASE' for the final result
  127. echo "- Creating '$EXPORT' branch for the result..."
  128. git branch -D $EXPORT 2>/dev/null
  129. git checkout -b $EXPORT || exit
  130. # Delete temporary branch
  131. git branch -D BASE 2>/dev/null
  132. echo "- Applying example config customizations..."
  133. cp -R "$TEMP/config" .
  134. find config -type f \! -name "Configuration*" -exec rm "{}" \;
  135. echo "- Adding path labels to all configs..."
  136. config-labels.py >/dev/null 2>&1
  137. git add . >/dev/null && git commit -m "Examples Customizations" >/dev/null
  138. echo "- Copying extras from Marlin..."
  139. cp -R "$TEMP/config" .
  140. # Apply labels again!
  141. config-labels.py >/dev/null 2>&1
  142. git add . >/dev/null && git commit -m "Examples Extras" >/dev/null
  143. rm -rf $TEMP
  144. git push -f --set-upstream upstream "$EXPORT"
  145. else
  146. echo "Usage: mfconfig init|manual|rebase"
  147. fi