Skip to content

Commit fc0e82f

Browse files
MaxythonGrimler91
authored andcommitted
feat(main/termux-tools): allow usage with pacman
Co-authored-by: Maxython <mixython@gmail.com> Closes: termux/termux-packages#10486
1 parent 903b772 commit fc0e82f

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

scripts/pkg

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#!/bin/bash
22
set -eu
33

4-
USER_AGENT='Termux-PKG/1.0 mirror-checker (termux-tools @PACKAGE_VERSION@) Termux (@TERMUX_APP_PACKAGE@; install-prefix:@TERMUX_PREFIX@)'
4+
declare -A commands_pkg=(
5+
["debian"]="dpkg -L|apt show|select_mirror; update_apt_cache; apt install|apt autoclean|apt clean|apt list|apt list --installed|apt install --reinstall|select_mirror; update_apt_cache; apt search|apt remove|select_mirror; apt update; apt full-upgrade"
6+
["pacman"]="pacman -Ql|pacman -Qi|pacman -Sy --needed|pacman -Sc|pacman -Scc|pacman -Sl|pacman -Q|pacman -S|pacman -Sys|pacman -Rcns|pacman -Syu"
7+
)
58

69
show_help() {
710
local cache_size
8-
cache_size=$(du -sh @TERMUX_CACHE_DIR@/apt/archives 2>/dev/null | cut -f1)
11+
local cache_dir=""
12+
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" ]; then
13+
cache_dir="@TERMUX_CACHE_DIR@/apt/archives"
14+
elif [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then
15+
cache_dir="@TERMUX_PREFIX@/var/cache/pacman/pkg"
16+
fi
17+
cache_size=$(du -sh "$cache_dir" 2>/dev/null | cut -f1)
918

1019
echo 'Usage: pkg command [arguments]'
1120
echo
@@ -51,7 +60,7 @@ check_mirror() {
5160
--fail \
5261
--connect-timeout "$timeout" \
5362
--location \
54-
--user-agent "$USER_AGENT" \
63+
--user-agent "Termux-PKG/1.0 mirror-checker (termux-tools @PACKAGE_VERSION@) Termux (@TERMUX_APP_PACKAGE@; install-prefix:@TERMUX_PREFIX@)" \
5564
"$mirror/dists/stable/Release" >/dev/null 2>&1
5665
}
5766

@@ -185,33 +194,26 @@ if [ $# = 0 ]; then
185194
show_help
186195
fi
187196

197+
case "$TERMUX_MAIN_PACKAGE_FORMAT" in
198+
debian|pacman) IFS="|" pkg_cmd=(${commands_pkg["$TERMUX_MAIN_PACKAGE_FORMAT"]});;
199+
*) echo "Error: pkg is not supported with '$TERMUX_MAIN_PACKAGE_FORMAT' package manager format"; exit 1;;
200+
esac
201+
188202
CMD="$1"
189203
shift 1
190204

191205
case "$CMD" in
192-
f*) dpkg -L "$@";;
206+
f*) eval ${pkg_cmd[0]} "$@";;
193207
h*) show_help;;
194-
sh*|inf*) apt show "$@";;
195-
add|i*)
196-
select_mirror
197-
update_apt_cache
198-
apt install "$@"
199-
;;
200-
autoc*) apt autoclean;;
201-
cl*) apt clean;;
202-
list-a*) apt list "$@";;
203-
list-i*) apt list --installed "$@";;
204-
rei*) apt install --reinstall "$@";;
205-
se*)
206-
select_mirror
207-
update_apt_cache
208-
apt search "$@"
209-
;;
210-
un*|rem*|rm|del*) apt remove "$@";;
211-
up*)
212-
select_mirror
213-
apt update
214-
apt full-upgrade "$@"
215-
;;
208+
sh*|inf*) eval ${pkg_cmd[1]} "$@";;
209+
add|i*) eval ${pkg_cmd[2]} "$@";;
210+
autoc*) eval ${pkg_cmd[3]};;
211+
cl*) eval ${pkg_cmd[4]};;
212+
list-a*) eval ${pkg_cmd[5]} "$@";;
213+
list-i*) eval ${pkg_cmd[6]} "$@";;
214+
rei*) eval ${pkg_cmd[7]} "$@";;
215+
se*) eval ${pkg_cmd[8]} "$@";;
216+
un*|rem*|rm|del*) eval ${pkg_cmd[9]} "$@";;
217+
up*) eval ${pkg_cmd[10]} "$@";;
216218
*) echo "Unknown command: '$CMD' (run 'pkg help' for usage information)"; exit 1;;
217219
esac

0 commit comments

Comments
 (0)