Skip to content

Commit 70a583f

Browse files
change(properties.sh): move TERMUX_REGEX__* variables before setting any Termux variables in case validation is required while variables are being set
1 parent 6767a9c commit 70a583f

File tree

1 file changed

+154
-154
lines changed

1 file changed

+154
-154
lines changed

scripts/properties.sh

Lines changed: 154 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,160 @@ __termux_build_props__add_variables_validator_actions() {
110110

111111

112112

113+
####
114+
# Variables for validating Termux variables.
115+
####
116+
117+
##
118+
# Regex that matches an absolute path that starts with a `/` with at
119+
# least one characters under rootfs `/`. Duplicate or trailing path
120+
# separators `/` are not allowed.
121+
##
122+
TERMUX_REGEX__ABSOLUTE_PATH='^(/[^/]+)+$'
123+
124+
##
125+
# Regex that matches a relative path that does not start with a `/`.
126+
# Duplicate or trailing path separators `/` are not allowed.
127+
##
128+
TERMUX_REGEX__RELATIVE_PATH='^[^/]+(/[^/]+)*$'
129+
130+
##
131+
# Regex that matches (rootfs `/`) or (an absolute path that starts
132+
# with a `/`). Duplicate or trailing path separators `/` are not
133+
# allowed.
134+
##
135+
TERMUX_REGEX__ROOTFS_OR_ABSOLUTE_PATH='^((/)|((/[^/]+)+))$'
136+
137+
138+
##
139+
# Regex that matches a safe absolute path that starts with a `/` with
140+
# at least one characters under rootfs `/`. Duplicate or trailing path
141+
# separators `/` are not allowed. The path component characters must
142+
# be in the range `[a-zA-Z0-9+,.=_-]`.
143+
#
144+
# The path must also be validated against
145+
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
146+
##
147+
TERMUX_REGEX__SAFE_ABSOLUTE_PATH='^(/[a-zA-Z0-9+,.=_-]+)+$'
148+
149+
##
150+
# Regex that matches a safe relative path that does not start with a
151+
# `/`. Duplicate or trailing path separators `/` are not allowed. The
152+
# path component characters must be in the range `[a-zA-Z0-9+,.=_-]`.
153+
#
154+
# The path must also be validated against
155+
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
156+
##
157+
TERMUX_REGEX__SAFE_RELATIVE_PATH='^[a-zA-Z0-9+,.=_-]+(/[a-zA-Z0-9+,.=_-]+)*$'
158+
159+
##
160+
# Regex that matches (rootfs `/`) or (a safe absolute path that starts
161+
# with a `/`). Duplicate or trailing path separators `/` are not
162+
# allowed. The path component characters must be in the range
163+
# `[a-zA-Z0-9+,.=_-]`.
164+
#
165+
# The path must also be validated against
166+
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
167+
##
168+
TERMUX_REGEX__SAFE_ROOTFS_OR_ABSOLUTE_PATH='^((/)|((/[a-zA-Z0-9+,.=_-]+)+))$'
169+
170+
171+
##
172+
# Regex that matches a path containing single `/./` or double `/../` dot components.
173+
##
174+
TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH='((^\./)|(^\.\./)|(/\.$)|(/\.\.$)|(/\./)|(/\.\./))'
175+
176+
177+
##
178+
# Regex that matches invalid Termux rootfs paths.
179+
#
180+
# The Termux rootfs or prefix paths must not be equal to or be under
181+
# specific Filesystem Hierarchy Standard paths or paths used by Termux
182+
# docker image/host OS for its own files, as Termux packages files
183+
# must be kept separate from the build host. The Termux app data/prefix
184+
# directories are also wiped by `clean.sh` when not running on-device,
185+
# which wouldn't be possible if Termux and host directories are shared.
186+
#
187+
# The invalid paths list does not include the `/data` and `/mnt/expand`
188+
# paths under which private app data directories are assigned to
189+
# Android apps, or the `/data/local/tmp` directory assigned to `adb`
190+
# `shell` user, or the `/system` directory for the Android system.
191+
#
192+
# - https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html
193+
# - https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
194+
# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-private-app-data-directory
195+
##
196+
TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS='^((/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/home)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr)|(/usr/local)|(((/usr/)|(/usr/local/))((bin)|(games)|(include)|(lib)|(libexec)|(lib[^/]+)|(sbin)|(share)|(src)|(X11R6))(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
197+
198+
##
199+
# Regex that matches invalid Termux home paths.
200+
#
201+
# Same reasoning as `TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS`,
202+
# and invalid paths are the same as well except that `/home` is
203+
# allowed, and `/` and all paths under `/usr` are not allowed.
204+
#
205+
# `/home` is allowed as package data files are not packaged from there.
206+
##
207+
TERMUX_REGEX__INVALID_TERMUX_HOME_PATHS='^((/)|(/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
208+
209+
##
210+
# Regex that matches invalid Termux prefix paths.
211+
#
212+
# Same reasoning as `TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS`,
213+
# and invalid paths are the same as well except that `/` is not
214+
# allowed.
215+
##
216+
TERMUX_REGEX__INVALID_TERMUX_PREFIX_PATHS='^((/)|(/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/home)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr)|(/usr/local)|(((/usr/)|(/usr/local/))((bin)|(games)|(include)|(lib)|(libexec)|(lib[^/]+)|(sbin)|(share)|(src)|(X11R6))(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
217+
218+
219+
##
220+
# Regex that matches an unsigned integer `>= 0`.
221+
##
222+
TERMUX_REGEX__UNSIGNED_INT='^[0-9]+$'
223+
224+
225+
##
226+
# Regex to match an android app package name.
227+
#
228+
# The package name must have at least two segments separated by a dot
229+
# `.`, where each segment must start with at least one character in
230+
# the range `[a-zA-Z]`, followed by zero or more characters in the
231+
# range `[a-zA-Z0-9_]`. The package name length must also be
232+
# `<= 255` (`NAME_MAX` for ext4 partitions). The length is not checked
233+
# by this regex and it must be checked with `TERMUX__NAME_MAX`, as
234+
# `bash` `=~` regex conditional does not support lookaround.
235+
#
236+
# Unlike Android, the Termux app package name max length is not `255`
237+
# as its limited by `TERMUX__APPS_DIR___MAX_LEN` and `TERMUX__ROOTFS_DIR___MAX_LEN`.
238+
#
239+
# - https://developer.android.com/build/configure-app-module#set-application-id
240+
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/parsing/ApkLiteParseUtils.java;l=669-677
241+
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java;l=63-103
242+
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/os/FileUtils.java;l=954-994
243+
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/PackageManager.java;l=2147-2155
244+
##
245+
TERMUX_REGEX__APP_PACKAGE_NAME="^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$"
246+
247+
##
248+
# Regex to match an android app data path.
249+
#
250+
# The supported formats are:
251+
# - `/data/data/<package_name>` (for primary user `0`) if app is to be
252+
# installed on internal sd.
253+
# - `/data/user/<user_id>/<package_name>` (for all users) if app is to
254+
# be installed on internal sd.
255+
# `/mnt/expand/<volume_uuid>/user/<user_id>/<package_name>` if app is
256+
# to be installed on a removable/portable volume/sd card being used as
257+
# adoptable storage.
258+
#
259+
# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-private-app-data-directory
260+
##
261+
TERMUX_REGEX__APP_DATA_DIR_PATH='^(((/data/data)|(/data/user/[0-9]+)|(/mnt/expand/[^/]+/user/[0-9]+))/[^/]+)$'
262+
263+
264+
265+
266+
113267
###
114268
# Variables for the Termux build tools.
115269
###
@@ -1850,160 +2004,6 @@ TERMUX_AM_APP__AM_CLASS__CLASS_NAME="$TERMUX_AM_APP__NAMESPACE.Am"
18502004

18512005

18522006

1853-
####
1854-
# Variables for validating Termux variables.
1855-
####
1856-
1857-
##
1858-
# Regex that matches an absolute path that starts with a `/` with at
1859-
# least one characters under rootfs `/`. Duplicate or trailing path
1860-
# separators `/` are not allowed.
1861-
##
1862-
TERMUX_REGEX__ABSOLUTE_PATH='^(/[^/]+)+$'
1863-
1864-
##
1865-
# Regex that matches a relative path that does not start with a `/`.
1866-
# Duplicate or trailing path separators `/` are not allowed.
1867-
##
1868-
TERMUX_REGEX__RELATIVE_PATH='^[^/]+(/[^/]+)*$'
1869-
1870-
##
1871-
# Regex that matches (rootfs `/`) or (an absolute path that starts
1872-
# with a `/`). Duplicate or trailing path separators `/` are not
1873-
# allowed.
1874-
##
1875-
TERMUX_REGEX__ROOTFS_OR_ABSOLUTE_PATH='^((/)|((/[^/]+)+))$'
1876-
1877-
1878-
##
1879-
# Regex that matches a safe absolute path that starts with a `/` with
1880-
# at least one characters under rootfs `/`. Duplicate or trailing path
1881-
# separators `/` are not allowed. The path component characters must
1882-
# be in the range `[a-zA-Z0-9+,.=_-]`.
1883-
#
1884-
# The path must also be validated against
1885-
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
1886-
##
1887-
TERMUX_REGEX__SAFE_ABSOLUTE_PATH='^(/[a-zA-Z0-9+,.=_-]+)+$'
1888-
1889-
##
1890-
# Regex that matches a safe relative path that does not start with a
1891-
# `/`. Duplicate or trailing path separators `/` are not allowed. The
1892-
# path component characters must be in the range `[a-zA-Z0-9+,.=_-]`.
1893-
#
1894-
# The path must also be validated against
1895-
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
1896-
##
1897-
TERMUX_REGEX__SAFE_RELATIVE_PATH='^[a-zA-Z0-9+,.=_-]+(/[a-zA-Z0-9+,.=_-]+)*$'
1898-
1899-
##
1900-
# Regex that matches (rootfs `/`) or (a safe absolute path that starts
1901-
# with a `/`). Duplicate or trailing path separators `/` are not
1902-
# allowed. The path component characters must be in the range
1903-
# `[a-zA-Z0-9+,.=_-]`.
1904-
#
1905-
# The path must also be validated against
1906-
# `TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH`.
1907-
##
1908-
TERMUX_REGEX__SAFE_ROOTFS_OR_ABSOLUTE_PATH='^((/)|((/[a-zA-Z0-9+,.=_-]+)+))$'
1909-
1910-
1911-
##
1912-
# Regex that matches a path containing single `/./` or double `/../` dot components.
1913-
##
1914-
TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH='((^\./)|(^\.\./)|(/\.$)|(/\.\.$)|(/\./)|(/\.\./))'
1915-
1916-
1917-
##
1918-
# Regex that matches invalid Termux rootfs paths.
1919-
#
1920-
# The Termux rootfs or prefix paths must not be equal to or be under
1921-
# specific Filesystem Hierarchy Standard paths or paths used by Termux
1922-
# docker image/host OS for its own files, as Termux packages files
1923-
# must be kept separate from the build host. The Termux app data/prefix
1924-
# directories are also wiped by `clean.sh` when not running on-device,
1925-
# which wouldn't be possible if Termux and host directories are shared.
1926-
#
1927-
# The invalid paths list does not include the `/data` and `/mnt/expand`
1928-
# paths under which private app data directories are assigned to
1929-
# Android apps, or the `/data/local/tmp` directory assigned to `adb`
1930-
# `shell` user, or the `/system` directory for the Android system.
1931-
#
1932-
# - https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html
1933-
# - https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
1934-
# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-private-app-data-directory
1935-
##
1936-
TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS='^((/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/home)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr)|(/usr/local)|(((/usr/)|(/usr/local/))((bin)|(games)|(include)|(lib)|(libexec)|(lib[^/]+)|(sbin)|(share)|(src)|(X11R6))(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
1937-
1938-
##
1939-
# Regex that matches invalid Termux home paths.
1940-
#
1941-
# Same reasoning as `TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS`,
1942-
# and invalid paths are the same as well except that `/home` is
1943-
# allowed, and `/` and all paths under `/usr` are not allowed.
1944-
#
1945-
# `/home` is allowed as package data files are not packaged from there.
1946-
##
1947-
TERMUX_REGEX__INVALID_TERMUX_HOME_PATHS='^((/)|(/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
1948-
1949-
##
1950-
# Regex that matches invalid Termux prefix paths.
1951-
#
1952-
# Same reasoning as `TERMUX_REGEX__INVALID_TERMUX_ROOTFS_PATHS`,
1953-
# and invalid paths are the same as well except that `/` is not
1954-
# allowed.
1955-
##
1956-
TERMUX_REGEX__INVALID_TERMUX_PREFIX_PATHS='^((/)|(/bin(/.*)?)|(/boot(/.*)?)|(/dev(/.*)?)|(/etc(/.*)?)|(/home)|(/lib(/.*)?)|(/lib[^/]+(/.*)?)|(/media)|(/mnt)|(/opt)|(/proc(/.*)?)|(/root)|(/run(/.*)?)|(/sbin(/.*)?)|(/srv(/.*)?)|(/sys(/.*)?)|(/tmp(/.*)?)|(/usr)|(/usr/local)|(((/usr/)|(/usr/local/))((bin)|(games)|(include)|(lib)|(libexec)|(lib[^/]+)|(sbin)|(share)|(src)|(X11R6))(/.*)?)|(/var(/.*)?)|(/bin.usr-is-merged)|(/lib.usr-is-merged)|(/sbin.usr-is-merged)|(/.dockerinit)|(/.dockerenv))$'
1957-
1958-
1959-
##
1960-
# Regex that matches an unsigned integer `>= 0`.
1961-
##
1962-
TERMUX_REGEX__UNSIGNED_INT='^[0-9]+$'
1963-
1964-
1965-
##
1966-
# Regex to match an android app package name.
1967-
#
1968-
# The package name must have at least two segments separated by a dot
1969-
# `.`, where each segment must start with at least one character in
1970-
# the range `[a-zA-Z]`, followed by zero or more characters in the
1971-
# range `[a-zA-Z0-9_]`. The package name length must also be
1972-
# `<= 255` (`NAME_MAX` for ext4 partitions). The length is not checked
1973-
# by this regex and it must be checked with `TERMUX__NAME_MAX`, as
1974-
# `bash` `=~` regex conditional does not support lookaround.
1975-
#
1976-
# Unlike Android, the Termux app package name max length is not `255`
1977-
# as its limited by `TERMUX__APPS_DIR___MAX_LEN` and `TERMUX__ROOTFS_DIR___MAX_LEN`.
1978-
#
1979-
# - https://developer.android.com/build/configure-app-module#set-application-id
1980-
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/parsing/ApkLiteParseUtils.java;l=669-677
1981-
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java;l=63-103
1982-
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/os/FileUtils.java;l=954-994
1983-
# - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/pm/PackageManager.java;l=2147-2155
1984-
##
1985-
TERMUX_REGEX__APP_PACKAGE_NAME="^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$"
1986-
1987-
##
1988-
# Regex to match an android app data path.
1989-
#
1990-
# The supported formats are:
1991-
# - `/data/data/<package_name>` (for primary user `0`) if app is to be
1992-
# installed on internal sd.
1993-
# - `/data/user/<user_id>/<package_name>` (for all users) if app is to
1994-
# be installed on internal sd.
1995-
# `/mnt/expand/<volume_uuid>/user/<user_id>/<package_name>` if app is
1996-
# to be installed on a removable/portable volume/sd card being used as
1997-
# adoptable storage.
1998-
#
1999-
# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-private-app-data-directory
2000-
##
2001-
TERMUX_REGEX__APP_DATA_DIR_PATH='^(((/data/data)|(/data/user/[0-9]+)|(/mnt/expand/[^/]+/user/[0-9]+))/[^/]+)$'
2002-
2003-
2004-
2005-
2006-
20072007
###
20082008
# Variables for the Termux package repositories.
20092009
###

0 commit comments

Comments
 (0)