tazpkg rev 842

tazpkg: internal command 'call ...' to call tazpkg functions from modules (to share functions between tazpkg and its modules)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Sep 02 03:31:47 2015 +0300 (2015-09-02)
parents fe2625fde69c
children 95c016ddc72d
files modules/block modules/check modules/flavor modules/search modules/upgrade tazpkg
line diff
     1.1 --- a/modules/block	Fri Aug 28 17:19:09 2015 +0300
     1.2 +++ b/modules/block	Wed Sep 02 03:31:47 2015 +0300
     1.3 @@ -13,75 +13,54 @@
     1.4  
     1.5  
     1.6  
     1.7 -# Log activity
     1.8 -
     1.9 -log_pkg() {
    1.10 -	[ -w "$LOG" ] &&
    1.11 -	echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)" >> "$LOG"
    1.12 -}
    1.13 -
    1.14 -
    1.15 -
    1.16 +newline
    1.17 +if [ ! -d "$INSTALLED/$2" ]; then
    1.18 +	_ 'Package "%s" is not installed.' "$2"
    1.19 +	exit 1
    1.20 +fi
    1.21  
    1.22  case $1 in
    1.23  
    1.24  	block|-b)
    1.25  		# Block package
    1.26 -		newline
    1.27 -		if [ ! -d "$INSTALLED/$2" ]; then
    1.28 -			_ 'Package "%s" is not installed.' "$2"
    1.29 -			exit 1
    1.30 -		fi
    1.31  		if grep -qs "^$2" "$BLOCKED"; then
    1.32  			_ 'Package "%s" is already blocked.' "$2"
    1.33  		else
    1.34  			echo "$2" >> "$BLOCKED"
    1.35  			# Log this activity
    1.36 -			. "$INSTALLED/$2/receipt"; log_pkg Blocked
    1.37 +			. "$INSTALLED/$2/receipt"; tazpkg call log_pkg Blocked
    1.38  			_ 'Package "%s" blocked.' "$2"
    1.39  		fi
    1.40 -		newline
    1.41  		;;
    1.42  
    1.43  
    1.44  	unblock|-u)
    1.45  		# Unblock package
    1.46 -		newline
    1.47 -		if [ ! -d "$INSTALLED/$2" ]; then
    1.48 -			_ 'Package "%s" is not installed.' "$2"
    1.49 -			exit 1
    1.50 -		fi
    1.51  		if grep -qs "^$2" "$BLOCKED"; then
    1.52  			sed -i "/^$2\$/d" "$BLOCKED"
    1.53  			# Log this activity
    1.54 -			. "$INSTALLED/$2/receipt"; log_pkg Unblocked
    1.55 +			. "$INSTALLED/$2/receipt"; tazpkg call log_pkg Unblocked
    1.56  			_ 'Package "%s" unblocked.' "$2"
    1.57  		else
    1.58  			_ 'Package "%s" is not blocked.' "$2"
    1.59  		fi
    1.60 -		newline
    1.61  		;;
    1.62  
    1.63  
    1.64  	chblock)
    1.65  		# Block/unblock package
    1.66 -		newline
    1.67 -		if [ ! -d "$INSTALLED/$2" ]; then
    1.68 -			_ 'Package "%s" is not installed.' "$2"
    1.69 -			exit 1
    1.70 -		fi
    1.71  		if grep -qs "^$2" "$BLOCKED"; then
    1.72  			sed -i "/^$2\$/d" "$BLOCKED"
    1.73  			# Log this activity
    1.74 -			. "$INSTALLED/$2/receipt"; log_pkg Unblocked
    1.75 +			. "$INSTALLED/$2/receipt"; tazpkg call log_pkg Unblocked
    1.76  			_ 'Package "%s" unblocked.' "$2"
    1.77  		else
    1.78  			echo "$2" >> "$BLOCKED"
    1.79  			# Log this activity
    1.80 -			. "$INSTALLED/$2/receipt"; log_pkg Blocked
    1.81 +			. "$INSTALLED/$2/receipt"; tazpkg call log_pkg Blocked
    1.82  			_ 'Package "%s" blocked.' "$2"
    1.83  		fi
    1.84 -		newline
    1.85  		;;
    1.86  
    1.87  esac
    1.88 +newline
     2.1 --- a/modules/check	Fri Aug 28 17:19:09 2015 +0300
     2.2 +++ b/modules/check	Wed Sep 02 03:31:47 2015 +0300
     2.3 @@ -13,29 +13,6 @@
     2.4  
     2.5  
     2.6  
     2.7 -# Get repositories priority using $PKGS_DB/priority.
     2.8 -# In this file undigest repos are called by their names and main mirror
     2.9 -# by 'main'. Sort order: priority
    2.10 -
    2.11 -look_for_priority() {
    2.12 -	[ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority")
    2.13 -
    2.14 -	for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do
    2.15 -		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then
    2.16 -			priority=$(echo -e "$priority\n$rep")
    2.17 -		fi
    2.18 -	done
    2.19 -
    2.20 -	priority=$(echo "$priority" | sed '/^$/d' | \
    2.21 -		while read line; do
    2.22 -		case $line in
    2.23 -			(main) echo "$PKGS_DB";;
    2.24 -			(*)    echo "$PKGS_DB/undigest/$line";;
    2.25 -		esac
    2.26 -	done)
    2.27 -}
    2.28 -
    2.29 -
    2.30  # Print package name if not printed yet
    2.31  print_pkgname() {
    2.32  	if [ "$PACKAGE" != "$PACKAGE_PRINTED" ]; then
    2.33 @@ -109,7 +86,7 @@
    2.34  
    2.35  
    2.36  # Get repositories priority list.
    2.37 -look_for_priority
    2.38 +priority=$(tazpkg call look_for_priority)
    2.39  
    2.40  cd "$INSTALLED"
    2.41  if [ -z "$2" -o -n "$full" ]; then PACKAGES="$(ls)"; else PACKAGES="$2"; fi
     3.1 --- a/modules/flavor	Fri Aug 28 17:19:09 2015 +0300
     3.2 +++ b/modules/flavor	Wed Sep 02 03:31:47 2015 +0300
     3.3 @@ -15,29 +15,6 @@
     3.4  
     3.5  
     3.6  
     3.7 -# Get repositories priority using $PKGS_DB/priority.
     3.8 -# In this file undigest repos are called by their names and main mirror
     3.9 -# by 'main'. Sort order: priority
    3.10 -
    3.11 -look_for_priority() {
    3.12 -	[ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority")
    3.13 -
    3.14 -	for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do
    3.15 -		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then
    3.16 -			priority=$(echo -e "$priority\n$rep")
    3.17 -		fi
    3.18 -	done
    3.19 -
    3.20 -	priority=$(echo "$priority" | sed '/^$/d' | \
    3.21 -		while read line; do
    3.22 -		case $line in
    3.23 -			(main) echo "$PKGS_DB";;
    3.24 -			(*)    echo "$PKGS_DB/undigest/$line";;
    3.25 -		esac
    3.26 -	done)
    3.27 -}
    3.28 -
    3.29 -
    3.30  # Download a file from this mirror
    3.31  
    3.32  download_from() {
    3.33 @@ -76,7 +53,7 @@
    3.34  
    3.35  
    3.36  # Get repositories priority list.
    3.37 -look_for_priority
    3.38 +priority=$(tazpkg call look_for_priority)
    3.39  
    3.40  FLAVOR="$1"
    3.41  TMP_DIR=$(mktemp -d)
     4.1 --- a/modules/search	Fri Aug 28 17:19:09 2015 +0300
     4.2 +++ b/modules/search	Wed Sep 02 03:31:47 2015 +0300
     4.3 @@ -13,19 +13,6 @@
     4.4  
     4.5  
     4.6  
     4.7 -# Translate category names (must be last in line)
     4.8 -
     4.9 -translate_category() {
    4.10 -	sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|;
    4.11 -		s|utilities$|$(_ utilities)|; s|network$|$(_ network)|;
    4.12 -		s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|;
    4.13 -		s|office$|$(_ office)|; s|development$|$(_ development)|;
    4.14 -		s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|;
    4.15 -		s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|;
    4.16 -		s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|"
    4.17 -}
    4.18 -
    4.19 -
    4.20  # Search pattern in installed packages.
    4.21  
    4.22  search_in_installed_packages() {
    4.23 @@ -38,7 +25,7 @@
    4.24  		index($1 "-" $2, pattern) {
    4.25  			printf "%-24s%-18s%s\n", $1, $2, $3;
    4.26  			printf "1" >> t
    4.27 -		}' "$PKGS_DB/installed.info" | translate_category
    4.28 +		}' "$PKGS_DB/installed.info" | tazpkg call translate_category
    4.29  	num=$(wc -m < "$TMPLIST"); rm "$TMPLIST"
    4.30  
    4.31  	footer "$(_p \
    4.32 @@ -61,7 +48,7 @@
    4.33  		index($1 "-" $2, pattern) {
    4.34  			printf "%-24s%-18s%s\n", $1, $2, $3;
    4.35  			printf "1" >> t
    4.36 -		}' "$i" | translate_category
    4.37 +		}' "$i" | tazpkg call translate_category
    4.38  	done
    4.39  
    4.40  	for i in $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list; do
    4.41 @@ -70,7 +57,7 @@
    4.42  		index($1 "-" $5, pattern) {
    4.43  			printf "%-24s%-18s%s\n", $1 " (extra)", $5, $4;
    4.44  			printf "1" >> t
    4.45 -		}' "$i" | translate_category
    4.46 +		}' "$i" | tazpkg call translate_category
    4.47  	done
    4.48  
    4.49  	if [ ! -f "$PKGS_DB/packages.info" ]; then
    4.50 @@ -185,8 +172,9 @@
    4.51  
    4.52  			# Check all pkg files.list in search match which specify the package
    4.53  			# name and the full path to the file(s).
    4.54 -			for pkg in $INSTALLED/*; do
    4.55 -				if grep -qs "$2" "$pkg/files.list"; then
    4.56 +			for pkg in $(awk -F$'\t' '{print $1}' $PKGS_DB/installed.info); do
    4.57 +				FL="$INSTALLED/$pkg/files.list"
    4.58 +				if grep -qs "$2" "$FL"; then
    4.59  					newline
    4.60  					emsg "<c 33>$(_ 'Package %s:' "$pkg")</c>"
    4.61  					awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" '
    4.62 @@ -196,7 +184,7 @@
    4.63  							print " "$0;
    4.64  							printf "1" >> tmp;
    4.65  						}
    4.66 -					' "$pkg/files.list"
    4.67 +					' "$FL"
    4.68  				fi
    4.69  			done
    4.70  
     5.1 --- a/modules/upgrade	Fri Aug 28 17:19:09 2015 +0300
     5.2 +++ b/modules/upgrade	Wed Sep 02 03:31:47 2015 +0300
     5.3 @@ -17,36 +17,6 @@
     5.4  . @@MODULES@@/getenv
     5.5  
     5.6  
     5.7 -
     5.8 -
     5.9 -# Functions
    5.10 -# ---------
    5.11 -
    5.12 -# Get repositories priority using $PKGS_DB/priority.
    5.13 -# In this file undigest repos are called by their names and main mirror
    5.14 -# by 'main'. Sort order: priority
    5.15 -
    5.16 -look_for_priority() {
    5.17 -	[ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority")
    5.18 -
    5.19 -	for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do
    5.20 -		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then
    5.21 -			priority=$(echo -e "$priority\n$rep")
    5.22 -		fi
    5.23 -	done
    5.24 -
    5.25 -	priority=$(echo "$priority" | sed '/^$/d' | \
    5.26 -		while read line; do
    5.27 -		case $line in
    5.28 -			(main) echo "$PKGS_DB";;
    5.29 -			(*)    echo "$PKGS_DB/undigest/$line";;
    5.30 -		esac
    5.31 -	done)
    5.32 -}
    5.33 -
    5.34 -
    5.35 -
    5.36 -
    5.37  time="$(date +%s)"
    5.38  
    5.39  # Recharge packages databases (if necessary) (respects already exported "root" value)
    5.40 @@ -56,9 +26,8 @@
    5.41  blocked_counter=$(mktemp)
    5.42  tmp_up_list=$(mktemp)
    5.43  
    5.44 -look_for_priority
    5.45  repo_number=1
    5.46 -for repo in $priority; do
    5.47 +for repo in $(tazpkg call look_for_priority); do
    5.48  	if [ "$repo" == "$PKGS_DB" ]; then
    5.49  		repo_name='Main'
    5.50  	else
     6.1 --- a/tazpkg	Fri Aug 28 17:19:09 2015 +0300
     6.2 +++ b/tazpkg	Wed Sep 02 03:31:47 2015 +0300
     6.3 @@ -173,17 +173,17 @@
     6.4  	[ -s "$PKGS_DB/priority" ] && priority=$(cat $PKGS_DB/priority)
     6.5  
     6.6  	for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
     6.7 -		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ $PKGS_DB/priority; then
     6.8 +		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ "$PKGS_DB/priority"; then
     6.9  			priority=$(echo -e "$priority\n$rep")
    6.10  		fi
    6.11  	done
    6.12 -	priority=$(echo "$priority" | sed '/^$/d' | \
    6.13 -		while read line; do
    6.14 +	echo "$priority" | sed '/^$/d' | \
    6.15 +	while read line; do
    6.16  		case $line in
    6.17 -			(main) echo $PKGS_DB;;
    6.18 -			(*)    echo $PKGS_DB/undigest/$line;;
    6.19 +			main) echo "$PKGS_DB";;
    6.20 +			*)    echo "$PKGS_DB/undigest/$line";;
    6.21  		esac
    6.22 -	done)
    6.23 +	done
    6.24  }
    6.25  
    6.26  
    6.27 @@ -357,7 +357,7 @@
    6.28  	# input: "<package_name>" or "<package_name>-<version>" (ex. "nano" or "nano-2.4.0")
    6.29  	local pkg equiv
    6.30  	for rep in $priority; do
    6.31 -		pkg=$(awk -F$'\t' -vp="$1" 'p==$1||p==$1"-"$2{print $1"-"$2}' $rep/packages.info)
    6.32 +		pkg=$(awk -F$'\t' -vp="$1" 'p==$1||p==$1"-"$2{print $1"-"$2}' "$rep/packages.info")
    6.33  
    6.34  		if [ -n "$pkg" ]; then
    6.35  			get_cache_dir; break
    6.36 @@ -979,6 +979,15 @@
    6.37  ###################
    6.38  
    6.39  case "$COMMAND" in
    6.40 +	call)
    6.41 +		# Call internal tazpkg function from external tazpkg module or other script.
    6.42 +		# Useful for functions sharing.
    6.43 +		shift
    6.44 +		# Check to call only tazpkg functions
    6.45 +		fgrep -q "$1()" "$0" && $@
    6.46 +		;;
    6.47 +
    6.48 +
    6.49  	list|-l)
    6.50  		# Various lists
    6.51  		shift
    6.52 @@ -1061,7 +1070,7 @@
    6.53  		[ -n "$list" ] && INSTALL_LIST="$list"
    6.54  
    6.55  		# Get repositories priority list.
    6.56 -		look_for_priority
    6.57 +		priority=$(look_for_priority)
    6.58  
    6.59  		# Check if forced install.
    6.60  		if [ -z "$forced" ]; then
    6.61 @@ -1358,7 +1367,7 @@
    6.62  		fi
    6.63  
    6.64  		# Get repositories priority list.
    6.65 -		look_for_priority
    6.66 +		priority=$(look_for_priority)
    6.67  
    6.68  		CURRENT_DIR="$PWD"
    6.69  		cd "$CACHE_DIR"
    6.70 @@ -1401,7 +1410,7 @@
    6.71  		[ -n "$list" ] && INSTALL_LIST="$list"					# internal option
    6.72  
    6.73  		# Get repositories priority list.
    6.74 -		look_for_priority
    6.75 +		priority=$(look_for_priority)
    6.76  
    6.77  		AUTOEXEC='no'
    6.78  		# Magic :)