From 5c56af98e95d12fd4531cd9197657eace1fe8bc1 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 Jan 2021 10:13:12 +0000 Subject: as_root(): add `sls` to accepted root tools FossilOrigin-Name: ca05dfca6f8529b23647ddac4e9d7d3317c4508ee15045e60a4eac63787a04b7 --- src/cpt-lib.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 2af31fb..73e483c 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -389,7 +389,7 @@ as_root() { "$@" case ${su##*/} in - sudo|doas) "$su" -u "$user" -- env "$@" ;; + sls|sudo|doas) "$su" -u "$user" -- env "$@" ;; su) su -c "env $* <&3" "$user" 3<&0 Date: Sun, 3 Jan 2021 22:00:59 +0000 Subject: _seq(): add function to print numbers sequentially FossilOrigin-Name: e512f7d12e12c16fe109cfdf642361bb46ba594273ecacd93531c0ddfb144a8e --- src/cpt-lib.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 73e483c..5e5e7b4 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -45,6 +45,15 @@ trap_set() { esac } +_seq() ( + # Pure shell counter meant to be used in 'for' loops. + i=0 buf='' + while [ "$(( i += 1 ))" -le "$1" ]; do + buf="$buf $i " + done + printf '%s' "$buf" +) + _stat() ( _user=; eval set -- "$(ls -ld "$1")" id -u "${_user:=$3}" >/dev/null 2>&1 || _user=root -- cgit v1.2.3 From 7f087e4530ba676628301142f330242ff445e6e2 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 Jan 2021 22:07:40 +0000 Subject: sepchar(): add function to seperate characters on given string FossilOrigin-Name: 3c44de3bfd6fbf69658371b2d8cd4d30043dd6f9b568c43ab30291925ebc582e --- src/cpt-lib.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 5e5e7b4..cc4938b 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -45,6 +45,21 @@ trap_set() { esac } +sepchar() ( + # Seperate every character on the given string without resorting to external + # processes. + [ "$1" ] || return 0; str=$1; set -- + while [ "$str" ]; do + str_tmp=$str + for i in $(_seq $(( ${#str} - 1 ))); do + str_tmp=${str_tmp%?} + done + set -- "$@" "$str_tmp" + str=${str#$str_tmp} + done + printf '%s\n' "$@" +) + _seq() ( # Pure shell counter meant to be used in 'for' loops. i=0 buf='' -- cgit v1.2.3 From 757d14f801364bbc071be3e55658b1c237fa10c6 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 Jan 2021 22:22:04 +0000 Subject: pkg_get_base(): add function to print the packages defined in /etc/cpt-base FossilOrigin-Name: f282158e981153846bc1aca83263de583403dd78444435cb139a7f25e6658c4e --- src/cpt-lib.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index cc4938b..b42d0e3 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -1809,6 +1809,19 @@ pkg_updates(){ log "Updated all packages" } +pkg_get_base() ( + # Print the packages defined in the /etc/cpt-base file. + # If an argument is given, it prints a space seperated list instead + # of a list seperated by newlines. + [ -f "$CPT_ROOT/etc/cpt-base" ] || return 1 + nonl=$1; set -- + while read -r pkg _; do + [ "${pkg##\#*}" ] || continue + set -- "$@" "$pkg" + done < "$CPT_ROOT/etc/cpt-base" + if [ "$nonl" ]; then printf '%s ' "$@"; else printf '%s\n' "$@"; fi +) + pkg_clean() { # Clean up on exit or error. This removes everything related # to the build. -- cgit v1.2.3 From 5bed6bb3ce3ea13adead455cbc7b0fc94818860b Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 Jan 2021 22:22:43 +0000 Subject: pkg_gentree(): add function to generate a dependency graph FossilOrigin-Name: e56971ac89f4a4e1c3efd62dad13b3a1c43bc6266c2803600995954cb61ee6cd --- src/cpt-lib.in | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index b42d0e3..770e38d 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -773,16 +773,29 @@ pkg_depends() { (pkg_list "$1" >/dev/null) && return while read -r dep type || [ "$dep" ]; do + # Skip comments and empty lines. + [ "${dep##\#*}" ] || continue # Skip test dependencies unless $CPT_TEST is set to 1. - case $type in test) [ "$CPT_TEST" = 1 ] || continue; esac + # + # Skip make dependencies on the 'tree' operation for child packages + # or when the 'first-nomake' argument is given. + case $type in + test) [ "$CPT_TEST" = 1 ] || continue ;; + make) [ "$2" = tree ] && [ -z "${3#first-nomake}" ] && continue + esac - # Recurse through the dependencies of the child packages. - [ "${dep##\#*}" ] && pkg_depends "$dep" + # Recurse through the dependencies of the child packages. Forward + # the 'tree' operation. + if [ "$2" = tree ]; then + pkg_depends "$dep" tree + else + pkg_depends "$dep" + fi done 2>/dev/null < "$(pkg_find "$1")/depends" ||: # After child dependencies are added to the list, # add the package which depends on them. - [ "$2" = explicit ] || deps="$deps $1 " + [ "$2" = explicit ] || [ "$3" ] || deps="$deps $1 " } } @@ -1822,6 +1835,29 @@ pkg_get_base() ( if [ "$nonl" ]; then printf '%s ' "$@"; else printf '%s\n' "$@"; fi ) +pkg_gentree() ( + # Generate an ordered dependency tree of a package. Useful for testing + # whether the generated dependency tree is enough to actually building a + # given package. A second argument can be given as a combination of + # characters (similar to 'tar(1)' keys) which will be used as an option + # parser. See the documentation for more information on the keys. + deps='' reverse='' nonl='' make_deps=first + for op in $(sepchar "$2"); do + case "$op" in + b) deps="$(pkg_get_base nonl)" ;; + x) make_deps=first-nomake ;; + r) reverse=1 ;; + n) nonl=1 ;; + *) return 1 + esac + done + pkg_depends "$1" tree "${make_deps:+first}" + eval set -- "$deps" + pkg_order "$@" + if [ "$reverse" ]; then eval set -- "$redro"; else eval set -- "$order"; fi + if [ "$nonl" ]; then printf '%s ' "$@"; else printf '%s\n' "$@"; fi +) + pkg_clean() { # Clean up on exit or error. This removes everything related # to the build. -- cgit v1.2.3