From e384398b4d0bd447d7121f971e1209b5d96dd926 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 13:35:42 +0500 Subject: [PATCH 1/6] mirrors: remove mirror files and entries from Makefile for mirrors removed in 138bb91d Previously only variables being set in mirror files were removed without removing the actual files. That resulted in following errors when `pkg` was run as required variables weren't being set. ``` /data/data/com.termux/files/usr/bin/pkg: line 106: MAIN: unbound variable /data/data/com.termux/files/usr/bin/pkg: line 111: WEIGHT: unbound variable ``` --- mirrors/Makefile.am | 11 +++++------ mirrors/china/mirrors.dgut.edu.cn | 0 mirrors/china/mirrors.hit.edu.cn | 0 mirrors/china/mirrors.njupt.edu.cn | 0 mirrors/china/mirrors.scau.edu.cn | 0 5 files changed, 5 insertions(+), 6 deletions(-) delete mode 100644 mirrors/china/mirrors.dgut.edu.cn delete mode 100644 mirrors/china/mirrors.hit.edu.cn delete mode 100644 mirrors/china/mirrors.njupt.edu.cn delete mode 100644 mirrors/china/mirrors.scau.edu.cn diff --git a/mirrors/Makefile.am b/mirrors/Makefile.am index c8c6915..d8f6a19 100644 --- a/mirrors/Makefile.am +++ b/mirrors/Makefile.am @@ -8,12 +8,11 @@ mirror.textcord.xyz tmx.xvx.my.id # Mirrors in China pkgdata_CHINA_MIRRORS = mirrors.tuna.tsinghua.edu.cn \ -mirror.iscas.ac.cn mirrors.nju.edu.cn mirrors.pku.edu.cn \ -mirrors.ustc.edu.cn mirrors.hit.edu.cn mirrors.bfsu.edu.cn \ -mirrors.aliyun.com mirrors.cqupt.edu.cn mirrors.dgut.edu.cn \ -mirror.nyist.edu.cn mirrors.njupt.edu.cn mirrors.sau.edu.cn \ -mirrors.scau.edu.cn mirrors.sdu.edu.cn mirrors.sustech.edu.cn \ -mirrors.zju.edu.cn mirror.sjtu.edu.cn mirrors.qvq.net.cn +mirror.iscas.ac.cn mirrors.nju.edu.cn mirrors.pku.edu.cn \ +mirrors.ustc.edu.cn mirrors.bfsu.edu.cn mirrors.aliyun.com \ +mirrors.cqupt.edu.cn mirror.nyist.edu.cn mirrors.sau.edu.cn \ +mirrors.sdu.edu.cn mirrors.sustech.edu.cn mirrors.zju.edu.cn \ +mirror.sjtu.edu.cn mirrors.qvq.net.cn # Mirrors in Europe pkgdata_EUROPE_MIRRORS = grimler.se mirror.termux.dev \ diff --git a/mirrors/china/mirrors.dgut.edu.cn b/mirrors/china/mirrors.dgut.edu.cn deleted file mode 100644 index e69de29..0000000 diff --git a/mirrors/china/mirrors.hit.edu.cn b/mirrors/china/mirrors.hit.edu.cn deleted file mode 100644 index e69de29..0000000 diff --git a/mirrors/china/mirrors.njupt.edu.cn b/mirrors/china/mirrors.njupt.edu.cn deleted file mode 100644 index e69de29..0000000 diff --git a/mirrors/china/mirrors.scau.edu.cn b/mirrors/china/mirrors.scau.edu.cn deleted file mode 100644 index e69de29..0000000 From 834b690f86d8a44ac6c0325a735437931bd5a5cf Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 13:38:24 +0500 Subject: [PATCH 2/6] mirrors: set mirrors list max line length at 70 characters and use only spaces instead of mix of tabs and spaces --- mirrors/Makefile.am | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mirrors/Makefile.am b/mirrors/Makefile.am index d8f6a19..608baef 100644 --- a/mirrors/Makefile.am +++ b/mirrors/Makefile.am @@ -2,12 +2,12 @@ pkgdata_MIRRORS = default # Mirrors in Asia (excl. China and Russia) -pkgdata_ASIA_MIRRORS = mirror.albony.xyz mirror.bardia.tech \ -mirrors.cbrx.io linux.domainesia.com mirror.nevacloud.com \ +pkgdata_ASIA_MIRRORS = mirror.albony.xyz mirror.bardia.tech \ +mirrors.cbrx.io linux.domainesia.com mirror.nevacloud.com \ mirror.textcord.xyz tmx.xvx.my.id # Mirrors in China -pkgdata_CHINA_MIRRORS = mirrors.tuna.tsinghua.edu.cn \ +pkgdata_CHINA_MIRRORS = mirrors.tuna.tsinghua.edu.cn \ mirror.iscas.ac.cn mirrors.nju.edu.cn mirrors.pku.edu.cn \ mirrors.ustc.edu.cn mirrors.bfsu.edu.cn mirrors.aliyun.com \ mirrors.cqupt.edu.cn mirror.nyist.edu.cn mirrors.sau.edu.cn \ @@ -15,18 +15,18 @@ mirrors.sdu.edu.cn mirrors.sustech.edu.cn mirrors.zju.edu.cn \ mirror.sjtu.edu.cn mirrors.qvq.net.cn # Mirrors in Europe -pkgdata_EUROPE_MIRRORS = grimler.se mirror.termux.dev \ -packages.termux.dev termux.librehat.com mirror.mwt.me \ -termux.mentality.rip mirrors.sahilister.in termux.cdn.lumito.net \ -termux.astra.in.ua termux.3san.dev mirror.accum.se \ -md.mirrors.hacktegic.com ftp.fau.de is.mirror.flokinet.net \ -ro.mirror.flokinet.net mirrors.medzik.dev mirrors.cfe.re \ -mirror.sunred.org mirror.autkin.net mirror.bouwhuis.network \ +pkgdata_EUROPE_MIRRORS = grimler.se mirror.termux.dev \ +packages.termux.dev termux.librehat.com mirror.mwt.me \ +termux.mentality.rip mirrors.sahilister.in termux.cdn.lumito.net \ +termux.astra.in.ua termux.3san.dev mirror.accum.se \ +md.mirrors.hacktegic.com ftp.fau.de is.mirror.flokinet.net \ +ro.mirror.flokinet.net mirrors.medzik.dev mirrors.cfe.re \ +mirror.sunred.org mirror.autkin.net mirror.bouwhuis.network \ mirror.leitecastro.com # Mirrors in North America -pkgdata_NORTH_AMERICA_MIRRORS = plug-mirror.rcac.purdue.edu \ -dl.kcubeterm.com mirrors.utermux.dev mirror.fcix.net mirror.mwt.me \ +pkgdata_NORTH_AMERICA_MIRRORS = plug-mirror.rcac.purdue.edu \ +dl.kcubeterm.com mirrors.utermux.dev mirror.fcix.net mirror.mwt.me \ mirror.vern.cc mirror.csclub.uwaterloo.ca mirror.quantum5.ca # Mirrors in Oceania From c3d1b6f7cf44cee166a0b0cd42e7f408c848f0f7 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 17:06:49 +0500 Subject: [PATCH 3/6] build: generate conffiles via Makefile instead of in termux-packages build.sh This changes build order where root directory will be built first before SUBDIRS. https://www.gnu.org/software/automake/manual/html_node/Subdirectories.html --- Makefile.am | 21 +++++++++++++++++++-- mirrors/Makefile.am | 6 ++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 28b4b44..ae2c36f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,14 @@ # along with termux-tools. If not, see # . -SUBDIRS = scripts doc mirrors motds +SUBDIRS = . scripts doc mirrors motds + +CONFFILES = \ +etc/motd \ +etc/motd.sh \ +etc/motd-playstore \ +etc/profile.d/init-termux-properties.sh \ +etc/termux-login.sh do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g" \ -e "s%[@]TERMUX_APP_PACKAGE[@]%${termux_app_package}%g" \ @@ -45,7 +52,17 @@ $(eval $(call sed-rule,init-termux-properties.sh)) $(eval $(call sed-rule,termux-login.sh)) -install-data-local: $(pkgdata_PROFILE) + + +create-deb-control-files: + printf "" > conffiles + for f in $(CONFFILES); do \ + printf "%s\n" "$$f" >> conffiles; \ + done + + + +install-data-local: create-deb-control-files $(pkgdata_PROFILE) $(MKDIR_P) $(DESTDIR)$(datarootdir)/examples/termux for f in $(pkgdata_EXAMPLES); do \ $(INSTALL) -m 644 $(srcdir)/$$f \ diff --git a/mirrors/Makefile.am b/mirrors/Makefile.am index 608baef..1256a92 100644 --- a/mirrors/Makefile.am +++ b/mirrors/Makefile.am @@ -85,6 +85,12 @@ uninstall-default: -rmdir $(DESTDIR)$(sysconfdir)/termux/mirrors install-data-local: install-default install-asia install-china install-europe install-north_america install-oceania install-south_america install-russia +create-deb-control-files: + sh -c "cd $$(dirname $(DESTDIR)$(sysconfdir)); find $$(basename $(DESTDIR)$(sysconfdir))/termux/mirrors -type f" >> ../conffiles; + + + +install-data-local: install-default install-asia install-china install-europe install-north_america install-oceania install-south_america install-russia create-deb-control-files uninstall-local: uninstall-default uninstall-asia uninstall-china uninstall-europe uninstall-north_america uninstall-oceania uninstall-south_america uninstall-russia From 1945fc9d980246e96c4b8379d98bd599718bee53 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 17:27:26 +0500 Subject: [PATCH 4/6] mirrors: fix removed, renamed and moved mirrors not getting deleted during package updates by manually deleting them in preinst step The `uninstall-removed-mirrors` target also deletes the removed mirrors from installation prefix, which wasn't being done before for build infrastructure and old files kept getting packed. --- Makefile.am | 1 + mirrors/Makefile.am | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index ae2c36f..f0f4350 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,6 +59,7 @@ create-deb-control-files: for f in $(CONFFILES); do \ printf "%s\n" "$$f" >> conffiles; \ done + printf "#!%s/bin/bash\n\n" "${termux_prefix}" > preinst diff --git a/mirrors/Makefile.am b/mirrors/Makefile.am index 1256a92..bd5d394 100644 --- a/mirrors/Makefile.am +++ b/mirrors/Makefile.am @@ -38,6 +38,28 @@ pkgdata_SOUTH_AMERICA_MIRRORS = mirrors.rda.run # Mirrors in Russia pkgdata_RUSSIA_MIRRORS = mirror.mephi.ru repository.su + +# Removed, renamed or moved mirrors +# Mirrors files are marked as conffiles and they are manually deleted +# in preinst step of package upgrade as conffiles removed in a newer +# version of the package are only deleted if package is purged and +# would otherwise be left as is after package upgrades and would still +# get used during mirror selection. +pkgdata_MIRRORS_REMOVED = \ +asia/packages.nscdn.top \ +china/mirrors.dgut.edu.cn \ +china/mirrors.hit.edu.cn \ +china/mirrors.njupt.edu.cn \ +china/mirrors.scau.edu.cn \ +europe/cdn.lumito.net \ +europe/mirror.termux.dv \ +europe/termux.sahilister.in \ +north_america/packages.termux.dev \ +oceania/mirrors.wale.id.au \ +russia/mirror.surf + + + define install-mirror-rule install-$1: $$(MKDIR_P) $$(DESTDIR)$$(sysconfdir)/termux/mirrors/$1 @@ -71,6 +93,8 @@ $(eval $(call uninstall-mirror-rule,oceania,OCEANIA)) $(eval $(call uninstall-mirror-rule,south_america,SOUTH_AMERICA)) $(eval $(call uninstall-mirror-rule,russia,RUSSIA)) + + install-default: $(pkgdata_MIRRORS) $(MKDIR_P) $(DESTDIR)$(sysconfdir)/termux/mirrors for f in $(pkgdata_MIRRORS); do \ @@ -84,15 +108,24 @@ uninstall-default: done -rmdir $(DESTDIR)$(sysconfdir)/termux/mirrors -install-data-local: install-default install-asia install-china install-europe install-north_america install-oceania install-south_america install-russia + + +uninstall-removed-mirrors: + for f in $(pkgdata_MIRRORS_REMOVED); do \ + rm -f $(DESTDIR)$(sysconfdir)/termux/mirrors/$$f; \ + done + + + create-deb-control-files: sh -c "cd $$(dirname $(DESTDIR)$(sysconfdir)); find $$(basename $(DESTDIR)$(sysconfdir))/termux/mirrors -type f" >> ../conffiles; + printf "# Delete removed mirrors\nfor f in %s; do\n if test -f \"%s/etc/termux/mirrors/\$$f\"; then\n echo \"Deleting removed mirror: \$$f\"; rm -f \"%s/etc/termux/mirrors/\$$f\";\n fi\ndone" "$(pkgdata_MIRRORS_REMOVED)" "$(termux_prefix)" "$(termux_prefix)" >> ../preinst; -install-data-local: install-default install-asia install-china install-europe install-north_america install-oceania install-south_america install-russia create-deb-control-files +install-data-local: uninstall-removed-mirrors install-default install-asia install-china install-europe install-north_america install-oceania install-south_america install-russia create-deb-control-files -uninstall-local: uninstall-default uninstall-asia uninstall-china uninstall-europe uninstall-north_america uninstall-oceania uninstall-south_america uninstall-russia +uninstall-local: uninstall-removed-mirrors uninstall-default uninstall-asia uninstall-china uninstall-europe uninstall-north_america uninstall-oceania uninstall-south_america uninstall-russia EXTRA_DIST = $(pkgdata_MIRRORS) $(pkgdata_ASIA_MIRRORS) \ $(pkgdata_CHINA_MIRRORS) $(pkgdata_EUROPE_MIRRORS) \ From dbe9dc35254675a5c0f900241df37ca879c7c456 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 18:37:49 +0500 Subject: [PATCH 5/6] pkg: ignore invalid mirror files that do not set the `MAIN`, `X11`, `ROOT` and `WEIGHT` variables to valid values We also unset the 4 variables before sourcing script to ensure the variables were set by the mirror file itself and not already exported before running `pkg` or for potentially a different sourced mirror file. Previously, errors like following would have been generated, like before fixes done in e384398b. ``` /data/data/com.termux/files/usr/bin/pkg: line 106: MAIN: unbound variable /data/data/com.termux/files/usr/bin/pkg: line 111: WEIGHT: unbound variable ``` --- scripts/pkg.in | 71 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/scripts/pkg.in b/scripts/pkg.in index 33c89cd..f789408 100644 --- a/scripts/pkg.in +++ b/scripts/pkg.in @@ -101,18 +101,61 @@ has_repo() { fi } +unset_mirror_variables() { + unset MAIN + unset X11 + unset ROOT + unset WEIGHT +} + get_mirror_url() { - source "$1" - echo $MAIN + local -r _mirror="$1" + local -r _has_repo_x11="$2" + local -r _has_repo_root="$3" + + unset_mirror_variables + source "$_mirror" + + if [[ -z "${MAIN:-}" ]]; then + echo "Warn: Ignoring mirror '$_mirror' without main channel url" >&2 + return 0 + elif [[ ! "${MAIN:-}" =~ ^https?://[^[:space:]]+$ ]]; then + echo "Warn: Ignoring mirror '$_mirror' with invalid main channel url '${MAIN:-}'" >&2 + return 0 + fi + + if [[ "$_has_repo_x11" == "true" ]]; then + if [[ -z "${X11:-}" ]]; then + echo "Warn: Ignoring mirror '$_mirror' without x11 channel url" >&2 + return 0 + elif [[ ! "${X11:-}" =~ ^https?://[^[:space:]]+$ ]]; then + echo "Warn: Ignoring mirror '$_mirror' with invalid x11 channel url '${X11:-}'" >&2 + return 0 + fi + fi + + if [[ "$_has_repo_root" == "true" ]]; then + if [[ -z "${ROOT:-}" ]]; then + echo "Warn: Ignoring mirror '$_mirror' without root channel url" >&2 + return 0 + elif [[ ! "${ROOT:-}" =~ ^https?://[^[:space:]]+$ ]]; then + echo "Warn: Ignoring mirror '$_mirror' with invalid root channel url '${ROOT:-}'" >&2 + return 0 + fi + fi + + if [[ ! "${WEIGHT:-}" =~ ^[0-9]+$ ]]; then + echo "Warn: Ignoring mirror '$_mirror' with invalid weight '${WEIGHT:-}'" >&2 + return 0 + fi + + echo "$MAIN" } get_mirror_weight() { + unset_mirror_variables source "$1" - if [[ ! "$WEIGHT" =~ ^[0-9]+$ ]]; then - echo "Error: Invalid weight in mirror $1" >&2 - exit 1 - fi - echo $WEIGHT + echo "$WEIGHT" } select_mirror() { @@ -178,10 +221,17 @@ select_mirror() { local total_mirrors=${#mirrors[@]} local parallel_jobs_current_count=1 + has_repo_x11="$(has_repo x11)" + has_repo_root="$(has_repo root)" + set +e i=0 for mirror in "${!mirrors[@]}"; do - url="$(get_mirror_url ${mirrors[$mirror]})" + url="$(get_mirror_url "${mirrors[$mirror]}" "$has_repo_x11" "$has_repo_root")" + if [ -z "$url" ]; then + unset "mirrors[$mirror]" + continue + fi job_number=$parallel_jobs_current_count parallel_jobs_current_count=$((parallel_jobs_current_count + 1)) @@ -270,12 +320,13 @@ select_mirror() { if [ -n "$selected_mirror" ]; then ( + unset_mirror_variables source "$selected_mirror" echo "deb $MAIN stable main" > @TERMUX_PREFIX@/etc/apt/sources.list - if [ "$(has_repo x11)" == "true" ]; then + if [[ "$has_repo_x11" == "true" ]]; then echo "deb $X11 x11 main" > @TERMUX_PREFIX@/etc/apt/sources.list.d/x11.list fi - if [ "$(has_repo root)" == "true" ]; then + if [[ "$has_repo_root" == "true" ]]; then echo "deb $ROOT root stable" > @TERMUX_PREFIX@/etc/apt/sources.list.d/root.list fi ) From 3e71c23c6f76064ddd69f98edbbdd77c89d108b8 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 8 Mar 2024 18:38:44 +0500 Subject: [PATCH 6/6] version 1.41.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6023180..64527ef 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ dnl along with termux-tools. If not, see dnl . AC_PREREQ([2.69]) -AC_INIT([termux-tools], [1.40.7], [support@termux.dev]) +AC_INIT([termux-tools], [1.41.0], [support@termux.dev]) AM_INIT_AUTOMAKE([foreign])