From 712eea99e9ee1f542ec27147e175b2520a71250d Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 21:50:07 +0000 Subject: cpt-list: add flag to make the operation quiet FossilOrigin-Name: f3ae20b2f810fa30dcea616faf392240300529f76779bb2dde07a417bda722bc --- src/cpt-list | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpt-list b/src/cpt-list index 4eb7cf6..77a9071 100755 --- a/src/cpt-list +++ b/src/cpt-list @@ -7,6 +7,7 @@ parser_definition() { "or: ${0##*/} -C pkg true-statement false-statement" msg -- '' 'Options:' flag CURRENT -c --current -- "Use the current directory as a package" + flag quiet -q -- "Make the operation quiet" param PKG -C --check label:" -C,--check PKG TRUE FALSE" -- \ "Check if PKG exists and return the string of TRUE if"\ "it exists, and the string of FALSE if it doesn't." \ @@ -23,7 +24,7 @@ if [ "$PKG" ]; then printf %s "$2" fi else -[ "$CURRENT" ] && set -- "${PWD##*/}" - -pkg_list "$@" + [ "$CURRENT" ] && set -- "${PWD##*/}" + [ "$quiet" ] && exec >/dev/null 2>&1 + pkg_list "$@" fi -- cgit v1.2.3 From 33856aceb8ecc4b0c24cf5ad2bd1796f08cce45e Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 21:50:47 +0000 Subject: cpt-list: update usage string FossilOrigin-Name: bf170e5e57810fd73e0d080f5aa60ac9fee5b2a083f22fed454b0283c0bc418f --- src/cpt-list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpt-list b/src/cpt-list index 77a9071..7cef79e 100755 --- a/src/cpt-list +++ b/src/cpt-list @@ -3,7 +3,7 @@ parser_definition() { setup REST help:usage -- \ - "usage: ${0##*/} [-c] pkg..." \ + "usage: ${0##*/} [-cq] pkg..." \ "or: ${0##*/} -C pkg true-statement false-statement" msg -- '' 'Options:' flag CURRENT -c --current -- "Use the current directory as a package" -- cgit v1.2.3 From 2d25afbdcb9d399f8bf24b7591b63aec2e457b68 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 21:51:24 +0000 Subject: cpt-list: add --quiet long option FossilOrigin-Name: bb65f6b97a58453a3e1831d925957c66fdae17f57f703e03679a083615ce25a7 --- src/cpt-list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpt-list b/src/cpt-list index 7cef79e..fcb1f49 100755 --- a/src/cpt-list +++ b/src/cpt-list @@ -7,7 +7,7 @@ parser_definition() { "or: ${0##*/} -C pkg true-statement false-statement" msg -- '' 'Options:' flag CURRENT -c --current -- "Use the current directory as a package" - flag quiet -q -- "Make the operation quiet" + flag quiet -q --quiet -- "Make the operation quiet" param PKG -C --check label:" -C,--check PKG TRUE FALSE" -- \ "Check if PKG exists and return the string of TRUE if"\ "it exists, and the string of FALSE if it doesn't." \ -- cgit v1.2.3 From 3d09fea9629b478cb50f799a2e9f27e9f5a8a52f Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 21:53:13 +0000 Subject: docs: update FossilOrigin-Name: 9d1edf74007926567f5dd6f9484ac36b6a75ffe2f17cbddb6a13128cfd343a11 --- man/cpt-list.1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/man/cpt-list.1 b/man/cpt-list.1 index 292ba13..778a57d 100644 --- a/man/cpt-list.1 +++ b/man/cpt-list.1 @@ -5,7 +5,7 @@ .Nd list packages .Sh SYNOPSIS .Nm -.Op Fl c +.Op Fl cq .Ar pkg... .Nm .Fl C @@ -20,7 +20,7 @@ list the given packages. If any of the given packages are not installed on the system, .Nm will exit with an error. However, -.Fl c +.Fl C and .Fl -check flags can be used in order to change the behaviour of the utility: @@ -28,6 +28,8 @@ flags can be used in order to change the behaviour of the utility: .It Fl c , -current Assumes that the current directory is a package and will use it instead of arguments. +.It Fl q , -quiet +Make the operation quiet, only reporting exit status. .It Fl C , -check Ar package true_statement false_statement Checks whether the .Em package -- cgit v1.2.3 From 13056c4341239128a9423f50090dd78259b6c23c Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 22:29:25 +0000 Subject: silence the package manager a bit FossilOrigin-Name: 0a695c5090671468ce8ddcf2f1138d3c510f8ad1b689dc3f19a3e39d8d30dc38 --- src/cpt-lib.in | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index ea00bb9..a2466af 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -30,6 +30,29 @@ log() { "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2 } +warn() { + # Print a warning message + log "$1" "$2" "${3:-WARNING}" +} + +outv() { + # Call `out()` when CPT_VERBOSE is set. + [ "$CPT_VERBOSE" -eq 1 ] || return 0 + out "$@" +} + +logv() { + # Call `log()` when CPT_VERBOSE is set. + [ "$CPT_VERBOSE" -eq 1 ] || return 0 + log "$@" +} + +warnv() { + # Call `warn()` when CPT_VERBOSE is set. + [ "$CPT_VERBOSE" -eq 1 ] || return 0 + warn "$@" +} + die() { # Print a message and exit with '1' (error). log "$1" "$2" "!>" @@ -383,11 +406,6 @@ global_options() { disp :version -v --version -- "Print version information" } -warn() { - # Print a warning message - log "$1" "$2" "${3:-WARNING}" -} - contains() { # Check if a "string list" contains a word. case " $1 " in *" $2 "*) return 0; esac; return 1 @@ -472,7 +490,11 @@ run_hook() { [ -f "$CPT_HOOK" ] || { CPT_HOOK=$oldCPT_HOOK; return 0 ;} - [ "$2" ] && log "$2" "Running $1 hook" + if [ "$2" ]; then + logv "$2" "Running $1 hook" + else + logv "Running $1 hook" + fi TYPE=${1:-null} PKG=${2:-null} DEST=${3:-null} . "$CPT_HOOK" CPT_HOOK=$oldCPT_HOOK @@ -534,7 +556,7 @@ pkg_lint() { repo_dir=$(pkg_find "$1") cd "$repo_dir" || die "'$repo_dir' not accessible" - [ -f sources ] || warn "$1" "Sources file not found" + [ -f sources ] || warnv "$1" "Sources file not found" [ -x build ] || die "$1" "Build file not found or not executable" [ -s version ] || die "$1" "Version file not found or empty" @@ -1386,17 +1408,17 @@ pkg_etc() { sum_sys=$(cd "$CPT_ROOT/"; sh256 "$file") sum_old=$("$grep" "$file$" "$mak_dir/c"); } 2>/dev/null ||: - log "$pkg_name" "Doing 3-way handshake for $file" - printf '%s\n' "Previous: ${sum_old:-null}" - printf '%s\n' "System: ${sum_sys:-null}" - printf '%s\n' "New: ${sum_new:-null}" + logv "$pkg_name" "Doing 3-way handshake for $file" + outv "Previous: ${sum_old:-null}" + outv "System: ${sum_sys:-null}" + outv "New: ${sum_new:-null}" # Use a case statement to easily compare three strings at # the same time. Pretty nifty. case ${sum_old:-null}${sum_sys:-null}${sum_new} in # old = Y, sys = X, new = Y "${sum_new}${sum_sys}${sum_old}") - log "Skipping $file" + logv "Skipping $file" continue ;; @@ -1406,7 +1428,7 @@ pkg_etc() { "${sum_old}${sum_old}${sum_old}"|\ "${sum_old:-null}${sum_sys}${sum_sys}"|\ "${sum_sys}${sum_old}"*) - log "Installing $file" + logv "Installing $file" new= ;; -- cgit v1.2.3 From f2acffb9bd6d4d5dcf4b8f1e5088c1923c439765 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 22:31:14 +0000 Subject: document CPT_VERBOSE FossilOrigin-Name: 1436c1a075f6e9a350826f6f3f0696dc492a926d3065559ec60fc4f596823fa1 --- docs/cpt.org | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/cpt.org b/docs/cpt.org index d78254c..3cc2198 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -161,65 +161,84 @@ to provide detailed information. #+VINDEX: CPT_PATH Set the locations of your repositories. It is similar to the ~PATH~ variable. + - ~CPT_CACHE~ :: #+VINDEX: CPT_CACHE The cache directory for =cpt=. Default: ~$XDG_CACHE_HOME/cpt~. + - ~CPT_CHOICE~ :: #+VINDEX: CPT_CHOICE If this is set to 0, a package installation will be aborted on conflicts. + - ~CPT_COLOR~ :: #+VINDEX: CPT_COLOR If this is set to 1, =cpt= tools will be forced to display coloured output. If set to 0, they will be forced to display them without colours. Otherwise, =cpt= will output colour as long as it is outputting to a terminal. + - ~CPT_DEBUG~ :: #+VINDEX: CPT_DEBUG If set to 1, temporary directories will not be removed after the operation. + - ~CPT_FETCH~ :: #+VINDEX: CPT_FETCH If set to 0, ~cpt-update~ will not fetch repositories. + - ~CPT_FORCE~ :: #+VINDEX: CPT_FORCE If set to 1, =cpt= tools will force operation. + - ~CPT_HOOK~ :: #+VINDEX: CPT_HOOK Absolute path to the package manager hook file. + - ~CPT_KEEPLOG~ :: #+VINDEX: CPT_KEEPLOG If set to 1, =cpt= will keep logs regardless of operation success. + - ~CPT_PID~ :: #+VINDEX: CPT_PID Set the temporary build directory name. + - ~CPT_PROMPT~ :: #+VINDEX: CPT_PROMPT If set to 0, =cpt= will not prompt you for anything. + - ~CPT_REPO_CACHE~ :: #+VINDEX: CPT_REPO_CACHE If set to 0, =cpt= will not use or write repository information cache. + - ~CPT_ROOT~ :: #+VINDEX: CPT_ROOT If this variable is set, =cpt= will assume the given path as the system root. + - ~CPT_TEST~ :: #+VINDEX: CPT_TEST If set to 1, ~cpt-build~ will run tests whenever available. + - ~CPT_TMPDIR~ :: #+VINDEX: CPT_TMPDIR The directory to create the temporary directories. +- ~CPT_VERBOSE~ :: + + #+VINDEX: CPT_VERBOSE + If this variable is set to 1, the package manager will print more information. + *** =CPT_PATH= :PROPERTIES: :DESCRIPTION: Set the locations of your repositories -- cgit v1.2.3 From 8e4ef0338bed826f54313fe553231271b4a99618 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 22:35:14 +0000 Subject: add --verbose flag FossilOrigin-Name: 6ded7bb8d323e48fe12e43e9e568cad9588f866b38c08599055bf450c6d2ea9d --- man/cpt-build.1 | 2 ++ man/cpt-install.1 | 2 ++ man/cpt-remove.1 | 2 ++ man/cpt-search.1 | 2 ++ man/cpt-update.1 | 2 ++ src/cpt-lib.in | 1 + 6 files changed, 11 insertions(+) diff --git a/man/cpt-build.1 b/man/cpt-build.1 index 79b24c6..1393aed 100644 --- a/man/cpt-build.1 +++ b/man/cpt-build.1 @@ -33,6 +33,8 @@ Use an alternate root directory Show help message .It Fl v , -version Print version information +.It Fl -verbose +Be more verbose .El .Sh AUTHOR .An Cem Keylan Aq Mt cem@ckyln.com diff --git a/man/cpt-install.1 b/man/cpt-install.1 index 65069f3..235c2df 100644 --- a/man/cpt-install.1 +++ b/man/cpt-install.1 @@ -29,6 +29,8 @@ Use an alternate root directory Show help message .It Fl v , -version Print version information +.It Fl -verbose +Be more verbose .El .Sh AUTHOR .An Cem Keylan Aq Mt cem@ckyln.com diff --git a/man/cpt-remove.1 b/man/cpt-remove.1 index f4bb6fb..e4c2e26 100644 --- a/man/cpt-remove.1 +++ b/man/cpt-remove.1 @@ -27,6 +27,8 @@ Use an alternate root directory Show help message .It Fl v , -version Print version information +.It Fl -verbose +Be more verbose .El .Sh AUTHOR .An Cem Keylan Aq Mt cem@ckyln.com diff --git a/man/cpt-search.1 b/man/cpt-search.1 index 05452bd..f59f7b9 100644 --- a/man/cpt-search.1 +++ b/man/cpt-search.1 @@ -24,6 +24,8 @@ package. Show help message .It Fl v , -version Print version information +.It Fl -verbose +Be more verbose .El .Sh EXAMPLES Below are usage examples for diff --git a/man/cpt-update.1 b/man/cpt-update.1 index 3af1205..bc63ea7 100644 --- a/man/cpt-update.1 +++ b/man/cpt-update.1 @@ -30,6 +30,8 @@ Use an alternate root directory Show help message .It Fl v , -version Print version information +.It Fl -verbose +Be more verbose .El .Sh AUTHOR .An Cem Keylan Aq Mt cem@ckyln.com diff --git a/src/cpt-lib.in b/src/cpt-lib.in index a2466af..1e4062a 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -404,6 +404,7 @@ global_options() { param CPT_ROOT --root init:@export -- "Use an alternate root directory" disp :usage -h --help -- "Show this help message" disp :version -v --version -- "Print version information" + flag CPT_VERBOSE --verbose init:@export -- "Be more verbose" } contains() { -- cgit v1.2.3 From eb9d73e219325ae09b756144d56686118011fb64 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 22:49:29 +0000 Subject: pkg_repository_update: read "MOTD" instead of "motd" FossilOrigin-Name: 65495408d5b97bdbac9317a940991dddec78d737abef168d366b1245e495c33b --- src/cpt-lib.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 1e4062a..4675d19 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -1641,12 +1641,12 @@ pkg_repository_update() { # Repositories can contain a "Message of the Day" file in order to # relay important information to their users. - ! [ -r "$repo_root/motd" ] || { + ! [ -r "$repo_root/MOTD" ] || { printf '%s\n%s\n%s\n\n' \ "$(_multiply_char '=' 60)" \ "Message of the Day [$PWD]" \ "$(_multiply_char '=' 60)" - cat "$repo_root/motd" + cat "$repo_root/MOTD" printf '\n%s\n' "$(_multiply_char '=' 60)" } } -- cgit v1.2.3 From 4d3a7455b536b7bf934561eb5ec187b1653aabb4 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 17 Jul 2021 22:51:10 +0000 Subject: docs: update FossilOrigin-Name: cb5549b4ba93ef506dbfeda10b817536982d92e809762247f81e00e6bc07924c --- docs/cpt.org | 9 +++++---- docs/cpt.texi | 27 +++++++++++++++++++++++---- docs/cpt.txt | 28 +++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/docs/cpt.org b/docs/cpt.org index 3cc2198..aa7c2cc 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -724,10 +724,11 @@ be a huge issue for you. :DESCRIPTION: Communicate with the users using your repository :END: -If a file named =motd= is found on the root directory of the package repository, -its contents will be printed to the standard output when the users are updating -their repositories. This method can be used to communicate messages to the -users, such as package removals or otherwise important information. +If a file named =MOTD= (all uppercase) is found on the root directory of the +package repository, its contents will be printed to the standard output when the +users are updating their repositories. This method can be used to communicate +messages to the users, such as package removals or otherwise important +information. * Comparison Between CPT and KISS diff --git a/docs/cpt.texi b/docs/cpt.texi index 525029c..8b7bb77 100644 --- a/docs/cpt.texi +++ b/docs/cpt.texi @@ -280,50 +280,68 @@ to provide detailed information. @item @code{CPT_PATH} @vindex CPT_PATH Set the locations of your repositories. It is similar to the @code{PATH} variable. + @item @code{CPT_CACHE} @vindex CPT_CACHE The cache directory for @samp{cpt}. Default: @code{$XDG_CACHE_HOME/cpt}. + @item @code{CPT_CHOICE} @vindex CPT_CHOICE If this is set to 0, a package installation will be aborted on conflicts. + @item @code{CPT_COLOR} @vindex CPT_COLOR If this is set to 1, @samp{cpt} tools will be forced to display coloured output. If set to 0, they will be forced to display them without colours. Otherwise, @samp{cpt} will output colour as long as it is outputting to a terminal. + @item @code{CPT_DEBUG} @vindex CPT_DEBUG If set to 1, temporary directories will not be removed after the operation. + @item @code{CPT_FETCH} @vindex CPT_FETCH If set to 0, @code{cpt-update} will not fetch repositories. + @item @code{CPT_FORCE} @vindex CPT_FORCE If set to 1, @samp{cpt} tools will force operation. + @item @code{CPT_HOOK} @vindex CPT_HOOK Absolute path to the package manager hook file. + @item @code{CPT_KEEPLOG} @vindex CPT_KEEPLOG If set to 1, @samp{cpt} will keep logs regardless of operation success. + @item @code{CPT_PID} @vindex CPT_PID Set the temporary build directory name. + @item @code{CPT_PROMPT} @vindex CPT_PROMPT If set to 0, @samp{cpt} will not prompt you for anything. + @item @code{CPT_REPO_CACHE} @vindex CPT_REPO_CACHE If set to 0, @samp{cpt} will not use or write repository information cache. + @item @code{CPT_ROOT} @vindex CPT_ROOT If this variable is set, @samp{cpt} will assume the given path as the system root. + @item @code{CPT_TEST} @vindex CPT_TEST If set to 1, @code{cpt-build} will run tests whenever available. + @item @code{CPT_TMPDIR} @vindex CPT_TMPDIR The directory to create the temporary directories. + +@item @code{CPT_VERBOSE} +@vindex CPT_VERBOSE +If this variable is set to 1, the package manager will print more information. @end table @menu @@ -836,10 +854,11 @@ be a huge issue for you. @node Message of the Day @section Message of the Day -If a file named @samp{motd} is found on the root directory of the package repository, -its contents will be printed to the standard output when the users are updating -their repositories. This method can be used to communicate messages to the -users, such as package removals or otherwise important information. +If a file named @samp{MOTD} (all uppercase) is found on the root directory of the +package repository, its contents will be printed to the standard output when the +users are updating their repositories. This method can be used to communicate +messages to the users, such as package removals or otherwise important +information. @node Comparison Between CPT and KISS @chapter Comparison Between CPT and KISS diff --git a/docs/cpt.txt b/docs/cpt.txt index 144ff8b..78b0e6e 100644 --- a/docs/cpt.txt +++ b/docs/cpt.txt @@ -226,43 +226,61 @@ development manual for *Carbs Packaging Tools*. For development logs see `CPT_PATH' Set the locations of your repositories. It is similar to the `PATH' variable. + `CPT_CACHE' The cache directory for `cpt'. Default: `$XDG_CACHE_HOME/cpt'. + `CPT_CHOICE' If this is set to 0, a package installation will be aborted on conflicts. + `CPT_COLOR' If this is set to 1, `cpt' tools will be forced to display coloured output. If set to 0, they will be forced to display them without colours. Otherwise, `cpt' will output colour as long as it is outputting to a terminal. + `CPT_DEBUG' If set to 1, temporary directories will not be removed after the operation. + `CPT_FETCH' If set to 0, `cpt-update' will not fetch repositories. + `CPT_FORCE' If set to 1, `cpt' tools will force operation. + `CPT_HOOK' Absolute path to the package manager hook file. + `CPT_KEEPLOG' If set to 1, `cpt' will keep logs regardless of operation success. + `CPT_PID' Set the temporary build directory name. + `CPT_PROMPT' If set to 0, `cpt' will not prompt you for anything. + `CPT_REPO_CACHE' If set to 0, `cpt' will not use or write repository information cache. + `CPT_ROOT' If this variable is set, `cpt' will assume the given path as the system root. + `CPT_TEST' If set to 1, `cpt-build' will run tests whenever available. + `CPT_TMPDIR' The directory to create the temporary directories. + `CPT_VERBOSE' + If this variable is set to 1, the package manager will print + more information. + 4.2.1 `CPT_PATH' ---------------- @@ -758,11 +776,11 @@ development manual for *Carbs Packaging Tools*. For development logs see 6.3 Message of the Day ~~~~~~~~~~~~~~~~~~~~~~ - If a file named `motd' is found on the root directory of the package - repository, its contents will be printed to the standard output when - the users are updating their repositories. This method can be used to - communicate messages to the users, such as package removals or - otherwise important information. + If a file named `MOTD' (all uppercase) is found on the root directory + of the package repository, its contents will be printed to the + standard output when the users are updating their repositories. This + method can be used to communicate messages to the users, such as + package removals or otherwise important information. 7 Comparison Between CPT and KISS -- cgit v1.2.3 From f607bcfe57dfd57e62dee4c8564c845e47ad52e4 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 18 Jul 2021 11:14:19 +0000 Subject: fix unit tests FossilOrigin-Name: 113136588471fd5a9c55819056dd6a12d81c17733d585f203cb4955b9a4f90b9 --- spec/01_lib_spec.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/01_lib_spec.sh b/spec/01_lib_spec.sh index 0ff2752..113d517 100644 --- a/spec/01_lib_spec.sh +++ b/spec/01_lib_spec.sh @@ -1,4 +1,5 @@ # shellcheck disable=2091,2034 +CPT_VERBOSE=1 Describe 'CPT Library' export CPT_COLOR=0 @@ -161,7 +162,7 @@ Describe 'CPT Library' End It "doesn't log 'running hook' if no package is given" When call run_hook 2 '' destination - The stderr should eq "" + The stderr should eq "-> Running 2 hook " The output should eq "$CPT_HOOK 2 null destination" End It "uses the /etc/cpt-hook file of the root when called with a fourth arg" -- cgit v1.2.3 From e7b53041d08c088f50121a28fa75ac527a49b3ce Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 19 Jul 2021 12:20:22 +0000 Subject: pkg_query_meta: accept full path as well as package names FossilOrigin-Name: d0203f624858114c808537c5b1ac594d13c32bdd097b463c46a951c1390af75e --- src/cpt-lib.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 4675d19..407fd82 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -2000,8 +2000,11 @@ pkg_gentree() ( pkg_query_meta() { # Query the 'meta' file of the given meta package. If there is no meta file, # or the key being queried is unavailable, the function will return with - # error. - repo_dir=$(pkg_find "$1") + # error. Full path can be specified instead of package names. + case $1 in + */*) repo_dir=$1 ;; + *) repo_dir=$(pkg_find "$1") + esac [ -f "$repo_dir/meta" ] || return while IFS=': ' read -r key val; do case $key in -- cgit v1.2.3 From a8e8638bd7bd009b258691accae462d2ab311462 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 19 Jul 2021 12:20:57 +0000 Subject: outv/logv/warnv: fix tests FossilOrigin-Name: 0865023dcac5e01c69e729a0863e40539cad42b496614d77febf7b17a426458e --- src/cpt-lib.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 407fd82..7e754e8 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -37,19 +37,19 @@ warn() { outv() { # Call `out()` when CPT_VERBOSE is set. - [ "$CPT_VERBOSE" -eq 1 ] || return 0 + [ "$CPT_VERBOSE" = 1 ] || return 0 out "$@" } logv() { # Call `log()` when CPT_VERBOSE is set. - [ "$CPT_VERBOSE" -eq 1 ] || return 0 + [ "$CPT_VERBOSE" = 1 ] || return 0 log "$@" } warnv() { # Call `warn()` when CPT_VERBOSE is set. - [ "$CPT_VERBOSE" -eq 1 ] || return 0 + [ "$CPT_VERBOSE" = 1 ] || return 0 warn "$@" } -- cgit v1.2.3 From 4bad691465af048b36e9ba47688435ae3b9fe708 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 19 Jul 2021 12:22:08 +0000 Subject: docs: update FossilOrigin-Name: 6bd01ef3991f7e5d9d2aa908452b457edcab8b3a0967864cbb5b26126104e6e2 --- docs/cpt.org | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/cpt.org b/docs/cpt.org index aa7c2cc..1e551fe 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -1215,14 +1215,17 @@ rsync curl zlib ca-certificates bearssl This function is used to query the [[meta][meta file]] inside package directories. It can be used to retrieve information on a package that is otherwise irrelevant to the -package manager itself. It takes two arguments, first being the package and the -second being the key to be retrieved. If the package does not have a =meta= -file or the file does not contain the requested key, the function will return -with 1. +package manager itself. It takes two arguments, first being the package (or the +full path to a package directory) and the second being the key to be retrieved. +If the package does not have a =meta= file or the file does not contain the +requested key, the function will return with 1. #+begin_src sh $ pkg_query_meta cpt description Carbs Packaging Tools + +$ pkg_query_meta /path/to/cpt license +MIT #+end_src * {{{index(Concept, cp)}}} -- cgit v1.2.3 From 42d6268a40a6fe553c4291f3772ad94ccba6339e Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 19 Jul 2021 12:24:46 +0000 Subject: as_root: update environment variables FossilOrigin-Name: 889c399abaf2e8924eccfe3fd9369693351e2fb020916d00a4d6be1745153a00 --- src/cpt-lib.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 7e754e8..4b4d039 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -457,8 +457,10 @@ as_root() { CPT_PATH="$CPT_PATH" \ CPT_PID="$CPT_PID" \ CPT_PROMPT="$CPT_PROMPT" \ + CPT_REPO_CACHE="$CPT_REPO_CACHE" \ CPT_ROOT="$CPT_ROOT" \ CPT_TMPDIR="$CPT_TMPDIR" \ + CPT_VERBOSE="$CPT_VERBOSE" \ "$@" case ${su##*/} in -- cgit v1.2.3 From a61e707828228c11860c6573ca992ad55a379c0a Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 19 Jul 2021 12:25:07 +0000 Subject: docs: update FossilOrigin-Name: 5a09d7034d312982d515f96307837351ec067084fafd7973e29384dc8b44baf1 --- docs/cpt.texi | 11 +++++++---- docs/cpt.txt | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/cpt.texi b/docs/cpt.texi index 8b7bb77..b16fea7 100644 --- a/docs/cpt.texi +++ b/docs/cpt.texi @@ -1377,14 +1377,17 @@ rsync curl zlib ca-certificates bearssl This function is used to query the @ref{meta, , meta file} inside package directories. It can be used to retrieve information on a package that is otherwise irrelevant to the -package manager itself. It takes two arguments, first being the package and the -second being the key to be retrieved. If the package does not have a @samp{meta} -file or the file does not contain the requested key, the function will return -with 1. +package manager itself. It takes two arguments, first being the package (or the +full path to a package directory) and the second being the key to be retrieved. +If the package does not have a @samp{meta} file or the file does not contain the +requested key, the function will return with 1. @example $ pkg_query_meta cpt description Carbs Packaging Tools + +$ pkg_query_meta /path/to/cpt license +MIT @end example @node Concept Index diff --git a/docs/cpt.txt b/docs/cpt.txt index 78b0e6e..4e680b5 100644 --- a/docs/cpt.txt +++ b/docs/cpt.txt @@ -1282,13 +1282,17 @@ development manual for *Carbs Packaging Tools*. For development logs see This function is used to query the [meta file] inside package directories. It can be used to retrieve information on a package that is otherwise irrelevant to the package manager itself. It takes two - arguments, first being the package and the second being the key to be - retrieved. If the package does not have a `meta' file or the file does - not contain the requested key, the function will return with 1. + arguments, first being the package (or the full path to a package + directory) and the second being the key to be retrieved. If the + package does not have a `meta' file or the file does not contain the + requested key, the function will return with 1. ,---- | $ pkg_query_meta cpt description | Carbs Packaging Tools + | + | $ pkg_query_meta /path/to/cpt license + | MIT `---- -- cgit v1.2.3 From 686435fc9fced939a525b7437ec3e7af6c01aee0 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:06:45 +0000 Subject: cpt-revdepends: fix grep usage, and $tmp_dir FossilOrigin-Name: f51f87ee1550beaf2b698922c8887806d39c9aa85c9325037f5a46061716624d --- contrib/cpt-revdepends | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/cpt-revdepends b/contrib/cpt-revdepends index 833dea2..e8e8143 100755 --- a/contrib/cpt-revdepends +++ b/contrib/cpt-revdepends @@ -41,11 +41,11 @@ parser_definition() { cd "$sys_db" get_revdep() { - query="^$1\$" + pkg=$1; set -- "^$pkg\$" # Defined by parser. # shellcheck disable=2154 - [ "$make" ] && query="$query\\|^$1 *make\$" - grep "$query" -- */depends | while read -r pkg _; do + [ "$make" ] && set -- -e "$1" -e "^$pkg " + grep "$@" -- */depends | while read -r pkg _; do printf '%s\n' "${pkg%%/*}" done } @@ -53,7 +53,7 @@ get_revdep() { # Defined by parser. # shellcheck disable=2154 if [ "$tree" ]; then - create_cache nobuild + mkdir -p "$tmp_dir" :> "$tmp_dir/processed" get_revdep "$1" > "$tmp_dir/dep" while ! diff -q "$tmp_dir/dep" "$tmp_dir/processed" >/dev/null 2>&1; do -- cgit v1.2.3 From 31ec224db55bb90c451b121fcc03b36f4fff5d5e Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:09:29 +0000 Subject: cpt-revdepends: fix usage string FossilOrigin-Name: 4e34c38625436d6f4a9d0abc3adfc9042862792e8471b50c3ef573e157b56ecf --- contrib/cpt-revdepends | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/cpt-revdepends b/contrib/cpt-revdepends index e8e8143..3529a53 100755 --- a/contrib/cpt-revdepends +++ b/contrib/cpt-revdepends @@ -22,7 +22,7 @@ ## .El parser_definition() { - setup REST help:usage -- "usage: ${0##*/} [options...] [pkg...]" + setup REST help:usage -- "usage: ${0##*/} [options...] [pkg]" flag tree -t --tree -- "Also print indirect reverse dependencies" flag make -m --make -- "Include make dependencies" global_options -- cgit v1.2.3 From 18433331de86b478ef7048c102f7a99c69966d06 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:31:17 +0000 Subject: cpt-lib: change default log color FossilOrigin-Name: 2638da5faf49a1186b07ab01914a75eb55751269ae9a91bb9803605d88372a9e --- src/cpt-lib.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 4b4d039..306c5bd 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -2154,7 +2154,7 @@ create_cache() { # colors. This can of course be overriden if the user specifically want # colors during piping. if { [ "$CPT_COLOR" != 0 ] && [ -t 1 ] ;} || [ "$CPT_COLOR" = 1 ]; then - colory="\033[1;33m" colorb="\033[1;36m" colre="\033[m" + colory="\033[1;33m" colorb="\033[1;34m" colre="\033[m" fi } -- cgit v1.2.3 From e88492c6a19868600fc60003c17203aebde74cf8 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:32:00 +0000 Subject: docs: update FossilOrigin-Name: 1f3b58f235d6ebae4244c5b76d4d80772939548154f947ec76a3b7fbb5567e8d --- docs/cpt.org | 3 +++ docs/cpt.texi | 3 +++ docs/cpt.txt | 3 +++ 3 files changed, 9 insertions(+) diff --git a/docs/cpt.org b/docs/cpt.org index 1e551fe..7496ec9 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -553,6 +553,9 @@ license: MIT maintainer: Linux User #+end_example +Even though =meta= is not mandatory by the packaging system, it is a mandatory +file for submitting packages to Carbs Linux repositories. + ** post-install :PROPERTIES: :DESCRIPTION: The post-installation script diff --git a/docs/cpt.texi b/docs/cpt.texi index b16fea7..8bdcd99 100644 --- a/docs/cpt.texi +++ b/docs/cpt.texi @@ -689,6 +689,9 @@ license: MIT maintainer: Linux User @end example +Even though @samp{meta} is not mandatory by the packaging system, it is a mandatory +file for submitting packages to Carbs Linux repositories. + @node post-install @section post-install diff --git a/docs/cpt.txt b/docs/cpt.txt index 4e680b5..550a6a3 100644 --- a/docs/cpt.txt +++ b/docs/cpt.txt @@ -603,6 +603,9 @@ development manual for *Carbs Packaging Tools*. For development logs see | maintainer: Linux User `---- + Even though `meta' is not mandatory by the packaging system, it is a + mandatory file for submitting packages to Carbs Linux repositories. + [pkg_query_meta()] See section 8.7.10 -- cgit v1.2.3 From 65ec949d495b5b85d73bbae025195ae0cb8e1c8b Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 10:04:33 +0000 Subject: .build.yml: update otools build FossilOrigin-Name: f0e6afe3e50d65275b623b9566d4916d6a6acf06afde9d59c7526f3a044df111 --- .build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.build.yml b/.build.yml index 07908a2..e1f6a91 100644 --- a/.build.yml +++ b/.build.yml @@ -15,6 +15,7 @@ tasks: - install-pax: | git clone https://github.com/carbslinux/otools cd otools + ./configure make pax sudo install -Dm755 pax /usr/bin/pax - test: | -- cgit v1.2.3 From 9fee0d52ae7327c3b781bf24cb595342cd8a6193 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 10:07:40 +0000 Subject: cpt-maintainer: add tool to display the maintainer of the given package FossilOrigin-Name: aa2c95809a8569425002c8e5a6993df7830ccfbf3ade159d5b9da829992a7a7f --- contrib/cpt-maintainer | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 contrib/cpt-maintainer diff --git a/contrib/cpt-maintainer b/contrib/cpt-maintainer new file mode 100755 index 0000000..34f212f --- /dev/null +++ b/contrib/cpt-maintainer @@ -0,0 +1,49 @@ +#!/bin/sh -e +# Find the maintainer of a package + +## SYNOPSIS: +## .Nm +## .Op Ar pkg... + +## DESCRIPTION: +## .Nm +## finds the maintainer of the given pacage. If no package name is given, +## .Nm +## will use the name of the current directory as the package. + +# shellcheck disable=1091 +. cpt-lib + +usage() { + out "usage: ${0##*/} [pkg...]" + exit +} + +case $1 in + --help|-h) usage ;; + '') set -- "${PWD##*/}" +esac + +for pkgname; do + cpt-search -d "$pkgname" | while read -r pkg; do + # Default to the 'meta' file of the package instead of jumping through + # VCS hoops to find out. + log "$pkg" " " + pkg_query_meta "$pkg" maintainer && continue + + cd "$pkg" + # Use pkg_vcs_info to find out the repository type, but don't save + # repository information to the repository cache file. + repo_type=$(CPT_REPO_CACHE=0 pkg_vcs_info) + repo_type=${repo_type##*:} + + # We use the latest author who made a change to the version file to + # identify the maintainer of a package. + case $repo_type in + git) git log -1 --format='%an <%ae>' version ;; + fossil) fossil time par cur -n 1 -p version -F "%a" | sed \$d ;; + hg) hg log -l1 -T '{user}\n' -- version ;; + *) out "Maintainer information not available" + esac + done +done -- cgit v1.2.3 From db69b2f38ab92c9d5d79eb7cc46dc0707aa84271 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 14:28:04 +0000 Subject: .build.yml: do a quiet clone FossilOrigin-Name: 7b56e6bbadc2aa01bb14222396351119052ae4ea3ffd029844019262a80d624b --- .build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build.yml b/.build.yml index e1f6a91..536f9e7 100644 --- a/.build.yml +++ b/.build.yml @@ -13,7 +13,7 @@ tasks: cd cpt make - install-pax: | - git clone https://github.com/carbslinux/otools + git clone --quiet https://github.com/carbslinux/otools cd otools ./configure make pax -- cgit v1.2.3 From 9c80266180d2b46342199ec6d456cefd974bbd7a Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 14:29:36 +0000 Subject: docs: update FossilOrigin-Name: 941924b7276cd9ebd99a0980da4d465dc6dee3d83e6de2ffbac218a9b8f9c463 --- tools/tool2man.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/tool2man.sh b/tools/tool2man.sh index 38cdbf4..c4bbfb8 100755 --- a/tools/tool2man.sh +++ b/tools/tool2man.sh @@ -69,8 +69,8 @@ while read -r line; do esac done < "$file" -out ".Sh AUTHOR" ".An Cem Keylan Aq Mt cem@ckyln.com" -out ".Sh LICENSE" "See LICENSE for copyright information." +out ".Sh AUTHOR" ".An Cem Keylan Aq Mt cem@carbslinux.org" +out ".Sh COPYING" "See LICENSE for copyright information." out ".Sh SEE ALSO" ".Xr cpt 1" [ "$see" ] && for man in $see; do @@ -79,6 +79,6 @@ out ".Sh SEE ALSO" ".Xr cpt 1" out ".Pp" out "The full documentation of cpt is available as an info page." out "If either" ".Ic info" or ".Ic texinfo" -out "package is installed on your system, you can run" -out ".Bd -literal -offset indent" "info cpt" ".Ed" -out .Pp "to learn more about the package manager." +out "package is installed on your system, you can learn more about the package" +out "manager by running" +out ".Sq Sy info cpt ." -- cgit v1.2.3 From 14d010ec0322a92dab77765db45f1af927da8ef8 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 14:36:52 +0000 Subject: docs: update FossilOrigin-Name: d0f64abbc9cfcfbe1f2ce2a5a9ede01cada465c40fc188ad21effa24aef77f27 --- CHANGELOG.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf9e89..4b7c74e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ CHANGELOG ================================================================================ -This is the CHANGELOG for the Carbs Packaging Tools, initially a customized fork +This is the CHANGELOG for the Carbs Packaging Tools, initially a customised fork of the `kiss` package manager. The format is based on [Keep a Changelog], and this project _somewhat_ adheres to [Semantic Versioning]. @@ -12,8 +12,28 @@ this project _somewhat_ adheres to [Semantic Versioning]. UNRELEASED -------------------------------------------------------------------------------- +### IMPORTANT +- The package manager now enforces the usage of `pax` instead of `tar`. + +### Repository Backend + +`cpt` now has a faster and modular repository backend. `fossil` is now supported +by the package manager. During the repository fetch process, the repository +backend is stored in the cache directory so that the update takes less time on +the next pull. The usage of the repository cache can be disabled by setting +`$CPT_REPO_CACHE` to 0. + ### Added -- Added fossil support +- Added `-q, --quiet` flags to `cpt-list`. +- Re-added `cpt-maintainer`. It now supports `meta` and repository backends + other than `git`. +- The package manager now prints out `MOTD` files found on the repository root. +- Added the `$CPT_VERBOSE` variable and the `--verbose` flags to some utilities. + With the addition of these, some parts of the package manager will be more + quiet unless verbosity is explicitly requested. + +### Changed +- Reworked the package repository backend. 6.0.4 - 2021-05-12 -- cgit v1.2.3 -- cgit v1.2.3 From cc811e32c0cb32f406d1bf9ea36d319e5216cfb4 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 14:56:05 +0000 Subject: cpt: bump version to 6.1.0 FossilOrigin-Name: eda7941d69772129700d8d155a965551d3e606ada304ea34eea979df85beabf2 --- CHANGELOG.md | 2 +- config.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b7c74e..1ea1041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ this project _somewhat_ adheres to [Semantic Versioning]. [Semantic Versioning]: https://semver.org/spec/v2.0.0.html -UNRELEASED +6.1.0 - 2021-07-22 -------------------------------------------------------------------------------- ### IMPORTANT diff --git a/config.mk b/config.mk index 1bc27fe..5253f54 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # Carbs Packaging Tools -VERSION = dev +VERSION = 6.1.0 # Installation paths PREFIX = /usr/local -- cgit v1.2.3 From eeaa0e59b8289497ea3e7c0cdc00945874668d6e Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 15:03:21 +0000 Subject: fix mkdist FossilOrigin-Name: 50ea8287757380c29b44d75c827d7ab30354f5dc45efef2b86400f4cc771958c --- tools/mkdist.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/mkdist.sh b/tools/mkdist.sh index c21e964..bcf1caf 100755 --- a/tools/mkdist.sh +++ b/tools/mkdist.sh @@ -25,6 +25,8 @@ fossil ls | while read -r file; do cp "$file" "$basedir/$file" done +cp docs/cpt.info "$basedir/docs/cpt.info" + tar cf "$basedir.tar" "$basedir" xz -z "$basedir.tar" rm -rf -- "$basedir" -- cgit v1.2.3 From fb6a0c90c066e5ed91c607e125b3806a2fd462a5 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 15:05:08 +0000 Subject: docs: update FossilOrigin-Name: c16dc9832b060087d60660ce0a49e0c721e6ed6cadffea220a106c2f3ff72be3 --- www/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/index.md b/www/index.md index 0c55e80..99ad599 100644 --- a/www/index.md +++ b/www/index.md @@ -32,7 +32,7 @@ complements the tools that come with it. It has the following features:
-### Latest Release: 6.0.4 ([2021-05-12](/timeline?c=6.0.4)) +### Latest Release: 6.1.0 ([2021-07-22](/timeline?c=6.1.0)) - [Download](/uvlist?byage=1) - [Changelog](/doc/trunk/CHANGELOG.md) -- cgit v1.2.3 From 3cf4cf4b1649e5b561b392930a9277cbd36c5566 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 24 Jul 2021 20:37:51 +0000 Subject: pkg_download: new function for using alternative downloaders FossilOrigin-Name: a64a103f527bb5cd45b1e63cf1f8488a220222044c6f0c012f6947ae4abe3e40 --- src/cpt-lib.in | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 306c5bd..504829d 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -419,6 +419,21 @@ regesc() { sed 's|\\|\\\\|g;s|\[|\\[|g;s|\$|\\$|g;s|\.|\\.|g;s|\*|\\*|g;s|\^|\\^|g' } +pkg_download() { + # $1: URL + # $2: Output (Optional) + set -- "$1" "${2:-${1##*/}}" + case ${dl_prog##*/} in + aria2c|axel) set -- -o "$2" "$1" ;; + curl) set -- -fLo "$2" "$1" ;; + wget|wget2) set -- -O "$2" "$1" ;; + esac + + "$dl_prog" "$@" || { + rm -f "$2" + return 1 + } +} prompt() { # If a CPT_NOPROMPT variable is set, continue. @@ -688,10 +703,8 @@ pkg_sources() { # interrupt, we handle this ourselves. trap_set handle-int - curl "$src" -fLo "${src##*/}" || { - rm -f "${src##*/}" - die "$1" "Failed to download $src" - } + # Download the source + pkg_download "$src" || die "$1" "Failed to download $src" # Restore original trap value. trap_set cleanup @@ -2117,6 +2130,13 @@ create_cache() { command -v llvm-readelf || command -v eu-readelf)"} || elf_prog=ldd + dl_prog=${CPT_DOWNLOADER:="$( + command -v curl || + command -v wget || + command -v wget2 || + command -v axel || + command -v aria2c)"} || dl_prog=curl + # Make note of the user's current ID to do root checks later on. # This is used enough to warrant a place here. uid=$(id -u) -- cgit v1.2.3 From b18adcfd202ea80581e57df08a3fe559f9a78ae4 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 26 Jul 2021 22:39:53 +0000 Subject: cpt-size: rewrite tool to address POSIX compliance, faster calculation, and argument count limitations on huge packages FossilOrigin-Name: 01179eddc1e9cfa4183377c1f09da1de09f5ed0a801d81a94ae2aa8021ed1ff5 --- contrib/cpt-size | 65 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/contrib/cpt-size b/contrib/cpt-size index 2812d56..0ece039 100755 --- a/contrib/cpt-size +++ b/contrib/cpt-size @@ -11,40 +11,41 @@ ## .Ar packages ## using the files from the package manifest and outputs a total size of the ## packages along with all the files associated with them. +parser_definition() { + setup REST help:usage -- "usage: ${0##*/} [pkg...]" + disp :usage -h --help hidden:1 +} -## CAVEATS: -## .Nm -## uses the non-POSIX -## .Fl h -## and -## .Fl c -## flags for -## .Xr du 1 , -## which will not work with -## .Em sbase , -## but it is a major performance improvement compared to calculating -## total and human-readable sizes by hand. +# shellcheck source=/bin/cpt-lib +# shellcheck disable=1091 +. cpt-lib -case "$1" in - --help|-h) - printf '%s\n' "usage: ${0##*/} [pkg...]" - exit 0 - ;; - '') set -- "${PWD##*/}" -esac +# Ensure that all the packages given as arguments are installed. +pkg_list "$@" >/dev/null -for pkg; do cpt-list "$pkg" >/dev/null; done +mkdir -p "$tmp_dir" -files= -for pkg; do - while read -r file; do - # Filter directories from manifest and leave only files. - # Directories in the manifest end in a trailing '/'. - case $file in */) continue; esac - files="$files '$file'" - done < "$CPT_ROOT/var/db/cpt/installed/$pkg/manifest" -done -eval "set -- $files" +# We don't immediately pipe into awk as we want to exit in an error. +for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done | + xargs du -k > "$tmp_dir/size" -# Send the file list to 'du'. -du -shc -- "$@" 2>/dev/null +# This awk function formats the `du` output similar to the '-hc' flags. We +# could have used a shell `while read` loop to do the exact same thing, but that +# would be much much slower. +awk 'function fmtsize(s) { + if (s==0) f="" + else if (s<1024) f="K" + else if (s<(1048576)){f="M";s=s/1024;} + else if (s<(1073741824)){f="G";s=s/1048576;} + else f="" + return int(s) f + } + { + sc = $1 + size += $1 + sub(sprintf("^%s\s*", $1), "") + printf("%-6s %s\n", fmtsize(sc), $0) + } + END { + printf("%-6s total\n", fmtsize(size)) + }' "$tmp_dir/size" -- cgit v1.2.3 From 57093831d9c125b1ee872ecf21792324d2238354 Mon Sep 17 00:00:00 2001 From: merakor Date: Tue, 27 Jul 2021 09:23:22 +0000 Subject: Makefile: update test targets FossilOrigin-Name: 5e9fa6e8cf409564df3dd794ff0705fb43df65d142cb65daf56034bf31ae1671 --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eceb18d..3b49aaf 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,14 @@ src/cpt-lib: src/cpt-lib.in -e "s|@DOCSTRING@|Call functions from the library|g" < src/cpt-lib.in > $@ chmod 755 $@ -test: all tests/etc/cpt-hook +shellspec: all tests/etc/cpt-hook shellspec + +shellcheck: all cd src; find . ../contrib -name 'cpt*' ! -name '*.*' -exec shellcheck -e 2119 -x -f gcc {} + +test: shellspec shellcheck + tests/etc/cpt-hook: ln -s ../hook-file $@ @@ -47,4 +51,4 @@ clean: rm -rf src/cpt-lib "cpt-${VERSION}.tar.xz" coverage report rm -f tests/etc/cpt-hook -.PHONY: all dist clean install uninstall +.PHONY: all dist clean install uninstall shellspec shellcheck test -- cgit v1.2.3