forked from Caribou3d/CaribouMK3s-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.sh
executable file
·289 lines (278 loc) · 10.2 KB
/
sort.sh
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
##################################################################
# This script sorts generated Caribou hex files in differnt folders
#
# You can add two arguments <Start_path> <Destiontion_Path>
# <Start_path> defines to folder to be searched
# <Destination_Path> defines the folder where the files will be placed
#
# Example: ./sort.sh ../PF-build-hex/FW381-Build2869 ../PF-build-hex/Firmware-381-Build2869
# The script will search the files in ./FW381-Build2869 and copy them to the destination ../Firmware-381-Build2869
#
# V1.2
#
# Change log
# 17 Dec 2019, 3d-gussner, Initial version
# 18 Dec 2019, 3d-gussner, add arguments $1 = Start path and $2 Destination path
# 17 May 2020, 3d-gussner, Sorting of stock Prusa + OLED was missing thanks to @n4mb3r0n3
# 09 Sep 2020, 3d-gussner, Rebranding Caribou3d
# 10 Sep 2020, 3d-gussner, fix some sorting issues due to new naming convention
# 11 Jul 2021, wschadow, added LGX, added folders for Prusa and Caribou extruders
# 18 Jul 2021, wschadow, a zip file of the sorted files is generated
# 14 Feb 2020, wschadow, added LGXM and LGXMM, only sort and zip .elf files
# 11 Apr 2022, wschadow, updated output path and name of combined zip file
#
# Folder tree:
#.
#├── Caribou220
#│ ├── MK25
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK25S
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK3
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ └── MK3S
#│ │── BONDTECH
#│ │ ├── E3DV6
#│ │ ├── MOSQUITO
#│ │ └── MOSQUITO_MAGNUM
#│ │── Caribou
#│ ├── LGXC
# └── LGXM
#├── Caribou320
#│ ├── MK25
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK25S
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK3
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ └── MK3S
#│ │── BONDTECH
#│ │ ├── E3DV6
#│ │ ├── MOSQUITO
#│ │ └── MOSQUITO_MAGNUM
#│ │── Caribou
#│ ├── LGXC
# └── LGXM
#├── Caribou420
#│ ├── MK25
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK25S
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ ├── MK3
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Caribou
#│ └── MK3S
#│ │── BONDTECH
#│ │ ├── E3DV6
#│ │ ├── MOSQUITO
#│ │ └── MOSQUITO_MAGNUM
#│ │── Caribou
#│ ├── LGXC
# └── LGXM
#└── Prusa210
#│ ├── MK25
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Prusa
#│ ├── MK25S
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Prusa
#│ ├── MK3
#│ │ │── BONDTECH
#│ │ │ ├── E3DV6
#│ │ │ ├── MOSQUITO
#│ │ │ └── MOSQUITO_MAGNUM
#│ │ └── Prusa
#│ └── MK3S
#│ │── BONDTECH
#│ │ ├── E3DV6
#│ │ ├── MOSQUITO
#│ │ └── MOSQUITO_MAGNUM
#│ │── Prusa
#│ ├── LGXC
# └── LGXM
#
OS_FOUND=$( command -v uname)
case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
linux*)
TARGET_OS="linux"
;;
msys*|cygwin*|mingw*)
# or possible 'bash on windows'
TARGET_OS='windows'
;;
nt|win*)
TARGET_OS='windows'
;;
*)
TARGET_OS='unknown'
;;
esac
# Windows
if [ $TARGET_OS == "windows" ]; then
if [ $(uname -m) == "x86_64" ]; then
echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)"
Processor="64"
elif [ $(uname -m) == "i386" ]; then
echo "$(tput setaf 2)Windows 32-bit found$(tput sgr0)"
Processor="32"
fi
# Linux
elif [ $TARGET_OS == "linux" ]; then
if [ $(uname -m) == "x86_64" ]; then
echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)"
Processor="64"
elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)"
Processor="32"
elif [ $(uname -m) == "aarch64" ]; then
echo "$(tput setaf 2)Linux aarch64 bit found$(tput sgr0)"
Processor="aarch64"
fi
else
echo "$(tput setaf 1)This script doesn't support your Operating system!"
echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash"
echo "Read the notes of build.sh$(tput sgr0)"
exit 1
fi
# Set arrays for script
# Array of companies
declare -a CompanyArray=( "Caribou" "Prusa" )
# Array of printer types
declare -a TypesArray=( MK3S MK3 MK25S MK25 )
# Array of printer heights
declare -a HeightsArray=( 220 320 420)
# Array of Bondtech folder names
declare -a BondtechArray=( E3DV6 MOSQUITO MOSQUITO_MAGNUM )
# End of set arrays
# Main script
if [ -z "$1" ] ; then
Start_Path="."
else
Start_Path=$1
fi
if [ -z "$2" ] ; then
Destination_Path="."
else
Destination_Path=$2
fi
echo "Start Path: "$Start_Path
echo "Dest. Path: "$Destination_Path
# Loop for printer types
for COMPANY in ${CompanyArray[@]}; do
echo "Start $COMPANY"
for TYPE in ${TypesArray[@]}; do
# Loop for printer heights
if [ $COMPANY == "Prusa" ]; then
declare -a HeightsArray=( 210 )
fi
for HEIGHT in ${HeightsArray[@]}; do
# Loop for Bondtech types
for BONDTECH_TYPE in ${BondtechArray[@]}; do
# Create all directories, see Folder tree above
mkdir -p $Destination_Path/$COMPANY$HEIGHT/$TYPE/BONDTECH/$BONDTECH_TYPE
# Link files short names to folder long names
case $BONDTECH_TYPE in
E3DV6)
# For Bondtech E3DV6
BONDTECH_SHORT='BE'
# At this moment we don't use another version
BONDTECH_SHORT2='BE'
;;
MOSQUITO)
# For Bondtech MOSQUITO with E3D thermistor
BONDTECH_SHORT='BM'
# For Bondtech MOSQUITO with Slice engineering thermistor
BONDTECH_SHORT2='BMH'
;;
MOSQUITO_MAGNUM)
# For Bondtech MOSQUITO_MAGNUM with E3D thermistor
BONDTECH_SHORT='BMM'
# For Bondtech MOSQUITO_MAGNUM with Slice engineering thermistor
BONDTECH_SHORT2='BMMH'
;;
esac
# Find all Bondtech hex files and copy them to destination folder sorted by Type, Height and Bontech txpe.
# BONDTECH_SHORT -> Bondtech folder name
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-$BONDTECH_SHORT-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGHT/$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/BONDTECH/$BONDTECH_TYPE \;
# Find other Bondtech hex files and copy them to destination folder sorted By Type, Height and Bontech txpe.
# BONDTECH_SHORT2 -> Bondtech folder name
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-$BONDTECH_SHORT2-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGH-$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/BONDTECH/$BONDTECH_TYPE \;
done
if [ $TYPE == "MK3S" ]; then
# Find all LGXC files and copy them to the destination folder
mkdir -p $Destination_Path/$COMPANY$HEIGHT/$TYPE/LGXC
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-LGXC-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGH-$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/LGXC \;
# Find all LGM and LGMM files and copy them to the desitnation folder
mkdir -p $Destination_Path/$COMPANY$HEIGHT/$TYPE/LGXM
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-LGM-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGH-$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/LGXM \;
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-LGMM-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGH-$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/LGXM \;
fi
# Find rest hex files and copy them to destination folder sorted by Type and Height
mkdir -p $Destination_Path/$COMPANY$HEIGHT/$TYPE/$COMPANY
find -L $Start_Path -name "*$COMPANY$HEIGHT-$TYPE-Build*.hex" -type f -not -path "$Destination_Path/$COMPANY$HEIGHT/$TYPE/*" -exec cp {} $Destination_Path/$COMPANY$HEIGHT/$TYPE/$COMPANY \;
done
done
done
echo
echo ' ... done'
# =========================================================================================================
# delete empty subdirectories
find $Destination_Path -type d -empty -delete
# =========================================================================================================
# create zip-file for configuration
echo
echo 'creating zip file of sorted hex-files ....'
echo
if [ $TARGET_OS == "windows" ]; then
zip a $Destination_Path/$ZIPNAME.zip $Destination_Path/* | tail -4
else
ZIPNAMETMP=${Destination_Path%*/}
ZIPNAME=${ZIPNAMETMP##*/}
pushd $Destination_Path
zip -r $Destination_Path/$ZIPNAME.zip * | tail -4
popd
fi
echo
echo ' ... done'