Browse Source

Add 'mfconfig' script used to manage configs

Scott Lahteine 3 years ago
parent
commit
bb7dbceb5c
1 changed files with 183 additions and 0 deletions
  1. 183
    0
      buildroot/share/git/mfconfig

+ 183
- 0
buildroot/share/git/mfconfig View File

@@ -0,0 +1,183 @@
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
+
23
+REPOHOME="`dirname ~/Projects/Maker/Firmware/.`"
24
+MARLINREPO="$REPOHOME/MarlinFirmware"
25
+CONFIGREPO="$REPOHOME/Configurations"
26
+
27
+CEXA=config/examples
28
+CDEF=config/default
29
+BC=Configuration.h
30
+AC=Configuration_adv.h
31
+
32
+COMMIT_STEPS=0
33
+
34
+#cd "$CONFIGREPO" 2>/dev/null || { echo "Can't find Configurations repo!" ; exit 1; }
35
+
36
+ACTION=${1:-init}
37
+IMPORT=${2:-"import-2.0.x"}
38
+EXPORT=${3:-"bugfix-2.0.x"}
39
+
40
+echo -n "Doing grhh ... " ; grhh ; echo
41
+
42
+if [[ $ACTION == "manual" ]]; then
43
+
44
+  #
45
+  # Copy the latest default configs from MarlinFirmware/Marlin
46
+  # or one of the import branches here, then use them to construct
47
+  # a 'BASE' branch with only defaults as a starting point.
48
+  #
49
+
50
+  echo "- Updating '$IMPORT' from Marlin..."
51
+
52
+  git checkout $IMPORT || exit
53
+
54
+  # Reset from the latest complete state
55
+  #git reset --hard master
56
+
57
+  cp "$MARLINREPO/Marlin/"Configuration*.h "$CDEF/"
58
+  #git add . && git commit -m "Changes from Marlin ($(date '+%Y-%m-%d %H:%M'))."
59
+
60
+  echo "- Fix up the import branch and come back."
61
+
62
+  read -p "- Ready to init [y/N] ?" INIT_YES
63
+  echo
64
+
65
+  [[ $INIT_YES == 'Y' || $INIT_YES == 'y' ]] || { echo "Done." ; exit ; }
66
+
67
+  ACTION='init'
68
+fi
69
+
70
+if [[ $ACTION == "init" ]]; then
71
+  #
72
+  # Copy all configs from a source such as MarlinFirmware/Marlin
73
+  # or one of the import branches here, then use them to construct
74
+  # a 'BASE' branch with only defaults as a starting point.
75
+  #
76
+
77
+  echo "- Initializing BASE branch..."
78
+
79
+  # Use the import branch as the source
80
+  git checkout $IMPORT || exit
81
+
82
+  # Copy to a temporary location
83
+  TEMP=$( mktemp -d ) ; cp -R config $TEMP
84
+
85
+  # Make sure we're not on the 'BASE' branch...
86
+  git checkout master >/dev/null 2>&1 || exit
87
+
88
+  # Create 'BASE' as a copy of 'init-repo' (README, LICENSE, etc.)
89
+  git branch -D BASE 2>/dev/null
90
+  git checkout init-repo -b BASE || exit
91
+
92
+  # Copy all config files into place
93
+  echo "- Copying configs from Marlin..."
94
+  cp -R "$TEMP/config" .
95
+
96
+  # Delete anything that's not a Configuration file
97
+  find config -type f \! -name "Configuration*" -exec rm "{}" \;
98
+
99
+  # DEBUG: Commit the original config files for comparison
100
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Commit for comparison" >/dev/null
101
+
102
+  # Init Cartesian configurations to default
103
+  echo "- Initializing configs to default state..."
104
+
105
+  find "$CEXA" -name $BC ! -path */delta/* -print0 \
106
+    | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
107
+  find "$CEXA" -name $AC ! -path */delta/* -print0 \
108
+    | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
109
+
110
+  # DEBUG: Commit the reset for review
111
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Cartesian/SCARA configs..." >/dev/null
112
+
113
+  # Create base Delta configurations
114
+  cp "$CDEF"/* "$CEXA/delta/generic"
115
+
116
+  # DEBUG: Commit the reset for review
117
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Generic Delta..." >/dev/null
118
+
119
+  cp -R "$TEMP/$CEXA/delta/generic"/Conf* "$CEXA/delta/generic"
120
+
121
+  # DEBUG: Commit Generic Delta changes for review
122
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Apply Generic Delta..." >/dev/null
123
+
124
+  find "$CEXA/delta" -name $BC ! -path */generic/* -print0 \
125
+    | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$BC" "$F" ; done
126
+  find "$CEXA/delta" -name $AC ! -path */generic/* -print0 \
127
+    | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$AC" "$F" ; done
128
+
129
+  # DEBUG: Commit the reset for review
130
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Delta configs..." >/dev/null
131
+
132
+  # SCARA configurations
133
+  find "$CEXA/SCARA" -name $BC \
134
+    | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
135
+  find "$CEXA/SCARA" -name $AC \
136
+    | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
137
+
138
+  # DEBUG: Commit the reset for review or...
139
+  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset SCARA..." >/dev/null
140
+
141
+  # Update the %VERSION% in the README.md file
142
+  SED=$(which gsed || which sed)
143
+  VERS=$( echo $EXPORT | $SED 's/release-//' )
144
+  eval "${SED} -E -i~ -e 's/%VERSION%/$VERS/g' README.md"
145
+  rm -f README.md~
146
+
147
+  # NOT DEBUGGING: Commit the 'BASE', ready for customizations
148
+  ((COMMIT_STEPS)) || git add . >/dev/null && git commit --amend --no-edit >/dev/null
149
+
150
+  # Create a new branch from 'BASE' for the final result
151
+  echo "- Creating '$EXPORT' branch for the result..."
152
+  git branch -D $EXPORT 2>/dev/null
153
+  git checkout -b $EXPORT || exit
154
+
155
+  # Delete temporary branch
156
+  git branch -D BASE 2>/dev/null
157
+
158
+  echo "- Applying example config customizations..."
159
+  cp -R "$TEMP/config" .
160
+  find config -type f \! -name "Configuration*" -exec rm "{}" \;
161
+
162
+  echo "- Adding path labels to all configs..."
163
+  config-labels.py >/dev/null 2>&1
164
+
165
+  git add . >/dev/null && git commit -m "Examples Customizations" >/dev/null
166
+
167
+  echo "- Copying extras from Marlin..."
168
+  cp -R "$TEMP/config" .
169
+
170
+  # Apply labels again!
171
+  config-labels.py >/dev/null 2>&1
172
+
173
+  git add . >/dev/null && git commit -m "Examples Extras" >/dev/null
174
+
175
+  rm -rf $TEMP
176
+
177
+  git push -f --set-upstream upstream "$EXPORT"
178
+
179
+else
180
+
181
+  echo "Usage: mfconfig init|manual|rebase"
182
+
183
+fi

Loading…
Cancel
Save