-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.sh
303 lines (265 loc) · 8.06 KB
/
post.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
#!/bin/bash
set -euo pipefail # Exit immediately if a command fails, with error if a variable is unset, and propagate exit code in pipes
readonly LOG_FILE="/var/log/post_install.log"
# Logging function
log() {
local message="$1"
local code="${2:-0}" # Default to 0 if no code is provided
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message (exit code: $code)" >> "$LOG_FILE"
echo "$message" ; sleep 1
}
# User confirmation function
confirm() {
local prompt="$1"
read -rp "$prompt [Y/n] " choice
case "$choice" in
[yY]|[yY][eE][sS]|"") return 0 ;; # Yes
*) return 1 ;; # No
esac
}
# Function to install office suite
install_office_suite() {
log "Installing office suite"
read -p "Would you like to install Calligra or LibreOffice? (c/l): " choice
case "$choice" in
c|C)
install_package "calligra"
;;
l|L)
install_package "libreoffice-fresh" # or "libreoffice-still"
;;
*)
log "Invalid option. Please choose 'c' for Calligra or 'l' for LibreOffice." 1
;;
esac
}
# Function to install a package using pacman
install_package() {
local package=$1
log "Installing $package..."
if ! sudo pacman -S --noconfirm "$package"; then
log "Failed to install $package." 1
fi
}
# Add repository keys and setup Chaotic AUR
setup_chaotic_aur() {
log "Setting up Chaotic AUR repositories"
if ! grep -q '\[chaotic-aur\]' /etc/pacman.conf; then
if confirm "This will modify your /etc/pacman.conf to add Chaotic AUR. Proceed?"; then
pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
pacman-key --lsign-key 3056513887B78AEB
pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
chaotic_config="[chaotic-aur]\nInclude = /etc/pacman.d/chaotic-mirrorlist\n"
echo -e "$chaotic_config" >> /etc/pacman.conf
else
log "Chaotic AUR setup canceled."
fi
else
log "Chaotic AUR is already set up."
fi
}
# Update packages
update_packages() {
log "Updating repositories and packages"
if confirm "This will update your system packages. Proceed?"; then
if ! pacman -Syu --noconfirm; then
log "Failed to update packages." 1
fi
else
log "Package update canceled."
fi
}
# Configure Plymouth
configure_plymouth() {
log "Configuring Plymouth"
if confirm "This will install and configure Plymouth. Proceed?"; then
pacman -S --noconfirm plymouth
if ! grep -q "plymouth" /etc/mkinitcpio.conf; then
sed -i '/^HOOKS=/ s/udev/& plymouth/' /etc/mkinitcpio.conf
fi
plymouth-set-default-theme -R spinner
if pacman -Qi "grub" >/dev/null; then
sudo sed -i.bak 's/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/' /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
else
sed -i '/^options / s/rw/rw quiet splash/' /boot/loader/entries/*linu*.conf
fi
else
log "Plymouth configuration canceled."
fi
}
# Function to install packages from an array
install_packages_from_array() {
local category="$1"
shift
local packages=("$@")
log "Installing packages for $category..."
for pkg in "${packages[@]}"; do
if pacman -Qi "$pkg" >/dev/null 2>&1; then
log "$pkg is already installed."
else
log "Installing $pkg..."
if ! sudo pacman -S --noconfirm "$pkg"; then
log "Failed to install $pkg for $category." 1
fi
fi
done
log "Done installing packages for $category."
echo
}
# Main function
install_packages() {
# Define arrays for different categories
local base_system=(
"base-devel"
"git"
"xdg-user-dirs"
)
local desktop_environment=(
"archlinux-wallpaper"
)
local web_browsers=(
"firefox"
"chromium"
)
local fonts=(
"noto-fonts"
"noto-fonts-emoji"
"noto-fonts-cjk"
)
local video=(
"vlc"
"stremio"
"mpv"
)
local libs=(
"ffmpeg"
"gstreamer"
"gst-plugins-good"
"gst-plugins-bad"
"gst-plugins-ugly"
"imagemagick"
"libbluray"
"libaacs"
"webp-pixbuf-loader"
)
local communication=(
"discord"
)
local printing=(
"cups"
"system-config-printer"
"hplip"
)
local development=(
"bash-completion"
"python-pillow"
"python-pyqt5"
)
local graphics=(
"gimp"
"inkscape"
)
# Array containing all category arrays
local categories=(
"base_system"
"desktop_environment"
"web_browsers"
"fonts"
"video"
"libs"
"communication"
"printing"
"development"
"graphics"
)
# Loop through categories and install packages
for category in "${categories[@]}"; do
local packages
eval "packages=(\"\${${category}[@]}\")"
install_packages_from_array "$category" "${packages[@]}"
done
# Enable CUPS service if CUPS installed
if pacman -Qi cups >/dev/null 2>&1; then
systemctl enable cups.service
fi
# Install XFCE extensions if XFCE is installed
if pacman -Qi xfce4-panel >/dev/null 2>&1; then
log "Installing XFCE extensions and locker"
if confirm "This will install XFCE extensions. Proceed?"; then
sudo pacman -Rsnc --noconfirm xfce4-screensaver || log "Failed to remove xfce4-screensaver." 1
sudo pacman -S --noconfirm light-locker mugshot || log "Failed to install XFCE extensions." 1
else
log "XFCE extensions installation canceled."
fi
fi
}
# Install pfetch-rs
install_pfetch_rs() {
log "Installing pfetch-rs"
if confirm "This will download and install pfetch-rs. Proceed?"; then
if ! wget -qO- https://github.com/Gobidev/pfetch-rs/releases/download/v2.9.1/pfetch-linux-gnu-x86_64.tar.gz | tar -xzf -; then
log "Failed to download pfetch-rs." 1
return
fi
install -Dm755 pfetch /usr/bin/pfetch || log "Failed to install pfetch." 1
rm -f pfetch
else
log "pfetch-rs installation canceled."
fi
}
# Append line to all user's .bashrc
append_to_bashrc() {
log "Appending pfetch to user's .bashrc"
for user_home in /home/*; do
if [ -f "$user_home/.bashrc" ]; then
echo -e "\n\npfetch" >> "$user_home/.bashrc"
fi
done
}
cleanup() {
log "Cleaning up..."
if pacman -Qtdq | grep -q .; then
if confirm "This will remove orphaned packages. Proceed?"; then
sudo pacman -Rns --noconfirm $(pacman -Qtdq) || log "Failed to remove orphaned packages." 1
else
log "Orphaned package removal canceled."
fi
fi
if confirm "This will clean the package cache. Proceed?"; then
sudo pacman -Scc --noconfirm || log "Failed to clean package cache." 1
else
log "Package cache cleanup canceled."
fi
}
# Prompt user to reboot
prompt_reboot() {
echo
read -rp "Do you want to reboot now? [Y/n] " choice
case "$choice" in
[yY]|[yY][eE][sS]|"")
log "Rebooting system"
systemctl reboot
;;
*)
log "Post-installation tasks completed. You can manually reboot later."
;;
esac
}
# Main function
main() {
# Backup pacman.conf before modifying
cp /etc/pacman.conf /etc/pacman.conf.bak
sed -i '/^#Color/s/^#//; /^#ParallelDownloads/s/^#//' /etc/pacman.conf
setup_chaotic_aur
update_packages
configure_plymouth
install_packages
install_office_suite # Call the office suite installation function
install_pfetch_rs
append_to_bashrc
cleanup
prompt_reboot
}
main