# HG changeset patch # User Aleksej Bobylev # Date 1441153907 -10800 # Node ID 0560ba4306a1be816fa0230de43cc68cdf3d9b46 # Parent fe2625fde69cbacf801c666386c71c3b1d3af21a tazpkg: internal command 'call ...' to call tazpkg functions from modules (to share functions between tazpkg and its modules) diff -r fe2625fde69c -r 0560ba4306a1 modules/block --- a/modules/block Fri Aug 28 17:19:09 2015 +0300 +++ b/modules/block Wed Sep 02 03:31:47 2015 +0300 @@ -13,75 +13,54 @@ -# Log activity - -log_pkg() { - [ -w "$LOG" ] && - echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)" >> "$LOG" -} - - - +newline +if [ ! -d "$INSTALLED/$2" ]; then + _ 'Package "%s" is not installed.' "$2" + exit 1 +fi case $1 in block|-b) # Block package - newline - if [ ! -d "$INSTALLED/$2" ]; then - _ 'Package "%s" is not installed.' "$2" - exit 1 - fi if grep -qs "^$2" "$BLOCKED"; then _ 'Package "%s" is already blocked.' "$2" else echo "$2" >> "$BLOCKED" # Log this activity - . "$INSTALLED/$2/receipt"; log_pkg Blocked + . "$INSTALLED/$2/receipt"; tazpkg call log_pkg Blocked _ 'Package "%s" blocked.' "$2" fi - newline ;; unblock|-u) # Unblock package - newline - if [ ! -d "$INSTALLED/$2" ]; then - _ 'Package "%s" is not installed.' "$2" - exit 1 - fi if grep -qs "^$2" "$BLOCKED"; then sed -i "/^$2\$/d" "$BLOCKED" # Log this activity - . "$INSTALLED/$2/receipt"; log_pkg Unblocked + . "$INSTALLED/$2/receipt"; tazpkg call log_pkg Unblocked _ 'Package "%s" unblocked.' "$2" else _ 'Package "%s" is not blocked.' "$2" fi - newline ;; chblock) # Block/unblock package - newline - if [ ! -d "$INSTALLED/$2" ]; then - _ 'Package "%s" is not installed.' "$2" - exit 1 - fi if grep -qs "^$2" "$BLOCKED"; then sed -i "/^$2\$/d" "$BLOCKED" # Log this activity - . "$INSTALLED/$2/receipt"; log_pkg Unblocked + . "$INSTALLED/$2/receipt"; tazpkg call log_pkg Unblocked _ 'Package "%s" unblocked.' "$2" else echo "$2" >> "$BLOCKED" # Log this activity - . "$INSTALLED/$2/receipt"; log_pkg Blocked + . "$INSTALLED/$2/receipt"; tazpkg call log_pkg Blocked _ 'Package "%s" blocked.' "$2" fi - newline ;; esac +newline diff -r fe2625fde69c -r 0560ba4306a1 modules/check --- a/modules/check Fri Aug 28 17:19:09 2015 +0300 +++ b/modules/check Wed Sep 02 03:31:47 2015 +0300 @@ -13,29 +13,6 @@ -# Get repositories priority using $PKGS_DB/priority. -# In this file undigest repos are called by their names and main mirror -# by 'main'. Sort order: priority - -look_for_priority() { - [ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority") - - for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do - if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then - priority=$(echo -e "$priority\n$rep") - fi - done - - priority=$(echo "$priority" | sed '/^$/d' | \ - while read line; do - case $line in - (main) echo "$PKGS_DB";; - (*) echo "$PKGS_DB/undigest/$line";; - esac - done) -} - - # Print package name if not printed yet print_pkgname() { if [ "$PACKAGE" != "$PACKAGE_PRINTED" ]; then @@ -109,7 +86,7 @@ # Get repositories priority list. -look_for_priority +priority=$(tazpkg call look_for_priority) cd "$INSTALLED" if [ -z "$2" -o -n "$full" ]; then PACKAGES="$(ls)"; else PACKAGES="$2"; fi diff -r fe2625fde69c -r 0560ba4306a1 modules/flavor --- a/modules/flavor Fri Aug 28 17:19:09 2015 +0300 +++ b/modules/flavor Wed Sep 02 03:31:47 2015 +0300 @@ -15,29 +15,6 @@ -# Get repositories priority using $PKGS_DB/priority. -# In this file undigest repos are called by their names and main mirror -# by 'main'. Sort order: priority - -look_for_priority() { - [ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority") - - for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do - if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then - priority=$(echo -e "$priority\n$rep") - fi - done - - priority=$(echo "$priority" | sed '/^$/d' | \ - while read line; do - case $line in - (main) echo "$PKGS_DB";; - (*) echo "$PKGS_DB/undigest/$line";; - esac - done) -} - - # Download a file from this mirror download_from() { @@ -76,7 +53,7 @@ # Get repositories priority list. -look_for_priority +priority=$(tazpkg call look_for_priority) FLAVOR="$1" TMP_DIR=$(mktemp -d) diff -r fe2625fde69c -r 0560ba4306a1 modules/search --- a/modules/search Fri Aug 28 17:19:09 2015 +0300 +++ b/modules/search Wed Sep 02 03:31:47 2015 +0300 @@ -13,19 +13,6 @@ -# Translate category names (must be last in line) - -translate_category() { - sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|; - s|utilities$|$(_ utilities)|; s|network$|$(_ network)|; - s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|; - s|office$|$(_ office)|; s|development$|$(_ development)|; - s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|; - s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|; - s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|" -} - - # Search pattern in installed packages. search_in_installed_packages() { @@ -38,7 +25,7 @@ index($1 "-" $2, pattern) { printf "%-24s%-18s%s\n", $1, $2, $3; printf "1" >> t - }' "$PKGS_DB/installed.info" | translate_category + }' "$PKGS_DB/installed.info" | tazpkg call translate_category num=$(wc -m < "$TMPLIST"); rm "$TMPLIST" footer "$(_p \ @@ -61,7 +48,7 @@ index($1 "-" $2, pattern) { printf "%-24s%-18s%s\n", $1, $2, $3; printf "1" >> t - }' "$i" | translate_category + }' "$i" | tazpkg call translate_category done for i in $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list; do @@ -70,7 +57,7 @@ index($1 "-" $5, pattern) { printf "%-24s%-18s%s\n", $1 " (extra)", $5, $4; printf "1" >> t - }' "$i" | translate_category + }' "$i" | tazpkg call translate_category done if [ ! -f "$PKGS_DB/packages.info" ]; then @@ -185,8 +172,9 @@ # Check all pkg files.list in search match which specify the package # name and the full path to the file(s). - for pkg in $INSTALLED/*; do - if grep -qs "$2" "$pkg/files.list"; then + for pkg in $(awk -F$'\t' '{print $1}' $PKGS_DB/installed.info); do + FL="$INSTALLED/$pkg/files.list" + if grep -qs "$2" "$FL"; then newline emsg "$(_ 'Package %s:' "$pkg")" awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" ' @@ -196,7 +184,7 @@ print " "$0; printf "1" >> tmp; } - ' "$pkg/files.list" + ' "$FL" fi done diff -r fe2625fde69c -r 0560ba4306a1 modules/upgrade --- a/modules/upgrade Fri Aug 28 17:19:09 2015 +0300 +++ b/modules/upgrade Wed Sep 02 03:31:47 2015 +0300 @@ -17,36 +17,6 @@ . @@MODULES@@/getenv - - -# Functions -# --------- - -# Get repositories priority using $PKGS_DB/priority. -# In this file undigest repos are called by their names and main mirror -# by 'main'. Sort order: priority - -look_for_priority() { - [ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority") - - for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do - if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then - priority=$(echo -e "$priority\n$rep") - fi - done - - priority=$(echo "$priority" | sed '/^$/d' | \ - while read line; do - case $line in - (main) echo "$PKGS_DB";; - (*) echo "$PKGS_DB/undigest/$line";; - esac - done) -} - - - - time="$(date +%s)" # Recharge packages databases (if necessary) (respects already exported "root" value) @@ -56,9 +26,8 @@ blocked_counter=$(mktemp) tmp_up_list=$(mktemp) -look_for_priority repo_number=1 -for repo in $priority; do +for repo in $(tazpkg call look_for_priority); do if [ "$repo" == "$PKGS_DB" ]; then repo_name='Main' else diff -r fe2625fde69c -r 0560ba4306a1 tazpkg --- a/tazpkg Fri Aug 28 17:19:09 2015 +0300 +++ b/tazpkg Wed Sep 02 03:31:47 2015 +0300 @@ -173,17 +173,17 @@ [ -s "$PKGS_DB/priority" ] && priority=$(cat $PKGS_DB/priority) for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do - if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ $PKGS_DB/priority; then + if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ "$PKGS_DB/priority"; then priority=$(echo -e "$priority\n$rep") fi done - priority=$(echo "$priority" | sed '/^$/d' | \ - while read line; do + echo "$priority" | sed '/^$/d' | \ + while read line; do case $line in - (main) echo $PKGS_DB;; - (*) echo $PKGS_DB/undigest/$line;; + main) echo "$PKGS_DB";; + *) echo "$PKGS_DB/undigest/$line";; esac - done) + done } @@ -357,7 +357,7 @@ # input: "" or "-" (ex. "nano" or "nano-2.4.0") local pkg equiv for rep in $priority; do - pkg=$(awk -F$'\t' -vp="$1" 'p==$1||p==$1"-"$2{print $1"-"$2}' $rep/packages.info) + pkg=$(awk -F$'\t' -vp="$1" 'p==$1||p==$1"-"$2{print $1"-"$2}' "$rep/packages.info") if [ -n "$pkg" ]; then get_cache_dir; break @@ -979,6 +979,15 @@ ################### case "$COMMAND" in + call) + # Call internal tazpkg function from external tazpkg module or other script. + # Useful for functions sharing. + shift + # Check to call only tazpkg functions + fgrep -q "$1()" "$0" && $@ + ;; + + list|-l) # Various lists shift @@ -1061,7 +1070,7 @@ [ -n "$list" ] && INSTALL_LIST="$list" # Get repositories priority list. - look_for_priority + priority=$(look_for_priority) # Check if forced install. if [ -z "$forced" ]; then @@ -1358,7 +1367,7 @@ fi # Get repositories priority list. - look_for_priority + priority=$(look_for_priority) CURRENT_DIR="$PWD" cd "$CACHE_DIR" @@ -1401,7 +1410,7 @@ [ -n "$list" ] && INSTALL_LIST="$list" # internal option # Get repositories priority list. - look_for_priority + priority=$(look_for_priority) AUTOEXEC='no' # Magic :)