-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx
executable file
·146 lines (127 loc) · 3.28 KB
/
px
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
#!/bin/bash
function help() {
echo -e " ______ __
| _ \ \/ /
| |_) \ /
| __// \\
|_| /_/\_\\
${GREEN}PX - wrapper for package managers${NC}
${YELLOW}Usage:${NC}
px <command> [<args>]
${YELLOW}Some useful dk commands are:${NC}
${GREEN}add${NC} install package
${GREEN}rm${NC} remove package
${GREEN}up${NC} update packages
${GREEN}sync${NC} sync repo list
${GREEN}clean${NC} cleanup cache
${GREEN}<pkg>${NC} search for <pkg> package
${GREEN}sup${NC} list supported package managers"
exit 1
}
function sup() {
echo -e "
${YELLOW}Supported package managers${NC}:
${GREEN}dnf${NC} Fedora, RHEL
${GREEN}yay${NC} Archlinux, Manjaro
${GREEN}pacman${NC} Archlinux, Manjaro
${GREEN}apt${NC} Debian, ubuntu, Linux Mint
${GREEN}apk${NC} Alpine
${GREEN}zypper${NC} OpenSuse
${GREEN}brew${NC} macOS"
exit 1
}
function run_yay() {
! [ -x "$(command -v yay)" ] && run_pacman "$command" "$pkg"
case "$command" in
add) yay -S $pkg ;;
rm) yay -R $pkg ;;
up) yay -Syyu ;;
sync) yay -Sy ;;
clean) yay -Sc ;;
*) yay "$command" ;;
esac
}
function run_pacman() {
case "$command" in
add) sudo pacman -S $pkg --noconfirm ;;
rm) sudo pacman -R $pkg ;;
up) sudo pacman -Syu ;;
sync) sudo pacman -Sy ;;
clean) sudo pacman -Scc ;;
*) pacman -Ss "$command" ;;
esac
}
function run_dnf() {
case "$command" in
add) sudo dnf install -y $pkg ;;
rm) sudo dnf remove $pkg ;;
up | sync) sudo dnf upgrade ;;
clean) sudo dnf autoremove -y && sudo dnf clean all ;;
*) sudo dnf search "$command" ;;
esac
}
function run_apt() {
case "$command" in
add) sudo apt install -y $pkg ;;
rm) sudo apt remove -y $pkg ;;
up) sudo apt upgrade ;;
sync) sudo apt update ;;
clean) sudo apt autoremove && sudo apt clean ;;
*) sudo apt search "$command" ;;
esac
}
function run_zypper() {
case "$command" in
add) zypper install $pkg ;;
rm) zypper remove $pkg ;;
up) zypper update ;;
sync) zypper refresh ;;
clean) zypper clean ;;
*) zypper search "$command" ;;
esac
}
function run_apk() {
case "$command" in
add) apk add $pkg ;;
rm) apk del $pkg ;;
up) apk upgrade ;;
sync) apk update ;;
clean) apk cache clean ;;
*) apk search "$command" ;;
esac
}
function run_brew() {
case "$command" in
add) brew install $pkg ;;
rm) brew uninstall $pkg ;;
up) brew upgrade ;;
sync) brew update ;;
clean) brew cleanup ;;
*) brew search "$command" ;;
esac
}
function main() {
[[ -z "$command" ]] && help
if [ "$1" == 'sup' ]; then sup; fi
case "$distro" in
arch | manjaro) run_yay "$command" "$pkg" ;;
fedora | \"rhel\") run_dnf "$command" "$pkg" ;;
debian | ubuntu | linuxmint) run_apt "$command" "$pkg" ;;
\"opensuse-tumbleweed\" | \"opensuse-leap\") run_zypper "$command" "$pkg" ;;
alpine) run_apk "$command" "$pkg" ;;
Darwin) run_brew "$command" "$pkg" ;;
*) echo -e "${RED}px doesnt support your distro. See 'sup' command${NC}" ;;
esac
}
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
if [ -f "/etc/os-release" ]; then
distro=$(sed -n 's/^ID=//p' /etc/os-release)
else
distro=$(uname)
fi
command=$1
pkg="${*:2}"
main "$@"