-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.sh
executable file
·108 lines (85 loc) · 2.1 KB
/
util.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
#!/bin/bash
function main {
# install helper works with:
# pacman, yay, zipper
type="${1}"
# array of utils
install_utils=(pacman yay apt zypper)
# get package tool
for util in ${install_utils[@]};
do
bin_exits=$(which ${util} 2> /dev/null | grep ${util} -c)
if [[ ${bin_exits} == "1" ]]; then
# install yay
#if [[ ${util} == "pacman" ]]; then
# sudo pacman -S yay --noconfirm --needed
# util=(yay)
#fi
# return binary
install_util=${util}
echo "found: ${install_util}"
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}"
arr="${@:2}"
for pkg in ${arr}
do
case ${bin} in
'pacman')
sudo ${bin} -S --noconfirm --needed ${pkg}
;;
'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}"
arr="${@:2}"
for pkg in ${arr}
do
case ${bin} in
'pacman')
sudo ${bin} -Rs --noconfirm ${pkg}
;;
'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 "$@"