# HG changeset patch # User Aleksej Bobylev # Date 1448840737 -7200 # Node ID 19fad7781af35c016d420851079fe6b1bee1022a # Parent e2e188861988eb7ede8bdb6f4de3c0fd0f232fed modules getenv, get, install: provide --quiet option (don't display service messages, show errors only) diff -r e2e188861988 -r 19fad7781af3 modules/get --- a/modules/get Sat Nov 28 13:46:13 2015 +0200 +++ b/modules/get Mon Nov 30 01:45:37 2015 +0200 @@ -159,7 +159,7 @@ if [ -f 'packages.info' ]; then awk -F$'\t' -vp="$1" '$1==p{exit 1}' packages.info if [ "$?" -eq 1 ]; then - _ 'Package "%s" already in the cache' "$1" >&2 + [ -z "$quiet" ] && _ 'Package "%s" already in the cache' "$1" >&2 echo -n "$(pwd)/" awk -F$'\t' -vp="$1" '$1==p{printf "%s-%s.tazpkg\n", $1, $2; exit}' packages.info exit 0 @@ -283,7 +283,7 @@ virtual_pkg() { # input: $1 virtual package name # $2 repository db directory - # outout: display possible package name + # output: display possible package name local i for i in $(grep -hs "^$1=" "$2/packages.equiv" | sed "s/^$1=//"); do @@ -351,11 +351,11 @@ # Check if package already downloaded if [ -f "$namever.tazpkg" ]; then - [ -z "$nocache" ] && _ 'Package "%s" already in the cache' "$namever" >&2 + [ -z "$nocache" -a -z "$quiet" ] && _ 'Package "%s" already in the cache' "$namever" >&2 # Check if downloading complete, resume it not complete if ! tail -c 2k "$namever.tazpkg" | fgrep -q '00000000TRAILER'; then - _ 'Continuing package "%s" download' "$namever" >&2 + [ -z "$quiet" ] && _ 'Continuing package "%s" download' "$namever" >&2 download_from "$(cat "$rep/mirror")" "$namever.tazpkg" fi else diff -r e2e188861988 -r 19fad7781af3 modules/getenv --- a/modules/getenv Sat Nov 28 13:46:13 2015 +0200 +++ b/modules/getenv Mon Nov 30 01:45:37 2015 +0200 @@ -192,4 +192,33 @@ CUR_DIR="$(pwd)" + +# Quiet functions + +saved_action='' +qaction() { + saved_action="$1" + [ -z "$quiet" ] && action "$1"; +} + +qstatus() { + local ret_code=$? + if [ -z "$quiet" ]; then + test "$ret_code" -eq 0; status + elif [ "$ret_code" -ne 0 ]; then + # Show both action and it's status in the silent mode if error + action "$saved_action" + test 1 -eq 2; status + fi +} + +qtitle() { + [ -z "$quiet" ] && title "$@"; +} + +qfooter() { + [ -z "$quiet" ] && footer "$@"; +} + + debug '-- end getenv --' diff -r e2e188861988 -r 19fad7781af3 modules/install --- a/modules/install Sat Nov 28 13:46:13 2015 +0200 +++ b/modules/install Mon Nov 30 01:45:37 2015 +0200 @@ -188,7 +188,7 @@ extract_package() { # input: $1 - path to package to be extracted; package should be in the current dir # ROOT INDEPENDENT - action 'Extracting package...' + qaction 'Extracting package...' # Extract "outer layer": cpio; remove the original package file cpio -idm --quiet < "$1" && rm -f "$1" @@ -202,7 +202,7 @@ zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz fi - status + qstatus } @@ -248,12 +248,12 @@ call_pre_install() { local tmp if grep -q '^pre_install()' "$1"; then - action 'Execute pre-install commands...' + qaction 'Execute pre-install commands...' tmp="$(mktemp)" cp "$1" "$tmp" sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp" ( . "$tmp"; pre_install "$root" ) - status + qstatus rm "$tmp" fi @@ -262,12 +262,12 @@ call_post_install() { local tmp if grep -q '^post_install()' "$1"; then - action 'Execute post-install commands...' + qaction 'Execute post-install commands...' tmp="$(mktemp)" cp "$1" "$tmp" sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp" ( . "$tmp"; post_install "$root" ) - status + qstatus rm "$tmp" fi } @@ -332,17 +332,19 @@ #[ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> "$PKGS_DB/$INSTALL_LIST-processed" if [ -n "$sequence" ]; then - title 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence" + qtitle 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence" else - title 'Installation of package "%s"' "$PACKAGE" + qtitle 'Installation of package "%s"' "$PACKAGE" fi - print_short_description "$PACKAGE" - separator '-' + if [ -z "$quiet" ]; then + print_short_description "$PACKAGE" + separator '-' + fi - action 'Copying package...' + qaction 'Copying package...' cp "$PACKAGE_FILE" "$TMP_DIR" - status + qstatus cd "$TMP_DIR" extract_package "$(basename "$PACKAGE_FILE")" @@ -370,7 +372,7 @@ # Remember modified packages - action 'Remember modified packages...' + qaction 'Remember modified packages...' { check=false # TODO: why '[' the special? @@ -416,7 +418,7 @@ fi echo "$PACKAGE" >> "$dir/modifiers" done - status + qstatus cd "$TMP_DIR" @@ -432,7 +434,7 @@ if [ -n "$CONFIG_FILES" ]; then # Save "official" configuration files - action 'Saving configuration files...' + qaction 'Saving configuration files...' debug "\n" cd fs @@ -458,12 +460,12 @@ done fi # always '[ Done ]' status, unless '--newconf' is passed or not - :; status + :; qstatus fi if [ -n "$(ls fs/* 2>/dev/null)" ]; then - action 'Installing package...' + qaction 'Installing package...' debug '\n resolving destination links in source' IFS=$'\n' @@ -478,12 +480,12 @@ debug ' copying folders and files to destination' cp -af fs/* "$root/" - status + qstatus fi if [ -s files2remove.list ]; then - action 'Removing old files...' + qaction 'Removing old files...' while read file; do dir="$root$file" # Remove specified file @@ -494,15 +496,14 @@ rmdir "$dir" 2>/dev/null || break done done < files2remove.list - true - status + :; qstatus fi # Remove the temporary random directory. - action "Removing all tmp files..." + qaction "Removing all tmp files..." cd ..; rm -rf "$TMP_DIR" - status + qstatus # Post install commands @@ -525,7 +526,7 @@ fgrep -q /lib/modules "$fl" && ukrnl='yes' if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then - action 'Update system databases...' + qaction 'Update system databases...' upd=1 fi @@ -542,7 +543,7 @@ # packages 'busybox', 'kmod', 'depmod' [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a - [ "$upd" -eq 1 ] && status + [ "$upd" -eq 1 ] && qstatus @@ -563,7 +564,7 @@ sort "$ii" > "$TEMP_FILE"; mv -f "$TEMP_FILE" "$ii"; chmod a+r "$ii"; unset ii cd "$CUR_DIR" - footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")" + qfooter "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")" # Log this activity log_pkg Installed