dc14c12940
Usage of package manager as root has certain bad effects in Termux such as messed up SELinux contexts and ownership. Root checks done in 'pkg' wrapper are not reliable because one can execute 'apt' directly or with third-party script downloaded from the Internet. This commit adds user id check and if it found that uid is 0, apt will refuse to do any work in root session. These checks done in such way so they cannot be bypassed in any way unless command is executed as non-root user. Those who use Termux via ADB root shell should be able to switch to Termux user id with command 'su' in order to have package manager working. --- This change also affects the 'termux-info' utility: * It will no longer use 'apt policy' to detect subscribed repositories. Each source will be checked by script manually. * Information will be copied to clipboard only if 'termux-api' is installed. * Syntax error in timeout command is fixed: 'timeout' doesn't understand the argument '-t'. * Minor information entries reordering.
47 lines
981 B
Bash
Executable File
47 lines
981 B
Bash
Executable File
#!/bin/sh
|
|
set -e -u
|
|
|
|
show_help() {
|
|
echo 'Usage: pkg command [arguments]'
|
|
echo ''
|
|
echo 'A tool for managing packages. Commands:'
|
|
echo ''
|
|
echo ' files <packages>'
|
|
echo ' install <packages>'
|
|
echo ' list-all'
|
|
echo ' list-installed'
|
|
echo ' reinstall <packages>'
|
|
echo ' search <query>'
|
|
echo ' show <packages>'
|
|
echo ' uninstall <packages>'
|
|
echo ' upgrade'
|
|
exit 1
|
|
}
|
|
|
|
check_pkgcache() {
|
|
if [ -z "$(find @TERMUX_PREFIX@/var/cache/apt/pkgcache.bin -mmin -5)" ]; then
|
|
apt update
|
|
fi
|
|
}
|
|
|
|
if [ $# = 0 ]; then
|
|
show_help
|
|
fi
|
|
|
|
CMD="$1"
|
|
shift 1
|
|
|
|
case "$CMD" in
|
|
f*) dpkg -L "$@";;
|
|
h*) show_help;;
|
|
add|i*) check_pkgcache; apt install "$@";;
|
|
list-a*) apt list "$@";;
|
|
list-i*) apt list --installed "$@";;
|
|
rei*) apt install --reinstall "$@";;
|
|
se*) check_pkgcache; apt search "$@";;
|
|
sh*) apt show "$@";;
|
|
un*|rem*|rm|del*) apt remove "$@";;
|
|
up*) apt update; apt full-upgrade "$@";;
|
|
*) echo "Unknown command: '$CMD' (run 'pkg help' for usage information)"; exit 1;;
|
|
esac
|