-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.sh
executable file
·57 lines (50 loc) · 1.49 KB
/
helper.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
#!/bin/bash
# Script Directory
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
DETECT_INIT_SCRIPT="$SCRIPT_DIR/detectInit.sh"
getPkgString() {
if [[ "${initType}" == "systemD" ]]; then
echo "Detected :"
echo -e "\e[1;34mInit -> ${initType} \nDistro -> [Arch]\e[0m"
pkgString=($(echo "${packages[@]}" | awk -F" " '{ print $0}'))
else
echo "Detected :"
echo -e "\e[32mInit -> $initType \nDistro -> [Artix]\e[0m"
pkgString=""
for package in "${packages[@]}"; do
packageExist=$(pacman -Ss "${package}-${initType}")
if [[ "${packageExist}" != "" ]]; then
pkgString+="${package}-${initType} "
else
pkgString+="${package} "
fi
done
pkgString=($(echo "${pkgString}" | sed 's/^[ \t]*\(.*$\)/\1/' | awk -F" " '{ print $0}'))
fi
}
install() {
packages=($(echo "$1" | awk -F" " '{ print $0}'))
iteration=1
max_iteration=5
initType=$(bash "${DETECT_INIT_SCRIPT}")
getPkgString
# Handle Repository
if [[ "$2" == "pac" ]]; then
while [ $iteration -le $max_iteration ]; do
sudo pacman -S --noconfirm "${pkgString[@]}" && break
iteration=$(($iteration + 1))
done
elif [[ "$2" == "yay" ]]; then
while [ $iteration -le $max_iteration ]; do
yay -S --noconfirm "${packages[@]}" && break
iteration=$(($iteration + 1))
done
fi
# Check Success
if [[ $iteration -eq $max_iteration ]]; then
# Append Failed to install packages to a file
echo "${packages[@]}" >>"$SCRIPT_DIR/err.txt"
else
echo "All packages installed successfully!"
fi
}