aboutsummaryrefslogtreecommitdiff
path: root/buildroot/share/git/mfconfig
blob: 3fd5e399cc56007904cbccc6206e579458b4c965 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
#
# mfconfig init source dest
# mfconfig manual source dest
#
# The MarlinFirmware/Configurations layout could be broken up into branches,
# but this makes management more complicated and requires more commits to
# perform the same operation, so this uses a single branch with subfolders.
#
# init - Initialize the repo with a base commit and changes:
#   - Source will be an 'import' branch containing all current configs.
#   - Create an empty 'BASE' branch from 'init-repo'.
#   - Add Marlin config files, but reset all to defaults.
#   - Commit this so changes will be clear in following commits.
#   - Add changed Marlin config files and commit.
#
# manual - Manually import changes from the Marlin repo
#   - Replace 'default' configs with those from the Marlin repo.
#   - Wait for manual propagation to the rest of the configs.
#   - Run init with the given 'source' and 'dest'
#

REPOHOME="`dirname ~/Projects/Maker/Firmware/.`"
MARLINREPO="$REPOHOME/MarlinFirmware"
CONFIGREPO="$REPOHOME/Configurations"

CEXA=config/examples
CDEF=config/default
BC=Configuration.h
AC=Configuration_adv.h

COMMIT_STEPS=0

#cd "$CONFIGREPO" 2>/dev/null || { echo "Can't find Configurations repo!" ; exit 1; }

ACTION=${1:-init}
IMPORT=${2:-"import-2.0.x"}
EXPORT=${3:-"bugfix-2.0.x"}

echo -n "Doing grhh ... " ; grhh ; echo

if [[ $ACTION == "manual" ]]; then

  #
  # Copy the latest default configs from MarlinFirmware/Marlin
  # or one of the import branches here, then use them to construct
  # a 'BASE' branch with only defaults as a starting point.
  #

  echo "- Updating '$IMPORT' from Marlin..."

  git checkout $IMPORT || exit

  # Reset from the latest complete state
  #git reset --hard master

  cp "$MARLINREPO/Marlin/"Configuration*.h "$CDEF/"
  #git add . && git commit -m "Changes from Marlin ($(date '+%Y-%m-%d %H:%M'))."

  echo "- Fix up the import branch and come back."

  read -p "- Ready to init [y/N] ?" INIT_YES
  echo

  [[ $INIT_YES == 'Y' || $INIT_YES == 'y' ]] || { echo "Done." ; exit ; }

  ACTION='init'
fi

if [[ $ACTION == "init" ]]; then
  #
  # Copy all configs from a source such as MarlinFirmware/Marlin
  # or one of the import branches here, then use them to construct
  # a 'BASE' branch with only defaults as a starting point.
  #

  echo "- Initializing BASE branch..."

  # Use the import branch as the source
  git checkout $IMPORT || exit

  # Copy to a temporary location
  TEMP=$( mktemp -d ) ; cp -R config $TEMP

  # Make sure we're not on the 'BASE' branch...
  git checkout master >/dev/null 2>&1 || exit

  # Create 'BASE' as a copy of 'init-repo' (README, LICENSE, etc.)
  git branch -D BASE 2>/dev/null
  git checkout init-repo -b BASE || exit

  # Copy all config files into place
  echo "- Copying configs from Marlin..."
  cp -R "$TEMP/config" .

  # Delete anything that's not a Configuration file
  find config -type f \! -name "Configuration*" -exec rm "{}" \;

  # DEBUG: Commit the original config files for comparison
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Commit for comparison" >/dev/null

  # Init Cartesian configurations to default
  echo "- Initializing configs to default state..."

  find "$CEXA" -name $BC ! -path */delta/* -print0 \
    | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
  find "$CEXA" -name $AC ! -path */delta/* -print0 \
    | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done

  # DEBUG: Commit the reset for review
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Cartesian/SCARA configs..." >/dev/null

  # Create base Delta configurations
  cp "$CDEF"/* "$CEXA/delta/generic"

  # DEBUG: Commit the reset for review
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Generic Delta..." >/dev/null

  cp -R "$TEMP/$CEXA/delta/generic"/Conf* "$CEXA/delta/generic"

  # DEBUG: Commit Generic Delta changes for review
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Apply Generic Delta..." >/dev/null

  find "$CEXA/delta" -name $BC ! -path */generic/* -print0 \
    | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$BC" "$F" ; done
  find "$CEXA/delta" -name $AC ! -path */generic/* -print0 \
    | while read -d $'\0' F ; do cp "$CEXA/delta/generic/$AC" "$F" ; done

  # DEBUG: Commit the reset for review
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset Delta configs..." >/dev/null

  # SCARA configurations
  find "$CEXA/SCARA" -name $BC \
    | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
  find "$CEXA/SCARA" -name $AC \
    | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done

  # DEBUG: Commit the reset for review or...
  ((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset SCARA..." >/dev/null

  # Update the %VERSION% in the README.md file
  SED=$(which gsed || which sed)
  VERS=$( echo $EXPORT | $SED 's/release-//' )
  eval "${SED} -E -i~ -e 's/%VERSION%/$VERS/g' README.md"
  rm -f README.md~

  # NOT DEBUGGING: Commit the 'BASE', ready for customizations
  ((COMMIT_STEPS)) || git add . >/dev/null && git commit --amend --no-edit >/dev/null

  # Create a new branch from 'BASE' for the final result
  echo "- Creating '$EXPORT' branch for the result..."
  git branch -D $EXPORT 2>/dev/null
  git checkout -b $EXPORT || exit

  # Delete temporary branch
  git branch -D BASE 2>/dev/null

  echo "- Applying example config customizations..."
  cp -R "$TEMP/config" .
  find config -type f \! -name "Configuration*" -exec rm "{}" \;

  echo "- Adding path labels to all configs..."
  config-labels.py >/dev/null 2>&1

  git add . >/dev/null && git commit -m "Examples Customizations" >/dev/null

  echo "- Copying extras from Marlin..."
  cp -R "$TEMP/config" .

  # Apply labels again!
  config-labels.py >/dev/null 2>&1

  git add . >/dev/null && git commit -m "Examples Extras" >/dev/null

  rm -rf $TEMP

  git push -f --set-upstream upstream "$EXPORT"

else

  echo "Usage: mfconfig init|manual|rebase"

fi