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.
Reorganize patches for better understanding and ensure they are applied in
expected order.
Another changes:
* gnupg is now in recommends (used by apt-key).
* x11-repo is now in suggests.
* TCSAFLUSH patch is dropped because it is covered by one of NDK patches
where TCSAFLUSH value is replaced with TCSANOW.
Reorganize patches & do following changes:
* Enable use of sethostname(2) in utility `hostname`.
* Enable setting time in utility `date` - busybox already provide own
implementation of stime(2).
- both features require root.
Some of them will be useful only as root or if SELinux is set to "permissive".
These applets will not be symlinked and callable only with "busybox <applet name>".
Issue https://github.com/termux/termux-packages/issues/3594.
When installing or searching for packages, the `apt update` will run only if it
was not executed within the last 5 minutes. Command `pkg upgrade` will
always execute `apt update` to ensure that latest package versions were
picked during upgrade.