-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·261 lines (187 loc) · 5.1 KB
/
Copy pathdeploy
File metadata and controls
executable file
·261 lines (187 loc) · 5.1 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
set -Eeuo pipefail
trap 'echo "Error on line $LINENO: $BASH_COMMAND" >&2' ERR
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly CONFIG_DIR="$HOME/.config"
readonly PACMAN_CONF="/etc/pacman.conf"
info() {
echo "==> $*"
}
error() {
echo "ERROR: $*" >&2
exit 1
}
require_command() {
local command="$1"
if ! command -v "$command" >/dev/null 2>&1; then
error "Required command not found: $command"
fi
}
load_dependencies() {
local file="$1"
local -n deps="$2"
deps=()
[[ -f "$file" ]] || return 0
mapfile -t deps < <(
sed \
-e 's/#.*//' \
-e '/^[[:space:]]*$/d' \
-e 's/^[[:space:]]*//' \
-e 's/[[:space:]]*$//' \
"$file"
)
}
enable_multilib() {
info "Enabling multilib repository"
if grep -qE '^[[:space:]]*\[multilib\][[:space:]]*$' "$PACMAN_CONF"; then
info "Multilib is already enabled."
return
fi
if ! grep -qE '^[[:space:]]*#\[multilib\][[:space:]]*$' "$PACMAN_CONF"; then
error "Could not find the commented multilib section in $PACMAN_CONF"
fi
sudo sed -i \
-e 's/^[[:space:]]*#\[multilib\][[:space:]]*$/[multilib]/' \
-e 's/^[[:space:]]*#Include = \/etc\/pacman\.d\/mirrorlist$/Include = \/etc\/pacman.d\/mirrorlist/' \
"$PACMAN_CONF"
info "Multilib enabled."
}
configure_reflector() {
info "Installing and enabling reflector"
sudo pacman -S --needed --noconfirm reflector
sudo systemctl enable --now reflector.service
}
update_system() {
info "Updating system packages"
sudo pacman -Syu --noconfirm
}
install_yay() {
info "Installing yay"
sudo pacman -S --needed --noconfirm git base-devel
local build_dir
build_dir="$(mktemp -d)"
trap 'rm -rf "$build_dir"' EXIT
git clone https://aur.archlinux.org/yay.git "$build_dir/yay"
(
cd "$build_dir/yay"
makepkg -si --noconfirm
)
rm -rf "$build_dir"
info "yay installed."
}
update_aur_helper() {
info "Updating AUR packages"
yay -Syu --noconfirm
}
install_pacman_dependencies() {
local dependency_file="$SCRIPT_DIR/dependencies/pacman.txt"
local dependencies=()
info "Installing official repository packages"
load_dependencies "$dependency_file" dependencies
if ((${#dependencies[@]} == 0)); then
info "No pacman dependencies to install."
return
fi
sudo pacman -S --needed --noconfirm "${dependencies[@]}"
}
install_aur_dependencies() {
local dependency_file="$SCRIPT_DIR/dependencies/aur.txt"
local dependencies=()
info "Installing AUR packages"
load_dependencies "$dependency_file" dependencies
if ((${#dependencies[@]} == 0)); then
info "No AUR dependencies to install."
return
fi
yay -S --needed --noconfirm "${dependencies[@]}"
}
install_packages() {
install_pacman_dependencies
if ! command -v yay >/dev/null 2>&1; then
install_yay
fi
update_aur_helper
install_aur_dependencies
}
create_config_symlinks() {
local config_dir
local config_name
local target
local backup
info "Creating configuration symlinks"
mkdir -p "$CONFIG_DIR"
# Handle .zshrc
if [[ -L "$HOME/.zshrc" ]] && [[ "$(readlink "$HOME/.zshrc")" == "$SCRIPT_DIR/.zshrc" ]]; then
info "Already linked .zshrc"
else
if [[ -e "$HOME/.zshrc" || -L "$HOME/.zshrc" ]]; then
backup="$HOME/.zshrc.backup.$(date +%Y%m%d%H%M%S%N)"
mv "$HOME/.zshrc" "$backup"
info "Backed up .zshrc to $backup"
fi
ln -s "$SCRIPT_DIR/.zshrc" "$HOME/.zshrc"
info "Linked .zshrc"
fi
shopt -s nullglob
for config_dir in "$SCRIPT_DIR"/config/*/; do
config_name="$(basename "$config_dir")"
target="$CONFIG_DIR/$config_name"
if [[ -L "$target" ]] && [[ "$(readlink "$target")" == "$config_dir" ]]; then
info "Already linked $config_name"
continue
fi
if [[ -e "$target" || -L "$target" ]]; then
backup="$target.backup.$(date +%Y%m%d%H%M%S%N)"
mv "$target" "$backup"
info "Backed up $config_name to $backup"
fi
ln -s "$config_dir" "$target"
info "Linked $config_name"
done
shopt -u nullglob
}
make_waybar_script_executable() {
local waybar_script="$CONFIG_DIR/waybar/waybar.sh"
if [[ -f "$waybar_script" ]]; then
info "Making Waybar script executable"
chmod +x "$waybar_script"
fi
}
change_default_shell() {
local zsh_path
info "Configuring default shell"
if ! command -v zsh >/dev/null 2>&1; then
info "zsh is not installed; skipping shell configuration."
return
fi
zsh_path="$(command -v zsh)"
if [[ "$SHELL" == "$zsh_path" ]]; then
info "zsh is already the default shell."
return
fi
chsh -s "$zsh_path"
info "Default shell changed to $zsh_path."
}
validate_environment() {
info "Checking environment"
if [[ "$EUID" -eq 0 ]]; then
error "Do not run this script as root."
fi
require_command sudo
require_command pacman
require_command git
sudo -v
}
main() {
info "Starting Arch Linux setup"
validate_environment
create_config_symlinks
enable_multilib
configure_reflector
update_system
install_packages
change_default_shell
make_waybar_script_executable
info "Arch Linux setup completed successfully."
}
main "$@"