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(-) (limited to 'src/cpt-lib.in') 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 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(+) (limited to 'src/cpt-lib.in') 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(-) (limited to 'src/cpt-lib.in') 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 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(-) (limited to 'src/cpt-lib.in') 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(-) (limited to 'src/cpt-lib.in') 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 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(+) (limited to 'src/cpt-lib.in') 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 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(-) (limited to 'src/cpt-lib.in') 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 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(-) (limited to 'src/cpt-lib.in') 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