/
run_before_04-requirements.sh.tmpl
280 lines (250 loc) · 11.5 KB
/
run_before_04-requirements.sh.tmpl
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
#!/usr/bin/env bash
# @file System Requirements
# @brief Ensures commonly used system packages that are common dependencies of other packages are installed
# @description
# This script installs required system packages. Each system's required packages are defined in `home/.chezmoitemplates/$DISTRO_ID`,
# where `$DISTRO_ID` is equal to the Linux distribution ID found in `/etc/os-release`.
{{ includeTemplate "universal/logg-before" }}
{{- $packages := splitList " " (includeTemplate "universal/common-dependencies" .) -}}
{{- if ne .host.distro.id "darwin" -}}
{{- $additionalPackages := splitList " " (includeTemplate (print .host.distro.id "/common-dependencies") .) -}}
{{- $packages = concat $packages $additionalPackages -}}
{{- end -}}
### Ensure Ubuntu / Debian run in `noninteractive` mode
export DEBIAN_FRONTEND=noninteractive
if [ -d /Applications ] && [ -d /System ]; then
### Ensure environment variables are appropriately configured
export VOLTA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/volta"
export PATH="$VOLTA_HOME/bin:$PATH"
### Check for presence of Homebrew
if command -v brew > /dev/null; then
### Install base dependencies
logg 'Installing base dependencies for macOS using brew bundle'
logg info 'Dependencies: age jq node glow go go-task/tap/go-task gnupg gum m-cli progress volta yq m-cli yq zx'
logg info 'GNU compatibility dependencies: coreutils findutils'
brew bundle --verbose --no-lock --file=/dev/stdin <<EOF
{{ includeTemplate "darwin/Brewfile" . -}}
EOF
### Ensure Python version is 3.11 or higher
PYTHON_VERSION="$(python3 --version | sed 's/Python //')"
MIN_PYTHON_VERSION="3.11.0"
if [ "$(printf '%s\n' "$MIN_PYTHON_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" = "$MIN_PYTHON_VERSION" ]; then
logg info "Minimum Python version satisfied (minimum: $MIN_PYTHON_VERSION, current: $PYTHON_VERSION)"
else
logg info 'Updating Python 3 version with brew link --overwrite python@3.11'
brew link --overwrite python@3.11
fi
else
logg error 'brew was not found in the PATH'
fi
else
if [ '{{ .host.distro.id }}' = 'archlinux' ]; then
### Print dependency list
logg 'Installing common dependencies using pacman'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if pacman -Qs "$PACKAGE" > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo pacman -Sy --noconfirm --needed "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via pacman'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
### Install yay
if ! command -v yay > /dev/null; then
logg info 'Cloning yay from https://aur.archlinux.org/yay.git to /usr/local/src/yay'
sudo git clone https://aur.archlinux.org/yay.git /usr/local/src/yay
cd /usr/local/src/yay
logg info 'Installing yay via sudo makepkg -si'
sudo makepkg -si
fi
elif [ '{{ .host.distro.id }}' = 'centos' ]; then
### Upgrade system
logg info 'Upgrade system'
sudo dnf upgrade --refresh -y
### Enable CRB
logg info 'Ensure the CRB repository is activated'
sudo dnf config-manager --set-enabled crb
### Add EPEL
if ! dnf repolist | grep 'epel ' > /dev/null; then
logg info 'Adding the EPEL repository'
sudo dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION}.noarch.rpm"
fi
### Add EPEL Next
if ! dnf repolist | grep 'epel-next' > /dev/null; then
logg info 'Adding the EPEL Next repository'
sudo dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-${VERSION}.noarch.rpm"
else
logg info 'EPEL Next repository already enabled (EPEL compatibility for CentOS)'
fi
### Detect package manager
if command -v dnf > /dev/null; then
PKG_MANAGER='dnf'
else
PKG_MANAGER='yum'
fi
### Print dependency list
logg 'Installing common dependencies using '"$PKG_MANAGER"''
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if rpm -qa | grep "^$PACKAGE-" > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo "$PKG_MANAGER" install -y "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via '"$PKG_MANAGER"''
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
elif [ '{{ .host.distro.id }}' = 'debian' ]; then
if command -v apt-get > /dev/null && [ -f /etc/apt/preferences.d/nosnap.pref ]; then
logg info 'Moving /etc/apt/preferences.d/nosnap.pref to /etc/apt/nosnap.pref.bak' && sudo mv -f /etc/apt/preferences.d/nosnap.pref /etc/apt/nosnap.pref.bak
fi
### Print dependency list
logg 'Installing common dependencies using apt-get'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Update apt-get cache
logg info 'Running sudo apt-get update'
sudo apt-get update
### Update debconf for non-interactive installation
if command -v dpkg-reconfigure > /dev/null; then
logg info 'Running sudo dpkg-reconfigure debconf -f noninteractive -p critical'
sudo dpkg-reconfigure debconf -f noninteractive -p critical
fi
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if dpkg -l "$PACKAGE" | grep -E '^ii' > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via apt-get'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
elif [ '{{ .host.distro.id }}' = 'fedora' ]; then
### Upgrade system
logg info 'Upgrade system'
sudo dnf upgrade --refresh -y
# https://docs.fedoraproject.org/en-US/quick-docs/dnf-system-upgrade/
# TODO - Optional: Look into using Fedora's upgrade system described in the link above
# sudo dnf install dnf-plugin-system-upgrade
### Add RPM Fusion Free repository
if ! dnf repolist | grep 'rpmfusion-free' > /dev/null; then
logg info 'Adding RPM-Fusion Free repository for Fedora'
sudo dnf install -y "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm"
fi
### Add RPM Fusion Non-Free repository
if ! dnf repolist | grep 'rpmfusion-nonfree' > /dev/null; then
logg info 'Adding RPM-Fusion Non-Free repository for Fedora'
sudo dnf install -y "https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm"
fi
### Add Appstream data from the RPM Fusion repositories
if command -v gnome-shell > /dev/null; then
logg info 'Adding Appstream data from the RPM-Fusion repositories'
sudo dnf group update -y core
else
logg warn 'Skipping installation of Appstream data because GNOME is not installed'
fi
### Print dependency list
logg 'Installing common dependencies using dnf'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if rpm -qa | grep "^$PACKAGE-" > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo dnf install -y "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via dnf'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
elif [ '{{ .host.distro.id }}' = 'freebsd' ]; then
### Print dependency list
logg 'Installing common dependencies using pkg'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Install base dependencies
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Installing '"$PACKAGE"''
sudo pkg install -y "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via zypper'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
done
elif [ '{{ .host.distro.id }}' = 'opensuse' ]; then
### Print dependency list
logg 'Installing common dependencies using zypper'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Install base_devel
logg info 'Installing base_devel pattern with sudo zypper install -t pattern devel_basis'
sudo zypper install -t pattern devel_basis
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if rpm -qa | grep "$PACKAGE" > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo zypper install -y "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via zypper'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
elif [ '{{ .host.distro.id }}' = 'ubuntu' ]; then
if command -v apt-get > /dev/null && [ -f /etc/apt/preferences.d/nosnap.pref ]; then
logg info 'Moving /etc/apt/preferences.d/nosnap.pref to /etc/apt/nosnap.pref.bak' && sudo mv -f /etc/apt/preferences.d/nosnap.pref /etc/apt/nosnap.pref.bak
fi
### Print dependency list
logg 'Installing common dependencies using apt-get'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'
### Update apt-get cache
logg info 'Running sudo apt-get update'
sudo apt-get update
### Update debconf for non-interactive installation
if command -v dpkg-reconfigure > /dev/null; then
logg info 'Running sudo dpkg-reconfigure debconf -f noninteractive -p critical'
sudo dpkg-reconfigure debconf -f noninteractive -p critical
fi
### Install packages if they are not already present
for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do
logg info 'Checking for presence of '"$PACKAGE"''
if dpkg -l "$PACKAGE" | grep -E '^ii' > /dev/null; then
logg info 'The '"$PACKAGE"' package is already installed'
else
logg info 'Installing '"$PACKAGE"''
sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$?
if [ -n "$EXIT_CODE" ]; then
logg error 'Error installing '"$PACKAGE"' via apt-get'
logg info 'Proceeding with installation..'
unset EXIT_CODE
fi
fi
done
fi
fi