-
Notifications
You must be signed in to change notification settings - Fork 35
/
install_dependencies.sh
executable file
·332 lines (275 loc) · 6.94 KB
/
install_dependencies.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
ctrl_c()
{
exit 1
}
identify_linux_or_wsl()
{
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
echo "WSL"
else
echo "Linux"
fi
}
identify_operating_system()
{
case "${OSTYPE}" in
bsd*) echo "BSD" ;;
darwin*) echo "macOS" ;;
linux*) echo "$(identify_linux_or_wsl)" ;;
msys*) echo "Windows" ;;
solaris*) echo "Solaris" ;;
*) echo "Unknown" ;;
esac
}
identify_linux_pkg_manager()
{
distro_id="$(grep "^ID=" /etc/os-release | cut -d= -f2)"
distro_id_like="$(grep "^ID_LIKE=" /etc/os-release | cut -d= -f2)"
# Debian does not have "ID_LIKE"
if [[ "${distro_id}" == "debian" ]] || [[ "${distro_id_like}" =~ "debian" ]]; then
base_distro="debian"
else
base_distro="${distro_id}"
fi
case "${base_distro}" in
"debian") echo "apt" ;;
"fedora") echo "dnf" ;;
"redhat") echo "yum" ;;
"arch") echo "pacman" ;;
"archarm") echo "pacman" ;;
"manjaro") echo "pacman" ;;
*) echo "Unknown" ;;
esac
}
linux_install_dependencies()
{
pkg_manager="$(identify_linux_pkg_manager)"
case "${pkg_manager}" in
apt)
linux_install_software_with_apt
;;
dnf)
linux_install_software_with_dnf
;;
# yum)
# TODO: when someone requests it..
# linux_install_software_with_yum
# ;;
pacman)
linux_install_software_with_pacman
;;
*)
echo "Error: Unknown system"
echo "Please, ask KiRI dev to adapt the dependencies installer"
exit
;;
esac
}
# =============================================
# Linux apt-related stuff
# =============================================
linux_install_software_with_apt()
{
# Update packages knowledge
sudo apt-get update
# Install base packages
sudo apt-get install -y git
sudo apt-get install -y build-essential
sudo apt-get install -y libgtk-3-dev
sudo apt-get install -y libgmp-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y opam
sudo apt-get install -y python-is-python3
sudo apt-get install -y python3-pip
sudo apt-get install -y kicad
sudo apt-get install -y coreutils
sudo apt-get install -y zenity
sudo apt-get install -y librsvg2-bin
sudo apt-get install -y imagemagick
sudo apt-get install -y xdotool
sudo apt-get install -y rename # perl rename and not util-linux
}
# =============================================
# Linux dnf-related stuff
# =============================================
linux_install_software_with_dnf()
{
# Update packages knowledge
sudo dnf check-update
# Install base packages
# sudo dnf install -y git
# sudo dnf install -y pkg-config
# sudo dnf install -y coreutils
# sudo dnf install -y zenity
# sudo dnf install -y build-essential
# sudo dnf install -y libgtk-3-dev
# sudo dnf install -y libgmp-dev
# sudo dnf install -y python-is-python3
# sudo dnf install -y librsvg2-bin
sudo dnf install -y opam
sudo dnf install -y python3-pip
sudo dnf install -y kicad
sudo dnf install -y ImageMagick
sudo dnf install -y xdotool
sudo dnf install -y prename # perl rename and not util-linux
}
# =============================================
# Linux yum-related stuff
# =============================================
# linux_install_software_with_yum()
# {
# }
# =============================================
# Linux yum-related stuff
# =============================================
linux_install_software_with_pacman()
{
yes | sudo pacman -S make --needed
yes | sudo pacman -S patch --needed
yes | sudo pacman -S opam --needed
yes | sudo pacman -S python-pip --needed
yes | sudo pacman -S kicad --needed
yes | sudo pacman -S imagemagick --needed
yes | sudo pacman -S xdotool --needed
yes | sudo pacman -S perl-rename --needed
}
# =============================================
# macOS Related stuff
# =============================================
macos_install_homebrew()
{
# Install Homebrew
if ! which brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
macos_install_kicad()
{
kicad_5="/Applications/Kicad/Kicad.app"
kicad_6="/Applications/KiCad/KiCad.app"
if [[ ! -d "${kicad_5}" ]] && [[ ! -d "${kicad_6}" ]]; then
brew install --cask kicad
fi
}
macos_install_brew_modules()
{
sudo spctl --master-disable
xcode-select --install
# Update packages knowledge
#brew update
# Base dependencies
brew install git
# Opam dependencies
brew install gmp
brew install pkg-config
brew install opam
# KiRI dependencies
brew install gsed
brew install findutils
brew install coreutils
brew install wxpython
brew install wxwidgets
brew install librsvg
brew install imagemagick
brew install cliclick
brew install rename
}
# =============================================
# OS independent stuff
# =============================================
install_python_modules()
{
if [[ -z "${KIRI_HOME}" ]]; then
KIRI_HOME="./"
fi
# python_venv_path="${KIRI_HOME}/venv/"
# if [[ ! -d ${python_venv_path} ]]; then
# python3 -m venv ${KIRI_HOME}/venv/
# fi
# source "${python_venv_path}/bin/activate"
# Kicad-Diff dependencies
if [[ -f "${KIRI_HOME}/python-requirements.txt" ]]; then
yes | pip3 install -r "${KIRI_HOME}/python-requirements.txt"
else
yes | pip3 install -r https://raw.githubusercontent.com/leoheck/kiri/main/python-requirements.txt
fi
}
init_opam()
{
if [[ -z "${OPAM_VERSION}" ]]; then
OPAM_VERSION=4.10.2
fi
if [[ ! -d "${HOME}/.opam/${OPAM_VERSION}" ]]; then
yes | opam init --disable-sandboxing --reinit
opam switch create ${OPAM_VERSION}
else
opam switch ${OPAM_VERSION}
fi
eval "$(opam env)"
}
install_opam_modules()
{
eval "$(opam env)"
# Update packages knowledge
opam update
# Plotgitsch dependencies
opam install -y digestif
opam install -y lwt
opam install -y lwt_ppx
opam install -y cmdliner
opam install -y base64
opam install -y sha
opam install -y tyxml
opam install -y git-unix
}
# =============================================
# WSL dependent stuff
# =============================================
setup_inskape_worakaround()
{
read -r -d '' PROFILE <<-EOM
# Inkscape workaround: Temporary workaround for broken libgc
if [[ -z "\$_INKSCAPE_GC" ]]; then
export _INKSCAPE_GC=disable
fi
export DISPLAY=\$(grep nameserver /etc/resolv.conf | awk '{print \$2}'):0.0
EOM
if [[ -f ${HOME}/.profile ]]; then
echo -e "\n${PROFILE}" >> ${HOME}/.profile
fi
if [[ -f ${HOME}/.bashrc ]]; then
echo -e "\n${PROFILE}" >> ${HOME}/.bashrc
fi
if [[ -f ${HOME}/.zshrc ]]; then
echo -e "\n${PROFILE}" >> ${HOME}/.zshrc
fi
}
# ================================
main()
{
trap ctrl_c INT
operating_system="$(identify_operating_system)"
case "${operating_system}" in
"Linux")
linux_install_dependencies
;;
"macOS")
macos_install_homebrew
macos_install_kicad
macos_install_brew_modules
;;
"WSL")
linux_install_dependencies
setup_inskape_worakaround
;;
*)
echo "Installer does not handle \"${operating_system}\" yet."
exit 1
;;
esac
install_python_modules
init_opam
install_opam_modules
}
main "${@}"