-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjlcpcb-library.sh
executable file
·116 lines (91 loc) · 2.79 KB
/
jlcpcb-library.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
#!/bin/bash
declare -a parts
usage() {
echo "usage: $0: <jlc-parts-file> <library name> [patches dir]"
echo
echo "parts file: one Cxxxxx per line, # comments allowed"
echo "library name: A-Z0-9 in both filesystem and KiCad"
echo "patches dir: directory of patches to apply to footprints (optional)"
}
read_parts_file() {
while read line; do
local part=$(echo $line | sed -ne 's/^\(C[0-9]*\) .*$/\1/p')
parts+=($part)
done < $jlc_parts_file
}
function apply_patches_if_needed() {
library_name=$1
patches_dir=$2
if [[ ! -d $library_name/$library_name ]]; then
echo "apply_patches_if_needed(): no footprints found!"
return 1
fi
if [[ ! -d $patches_dir ]]; then
echo "No patches to apply"
return 0
fi
echo "Applying patches:"
for file in $patches_dir/*.patch; do
footprint_name=$(basename $(echo $file | sed -e 's/.patch//g'))
echo -n "* "
patch $library_name/$library_name/$footprint_name < $file
done
}
fix_smd_attr() {
library_name=$1
if [[ ! -d $library_name/$library_name ]]; then
echo "fix_smd_attr(): no footprints found!"
return 1
fi
echo "Processing footprints:"
for file in $library_name/$library_name/*.kicad_mod; do
echo -n "* $(basename $(basename $file)): "
# not for us
grep 'pad.*thru_hole' $file > /dev/null
if [[ $? == 0 ]]; then
echo "THT"
continue
fi
# adjusted?
grep "attr smd" $file > /dev/null
if [[ $? == 1 ]]; then
echo "SMD (patching)"
sed -ie 's/^\((module.*$\)/\1\n (attr smd)/g' $file
else
echo "SMD"
fi
done
}
main() {
if [[ "$2" == "" ]]; then
usage
exit 0
fi
local jlc_parts_file=$1
local library_name=$2
local patches_dir=$3
if [[ ! -f "$jlc_parts_file" ]]; then
usage
exit 0
fi
library_name_no_space=$(echo $library_name | sed 's/ /-/g')
#echo "library name: $library_name, library_name no space: $library_name_no_space"
if [[ "$library_name_no_space" != "$library_name" ]]; then
echo "error: space(s) in library name not allowed."
exit 1
fi
library_name_work=${library_name}-work
read_parts_file $jlc_parts_file
echo "Downloading components:"
# --skip_existing: always overwrite!
JLC2KiCadLib ${parts[*]} \
-dir ${library_name} \
-schematic_lib $library_name -footprint_lib $library_name |
grep --line-buffered -v '\(creating footprint\|creating 3D model\|writing in\)' |
sed -ne 's/.*INFO - \(.*\)$/\1/p'
echo
fix_smd_attr $library_name
echo
apply_patches_if_needed $library_name $patches_dir
}
main $*