-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpm.sh
157 lines (139 loc) · 3.13 KB
/
xpm.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
#!/usr/bin/env sh
pm=""
HOOKS_DIR=~/.config/xpm/hooks
if [ "$(uname)" = "Darwin" ]; then HOOKS_DIR=~/Library/Application Support/xpm/hooks; fi
# misc
usage() {
echo "usage: xpm COMMAND [PKG ...]"
echo ""
echo "xpm - x package manager, an interface to the system package manager."
echo ""
echo "COMMAND"
echo "install, in, i install all [PKG]"
echo "remove, re, r uninstall all [PKG] (and dependencies)"
echo "search, se, s search the repositories for [PKG]"
echo "query, qry, q query [PKG] for information"
echo "list, ls, l list installed files for [PKG]"
echo "update, up, u update all packages on the system"
echo ""
echo "See the README.md file for more details"
}
# hooks
exec_hooks() {
if [ "$1" = "" ]; then return; fi
if [ ! -d "$HOOKS_DIR" ]; then mkdir -p $HOOKS_DIR; fi
for f in "$HOOKS_DIR"/*; do
if [ "$(basename "$f")" = "$1" ]; then
echo "executing $f"
exec "$f"
fi
done
}
# identify the package manager
identify_pm() {
if [ "$(command -v apt)" ] && [ "$(command -v apt-get)" ]; then
pm="apt"
elif [ "$(command -v zypper)" ]; then
pm="zypper"
elif [ "$(command -v xbps-install)" ]; then
pm="xbps"
elif [ "$(command -v brew)" ]; then
pm="homebrew"
else
unknown_pm
fi
}
unknown_pm() {
echo "unknown package manager!"
echo " The package manager for your system could not be recognised."
echo " If you're using a stanadard package manager, report it to the dev so he can add support."
exit
}
# xpm commands
xpm_install() {
case $pm in
"apt") sudo apt install "$@" ;;
"zypper") sudo zypper install "$@" ;;
"xbps") sudo xbps-install "$@" ;;
"homebrew") brew install "$@" ;;
*) unknown_pm ;;
esac
}
xpm_remove() {
case $pm in
"apt") sudo apt purge "$@" ;;
"zypper") sudo zypper remove -u "$@" ;;
"xbps") sudo xbps-remove -R "$@" ;;
"homebrew") brew uninstall "$@" ;;
*) unknown_pm ;;
esac
}
xpm_search() {
case $pm in
"apt") apt search "$@" ;;
"zypper") zypper search "$@" ;;
"xbps") xbps-query -Rs "$@" ;;
"homebrew") brew search "$@" ;;
*) unknown_pm ;;
esac
}
xpm_query() {
case $pm in
"apt") apt show "$@" ;;
"zypper") zypper info "$@" ;;
"xbps") xbps-query -RS "$@" ;;
"homebrew") brew info "$@" ;;
*) unknown_pm ;;
esac
}
xpm_list() {
case $pm in
"apt") apt list --installed "$@" ;;
"zypper") zypper search --installed-only "$@" ;;
"xbps") xbps-query -S "$@" ;;
"homebrew") brew list "$@" ;;
*) unknown_pm ;;
esac
}
xpm_update() {
case $pm in
"apt") sudo apt update && sudo apt upgrade ;;
"zypper") sudo zypper refresh && sudo zypper update ;;
"xbps") sudo xbps-install -Suv ;;
"homebrew") brew update && brew upgrade ;;
*) unknown_pm ;;
esac
}
# main
identify_pm
cmd="$1";
if [ "$cmd" != "" ]; then shift; fi
case "$cmd" in
"i"|"in"|"install")
xpm_install "$@"
exec_hooks install
;;
"r"|"rm"|"remove")
xpm_remove "$@"
exec_hooks remove
;;
"s"|"se"|"search")
xpm_search "$@"
exec_hooks search
;;
"q"|"qry"|"query")
xpm_query "$@"
exec_hooks query
;;
"l"|"ls"|"list")
xpm_list "$@"
exec_hooks list
;;
"u"|"up"|"update")
xpm_update
exec_hooks update
;;
*)
usage
exit
esac