tazpkg view modules/flavor @ rev 955

modules/search: allow search file with dash at start: tazpkg -sf "-spi"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 22 00:02:54 2017 +0200 (2017-12-22)
parents 8a73a58ed3cb
children
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # flavor - TazPkg module
4 # Install package-list from a flavor
7 # Connect function libraries
8 . /lib/libtaz.sh
10 # Get TazPkg working environment
11 . @@MODULES@@/getenv
16 # Download a file from this mirror
18 download_from() {
19 case "$1" in
20 # Mirror URL can have a trailing slash or not.
21 http://* | https://* | ftp://*)
22 wget -c -q -T 30 -U $UA ${1%/}/$2 2>/dev/null && break ;;
23 *)
24 ln -sf ${1%/}/$2 . && break ;;
25 esac
26 }
29 # Download a file trying all mirrors
31 download() {
32 # input: <package_name>-<version>.tazpkg
33 local i
34 case "$1" in
35 *.tazpkg)
36 for i in $PRIORITY; do
37 if [ -n "$(awk -F$'\t' -vp="$1" 'p==$1"-"$2".tazpkg"{print $1}' \
38 "$i/packages.info")" ]; then
39 download_from "$(cat $i/mirror)" "$@" && return
40 fi
41 done
42 ;;
43 esac
45 for i in $(cat $(for rep in $PRIORITY; do echo $rep/mirror; done) 2>/dev/null); do
46 download_from "$i" "$@" && break
47 done
48 }
53 FLAVOR="$1"
54 TMP_DIR=$(mktemp -d)
56 [ -f "$FLAVOR.flavor" ] && cp "$FLAVOR.flavor" "$TMP_DIR"
58 cd "$TMP_DIR"
59 if [ -f "$FLAVOR.flavor" ] || download "$FLAVOR.flavor"; then
60 zcat < "$FLAVOR.flavor" | cpio --quiet -i >/dev/null
62 while read pkgver; do
63 # 'pkgver' here in form 'package-version'
64 awk -F$'\t' -vf="$pkgver" '$1 "-" $2 == f {exit 1}' "$PKGS_DB/installed.info"
65 # Continue if package already installed
66 [ "$?" -eq 1 ] && continue
68 # Install package if it's not installed or has a different version
69 cd "$CACHE_DIR"
70 download "$pkgver.tazpkg"
71 cd "$TMP_DIR"
72 tazpkg install "$CACHE_DIR/$pkgver.tazpkg" --forced
73 done < "$FLAVOR.pkglist"
75 [ -f "$FLAVOR.nonfree" ] && \
76 while read pkg; do
77 [ -d "$INSTALLED/$pkg" ] && continue
78 [ ! -d "$INSTALLED/get-$pkg" ] && tazpkg get-install get-$pkg
79 get-$pkg
80 done < "$FLAVOR.nonfree"
82 # Option "--purge"
83 # FIXME: respect all the installed dependencies of the flavored packages
84 [ -n "$purge" ] && \
85 for pkg in $(awk -F$'\t' '{printf "%s:%s ", $1, $2}' "$PKGS_DB/installed.info"); do
86 # If installed 'package-version' listed in 'pkglist'
87 grep -q "^${pkg/:/-}$" "$FLAVOR.pkglist" && continue
88 # If installed 'package' listed in 'nonfree'
89 grep -qs "^${pkg%:*}$" "$FLAVOR.nonfree" && continue
90 # Remove other packages
91 tazpkg remove "${pkg%:*}"
92 done
93 else
94 _ "Can't find flavor \"%s\". Abort." "$FLAVOR"
95 fi
96 cd "$TOP_DIR"
97 rm -rf "$TMP_DIR"