-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall.bash
More file actions
executable file
·245 lines (212 loc) · 7.63 KB
/
install.bash
File metadata and controls
executable file
·245 lines (212 loc) · 7.63 KB
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
#!/bin/bash
# shellcheck shell=bash
# Default environment is "local"
ENV="local"
# Parse command line arguments
i=0
while [[ $i -lt $# ]]; do
i=$((i + 1))
arg="${!i}"
case $arg in
--env=*)
ENV="${arg#*=}"
;;
--env)
i=$((i + 1))
if [[ $i -le $# ]]; then
ENV="${!i}"
fi
;;
*)
# Unknown option
;;
esac
done
echo "Installing dev tools to enable project management with oe-python-template and derivatives ..."
echo "Environment: $ENV"
# Format: "tool;package;url;environments"
# environments is a comma-separated list of environments where the tool should be installed
# If environments is empty, tool is installed in all environments
# Defaul environment is "local"
LINUX_APT_TOOLS=(
"curl;curl;https://curl.se/;"
"7z;p7zip-rar;https://www.7-zip.org/;"
)
BREW_TOOLS=(
"act;act;https://nektosact.com/;local"
"gh;gh;https://cli.github.com//;local"
"git;git;https://git-scm.com/;local"
"gmake;make;https://www.gnu.org/software/make/;"
"gpg;gnupg;https://gnupg.org/;"
"jq;jq;https://jqlang.org/;"
"magick;imagemagick;https://imagemagick.org/;"
"nixpacks;nixpacks;https://nixpacks.com/;"
"pinact;pinact;https://github.com/suzuki-shunsuke/pinact;local"
"pnpm;pnpm;https://pnpm.io/;"
"rg;ripgrep;https://github.com/BurntSushi/ripgrep;local"
"trivy;trivy;https://trivy.dev/latest/;"
"uv;uv;https://docs.astral.sh/uv/;local"
"xmllint;libxml2;https://en.wikipedia.org/wiki/Libxml2;"
"7z;p7zip;https://github.com/p7zip-project/p7zip;"
"sentry-cli;sentry-cli;https://docs.sentry.io/cli/;"
"git-filter-repo;git-filter-repo;https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository"
)
MAC_BREW_TOOLS=(
"pinentry-mac;pinentry-mac;https://github.com/GPGTools/pinentry;local"
"7zip;p7zip;https://www.7-zip.org/;local"
)
LINUX_BREW_TOOLS=(
# Linux-specific Homebrew tools will be added here
)
UV_TOOLS=(
"copier;copier;https://copier.readthedocs.io/;local"
)
PNPM_TOOLS=(
"@mermaid-js/mermaid-cli;;https://mermaid.js.org/;"
)
# Function to check if a tool should be installed in the current environment
should_install_in_env() {
local environments=$1
# If environments is empty, install in all environments
if [[ -z "$environments" ]]; then
return 0 # true
fi
# Check if the current environment is in the list
IFS=',' read -ra ENV_LIST <<< "$environments"
for e in "${ENV_LIST[@]}"; do
if [[ "$e" = "$ENV" ]]; then
return 0 # true
fi
done
return 1 # false
}
# Function to install/update brew tools
install_or_upgrade_brew_tool() {
local tool=$1
local package=$2
local url=$3
local environments=$4
# Check if the tool should be installed in the current environment
if ! should_install_in_env "$environments"; then
echo "Skipping $tool installation (not needed in $ENV environment)"
return
fi
if command -v "$tool" &> /dev/null; then
tool_path=$(command -v "$tool")
if [[ "$tool_path" == *"brew/"* ]]; then
echo "$tool already installed via Homebrew at $tool_path, upgrading..."
brew upgrade "$package" || true
else
echo "$tool already installed at $tool_path, skipping..."
fi
else
echo "Installing $tool from $package... # $url"
brew install "$package"
fi
}
# Function to install/update Linux tools via apt
install_or_update_linux_apt_tool() {
local tool=$1
local package=$2
local url=$3
local environments=$4
# Check if the tool should be installed in the current environment
if ! should_install_in_env "$environments"; then
echo "Skipping $tool installation (not needed in $ENV environment)"
return
fi
if command -v "$tool" &> /dev/null; then
echo "$tool already installed at $(command -v "$tool"), skipping..."
else
echo "Installing $tool from $package... # $url"
sudo apt-get update -y && sudo apt-get install --no-install-recommends "$package" -y
fi
}
# Function to install/update tools via uv
install_or_update_uv_tool() {
local tool=$1
local package=$2
local url=$3
local environments=$4
# Check if the tool should be installed in the current environment
if ! should_install_in_env "$environments"; then
echo "Skipping $tool installation (not needed in $ENV environment)"
return
fi
if command -v "$tool" &> /dev/null; then
echo "$tool already installed at $(command -v "$tool"), updating..."
uv tool update "$package"
else
echo "Installing $tool from $package... # $url"
uv tool install "$package"
fi
}
# Install/update Linux packages
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
for tool_entry in "${LINUX_APT_TOOLS[@]}"; do
IFS=";" read -r tool package url environments <<< "$tool_entry"
install_or_update_linux_apt_tool "$tool" "$package" "$url" "$environments"
done
fi
# Install/update Homebrew itself
if ! command -v brew &> /dev/null; then
# Check if we should install Homebrew in this environment
if [[ "$ENV" = "local" ]]; then
echo "Installing Homebrew... # https://brew.sh/"
/bin/bash -c "$(curl --proto "=https" -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Skipping Homebrew installation (not needed in $ENV environment)"
fi
elif [[ "$ENV" = "local" ]]; then
echo "Homebrew already installed at $(command -v brew), updating..."
brew update
fi
# Only proceed with Homebrew tools if brew is available
if command -v brew &> /dev/null; then
# Install/update Homebrew tools
for tool_entry in "${BREW_TOOLS[@]}"; do
IFS=";" read -r tool package url environments <<< "$tool_entry"
install_or_upgrade_brew_tool "$tool" "$package" "$url" "$environments"
done
# Install/update Homebrew tools for macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
for tool_entry in "${MAC_BREW_TOOLS[@]}"; do
IFS=";" read -r tool package url environments <<< "$tool_entry"
install_or_upgrade_brew_tool "$tool" "$package" "$url" "$environments"
done
fi
# Install/update Homebrew tools for Linux
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
for tool_entry in "${LINUX_BREW_TOOLS[@]}"; do
IFS=";" read -r tool package url environments <<< "$tool_entry"
install_or_upgrade_brew_tool "$tool" "$package" "$url" "$environments"
done
fi
fi
# Install/update UV tools
for tool_entry in "${UV_TOOLS[@]}"; do
IFS=";" read -r tool package url environments <<< "$tool_entry"
install_or_update_uv_tool "$tool" "$package" "$url" "$environments"
done
# Function to install/update tools via pnpm
install_or_update_pnpm_tool() {
local package=$1
local url=$2
local environments=$3
# Check if the tool should be installed in the current environment
if ! should_install_in_env "$environments"; then
echo "Skipping $package installation (not needed in $ENV environment)"
return
fi
if command -v pnpm &> /dev/null; then
echo "Installing/updating $package via pnpm... # $url"
pnpm add -g --ignore-scripts "$package"
else
echo "pnpm not found, skipping $package installation"
fi
}
# Install/update pnpm tools
for tool_entry in "${PNPM_TOOLS[@]}"; do
IFS=";" read -r package _ url environments <<< "$tool_entry"
install_or_update_pnpm_tool "$package" "$url" "$environments"
done