-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.sh
More file actions
executable file
·107 lines (83 loc) · 2.15 KB
/
util.sh
File metadata and controls
executable file
·107 lines (83 loc) · 2.15 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
#!/bin/bash
function main {
# install helper works with:
# pacman, yay, zipper
type="${1}"
# array of utils ordered by preference
install_utils=(paru yay pacman apt zypper)
# Reset install_util to ensure a selection is made
install_util=""
# get package tool
for util in ${install_utils[@]};
do
# Check if the utility binary exists
#bin_exits=$(which ${util} 2> /dev/null | grep ${util} -c)
#if [[ ${bin_exits} == "1" ]]; then
if which "${util}" > /dev/null 2>&1; then
# return first found binary
install_util=${util}
echo "found: ${install_util}"
break
fi
done
# which type
case ${type} in
'-i') # install
install ${install_util} ${@:2}
;;
'-r') # remove
remove ${install_util} ${@:2}
;;
*)
echo -n "unknown"
;;
esac
}
function install {
bin="${1}"
for pkg in "${@:2}"
do
case ${bin} in
'pacman')
sudo ${bin} -S --noconfirm --needed ${pkg}
;;
'paru'|'yay')
${bin} -S --noconfirm --needed ${pkg}
;;
'zypper')
sudo ${bin} -n install ${pkg}
;;
'apt')
sudo ${bin} install -y ${pkg}
;;
*)
echo -n "unknown"
;;
esac
done
}
function remove {
bin="${1}"
for pkg in "${@:2}"
do
case ${bin} in
'pacman')
sudo ${bin} -Rs --noconfirm ${pkg}
;;
'paru'|'yay')
${bin} -Rs --noconfirm ${pkg}
;;
'zypper')
sudo ${bin} -n rm ${pkg}
;;
'apt')
sudo ${bin} remove -y ${pkg}
;;
*)
echo -n "unknown"
;;
esac
done
}
# pass all args
main "$@"