diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cpt-lib.in | 92 | ||||
-rwxr-xr-x | src/cpt-list | 9 |
2 files changed, 75 insertions, 26 deletions
diff --git a/src/cpt-lib.in b/src/cpt-lib.in index ea00bb9..504829d 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" = 1 ] || return 0 + out "$@" +} + +logv() { + # Call `log()` when CPT_VERBOSE is set. + [ "$CPT_VERBOSE" = 1 ] || return 0 + log "$@" +} + +warnv() { + # Call `warn()` when CPT_VERBOSE is set. + [ "$CPT_VERBOSE" = 1 ] || return 0 + warn "$@" +} + die() { # Print a message and exit with '1' (error). log "$1" "$2" "!>" @@ -381,11 +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" -} - -warn() { - # Print a warning message - log "$1" "$2" "${3:-WARNING}" + flag CPT_VERBOSE --verbose init:@export -- "Be more verbose" } contains() { @@ -400,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. @@ -438,8 +472,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 @@ -472,7 +508,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 +574,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" @@ -663,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 @@ -1386,17 +1424,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 +1444,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= ;; @@ -1618,12 +1656,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)" } } @@ -1977,8 +2015,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 @@ -2089,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) @@ -2126,7 +2174,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 } diff --git a/src/cpt-list b/src/cpt-list index 4eb7cf6..fcb1f49 100755 --- a/src/cpt-list +++ b/src/cpt-list @@ -3,10 +3,11 @@ 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" + 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." \ @@ -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 |