tazpkg diff modules/flavor @ rev 840

Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Aug 28 16:10:34 2015 +0300 (2015-08-28)
parents
children 0560ba4306a1
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/flavor	Fri Aug 28 16:10:34 2015 +0300
     1.3 @@ -0,0 +1,123 @@
     1.4 +#!/bin/sh
     1.5 +# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
     1.6 +# flavor - TazPkg module
     1.7 +# Install package-list from a flavor
     1.8 +
     1.9 +
    1.10 +# Connect function libraries
    1.11 +. /lib/libtaz.sh
    1.12 +
    1.13 +# Get TazPkg working environment
    1.14 +. @@MODULES@@/getenv
    1.15 +
    1.16 +alias cpio='busybox cpio'
    1.17 +
    1.18 +
    1.19 +
    1.20 +
    1.21 +# Get repositories priority using $PKGS_DB/priority.
    1.22 +# In this file undigest repos are called by their names and main mirror
    1.23 +# by 'main'. Sort order: priority
    1.24 +
    1.25 +look_for_priority() {
    1.26 +	[ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority")
    1.27 +
    1.28 +	for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do
    1.29 +		if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then
    1.30 +			priority=$(echo -e "$priority\n$rep")
    1.31 +		fi
    1.32 +	done
    1.33 +
    1.34 +	priority=$(echo "$priority" | sed '/^$/d' | \
    1.35 +		while read line; do
    1.36 +		case $line in
    1.37 +			(main) echo "$PKGS_DB";;
    1.38 +			(*)    echo "$PKGS_DB/undigest/$line";;
    1.39 +		esac
    1.40 +	done)
    1.41 +}
    1.42 +
    1.43 +
    1.44 +# Download a file from this mirror
    1.45 +
    1.46 +download_from() {
    1.47 +	case "$1" in
    1.48 +		# Mirror URL can have a trailing slash or not.
    1.49 +		http://* | https://* | ftp://*)
    1.50 +			busybox wget -c -q -T 30 -U $UA ${1%/}/$2 2>/dev/null && break ;;
    1.51 +		*)
    1.52 +			ln -sf ${1%/}/$2 . && break ;;
    1.53 +	esac
    1.54 +}
    1.55 +
    1.56 +
    1.57 +# Download a file trying all mirrors
    1.58 +
    1.59 +download() {
    1.60 +	# input: <package_name>-<version>.tazpkg
    1.61 +	local i
    1.62 +	case "$1" in
    1.63 +		*.tazpkg)
    1.64 +			for i in $priority; do
    1.65 +				if [ -n "$(awk -F$'\t' -vp="$1" 'p==$1"-"$2".tazpkg"{print $1}' \
    1.66 +					"$i/packages.info")" ]; then
    1.67 +					download_from "$(cat $i/mirror)" "$@" && return
    1.68 +				fi
    1.69 +			done
    1.70 +			;;
    1.71 +	esac
    1.72 +
    1.73 +	for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
    1.74 +		download_from "$i" "$@" && break
    1.75 +	done
    1.76 +}
    1.77 +
    1.78 +
    1.79 +
    1.80 +
    1.81 +# Get repositories priority list.
    1.82 +look_for_priority
    1.83 +
    1.84 +FLAVOR="$1"
    1.85 +TMP_DIR=$(mktemp -d)
    1.86 +
    1.87 +[ -f "$FLAVOR.flavor" ] && cp "$FLAVOR.flavor" "$TMP_DIR"
    1.88 +
    1.89 +cd "$TMP_DIR"
    1.90 +if [ -f "$FLAVOR.flavor" ] || download "$FLAVOR.flavor"; then
    1.91 +	zcat < "$FLAVOR.flavor" | cpio --quiet -i >/dev/null
    1.92 +
    1.93 +	while read file; do
    1.94 +		# 'file' here in form 'package-version'
    1.95 +		is_installed=$(awk -F$'\t' -vf="$file" '$1 "-" $2 == f {print 1}' "$PKGS_DB/installed.info")
    1.96 +		[ -n "$is_installed" ] && continue
    1.97 +
    1.98 +		# Install package if it not installed or has a different version
    1.99 +		cd "$CACHE_DIR"
   1.100 +		download "$file.tazpkg"
   1.101 +		cd "$TMP_DIR"
   1.102 +		tazpkg install "$CACHE_DIR/$file.tazpkg" --forced
   1.103 +	done < "$FLAVOR.pkglist"
   1.104 +
   1.105 +	[ -f "$FLAVOR.nonfree" ] && \
   1.106 +	while read pkg; do
   1.107 +		[ -d "$INSTALLED/$pkg" ] && continue
   1.108 +		[ ! -d "$INSTALLED/get-$pkg" ] && tazpkg get-install get-$pkg
   1.109 +		get-$pkg
   1.110 +	done < "$FLAVOR.nonfree"
   1.111 +
   1.112 +	# Option "--purge"
   1.113 +	[ -n "$purge" ] && \
   1.114 +	for pkg in $(awk -F$'\t' '{printf "%s:%s ", $1, $2}' "$PKGS_DB/installed.info"); do
   1.115 +		# If installed 'package-version' listed in 'pkglist'
   1.116 +		grep -q "^${pkg/:/-}$" "$FLAVOR.pkglist" && continue
   1.117 +		# If installed 'package' listed in 'nonfree'
   1.118 +		grep -qs "^${pkg%:*}$" "$FLAVOR.nonfree" && continue
   1.119 +		# Remove other packages
   1.120 +		tazpkg remove "${pkg%:*}"
   1.121 +	done
   1.122 +else
   1.123 +	_ "Can't find flavor \"%s\". Abort." "$FLAVOR"
   1.124 +fi
   1.125 +cd "$TOP_DIR"
   1.126 +rm -rf "$TMP_DIR"