-
Notifications
You must be signed in to change notification settings - Fork 35
/
install_kiri.sh
executable file
·131 lines (103 loc) · 2.93 KB
/
install_kiri.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
#!/bin/bash
# Install KiRI and Kicad Plugin
# Set INSTALL_KIRI_REMOTELLY, to have kiri donwloaded from GitHub
# Otherwise it will install the local version of the script
# Default KIRI_INSTALL_PATH: ${HOME}/.local/share
CI=$(tput setaf 3) # Color Info
CB=$(tput bold) # Color Bold
CR=$(tput sgr0) # Color Reset
export KIRI_INSTALL_PATH
export KIRI_HOME
export KIRI_BRANCH
install_kiri()
{
# Remove previews version, if any
rm -rf "${KIRI_HOME}/kiri"
if [[ -n "${INSTALL_KIRI_REMOTELLY}" ]]; then
# Clone Kiri
if which git &> /dev/null; then
git clone --recurse-submodules -j8 https://github.com/leoheck/kiri.git "${KIRI_HOME}/kiri"
cd "${KIRI_HOME}/kiri/" || exit
git checkout ${KIRI_BRANCH}
else
echo "Git is missing, please use install_dependencies script"
exit 1
fi
else
cp -rf "../kiri" "${KIRI_HOME}"
fi
}
install_plotgitsch()
{
# Reload opam making sure it is available in the PATH
eval "$(opam env)"
# Install plotkicadsch
cd "${KIRI_HOME}/kiri/submodules/plotkicadsch" || exit
opam pin add -y kicadsch .
opam pin add -y plotkicadsch .
opam update -y
opam install -y plotkicadsch
cd - || exit
}
intall_kicad_plugin()
{
if [[ -n "${INSTALL_KIRI_REMOTELLY}" ]]; then
local install_url="https://raw.githubusercontent.com/leoheck/kiri/main/install_plugin.sh"
bash -c "$(curl -fsSL ${install_url})" "" "${KIRI_HOME}/kiri/" > /dev/null
else
./install_plugin.sh
fi
}
show_env_config_message()
{
read -r -d '' ENV_SETUP_NOTE <<-EOM
${CI}${CB}Finish KiRi setup by adding the following lines in the end of your ~/.bashrc or ~/.zshrc${CR}
# WINDOWS USERS
# Set DISPLAY to use X terminal in WSL
# In WSL2 the localhost and network interfaces are not the same than windows
if grep -q "WSL2" /proc/version &> /dev/null; then
# execute route.exe in the windows to determine its IP address
export DISPLAY=\$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print \$4}'):0.0
else
# In WSL1 the DISPLAY can be the localhost address
if grep -qi "Microsoft" /proc/version &> /dev/null; then
export DISPLAY=127.0.0.1:0.0
fi
fi
# Kiri environment setup
eval \$(opam env)
export KIRI_HOME="${KIRI_HOME}/kiri"
export PATH=\${KIRI_HOME}/submodules/KiCad-Diff/bin:\${PATH}
export PATH=\${KIRI_HOME}/bin:\${PATH}
EOM
echo -e "\n\n${ENV_SETUP_NOTE}\n"
}
show_initial_message()
{
if [[ -n "${KIRI_INSTALL_PATH}" ]]; then
KIRI_HOME="${KIRI_INSTALL_PATH}"
else
KIRI_HOME="${HOME}/.local/share"
fi
if [[ -n "${KIRI_BRANCH}" ]]; then
KIRI_BRANCH="main"
fi
read -r -d '' ENV_SETUP_NOTE <<-EOM
${CI}${CB}Installing KiRI${CR}
Installation path ${KIRI_HOME}
Change it using KIRI_INSTALL_PATH environment variable
KIRI_BRANCH variable can be used to test other branches of Kiri
Hit ENTER to continue or Ctrl+C to leave.
EOM
echo -e "\n${ENV_SETUP_NOTE}\n"
read
}
main()
{
show_initial_message
install_kiri
install_plotgitsch
intall_kicad_plugin
show_env_config_message
}
main