tazpkg view 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 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
13 alias cpio='busybox cpio'
18 # Get repositories priority using $PKGS_DB/priority.
19 # In this file undigest repos are called by their names and main mirror
20 # by 'main'. Sort order: priority
22 look_for_priority() {
23 [ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority")
25 for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do
26 if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then
27 priority=$(echo -e "$priority\n$rep")
28 fi
29 done
31 priority=$(echo "$priority" | sed '/^$/d' | \
32 while read line; do
33 case $line in
34 (main) echo "$PKGS_DB";;
35 (*) echo "$PKGS_DB/undigest/$line";;
36 esac
37 done)
38 }
41 # Download a file from this mirror
43 download_from() {
44 case "$1" in
45 # Mirror URL can have a trailing slash or not.
46 http://* | https://* | ftp://*)
47 busybox wget -c -q -T 30 -U $UA ${1%/}/$2 2>/dev/null && break ;;
48 *)
49 ln -sf ${1%/}/$2 . && break ;;
50 esac
51 }
54 # Download a file trying all mirrors
56 download() {
57 # input: <package_name>-<version>.tazpkg
58 local i
59 case "$1" in
60 *.tazpkg)
61 for i in $priority; do
62 if [ -n "$(awk -F$'\t' -vp="$1" 'p==$1"-"$2".tazpkg"{print $1}' \
63 "$i/packages.info")" ]; then
64 download_from "$(cat $i/mirror)" "$@" && return
65 fi
66 done
67 ;;
68 esac
70 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
71 download_from "$i" "$@" && break
72 done
73 }
78 # Get repositories priority list.
79 look_for_priority
81 FLAVOR="$1"
82 TMP_DIR=$(mktemp -d)
84 [ -f "$FLAVOR.flavor" ] && cp "$FLAVOR.flavor" "$TMP_DIR"
86 cd "$TMP_DIR"
87 if [ -f "$FLAVOR.flavor" ] || download "$FLAVOR.flavor"; then
88 zcat < "$FLAVOR.flavor" | cpio --quiet -i >/dev/null
90 while read file; do
91 # 'file' here in form 'package-version'
92 is_installed=$(awk -F$'\t' -vf="$file" '$1 "-" $2 == f {print 1}' "$PKGS_DB/installed.info")
93 [ -n "$is_installed" ] && continue
95 # Install package if it not installed or has a different version
96 cd "$CACHE_DIR"
97 download "$file.tazpkg"
98 cd "$TMP_DIR"
99 tazpkg install "$CACHE_DIR/$file.tazpkg" --forced
100 done < "$FLAVOR.pkglist"
102 [ -f "$FLAVOR.nonfree" ] && \
103 while read pkg; do
104 [ -d "$INSTALLED/$pkg" ] && continue
105 [ ! -d "$INSTALLED/get-$pkg" ] && tazpkg get-install get-$pkg
106 get-$pkg
107 done < "$FLAVOR.nonfree"
109 # Option "--purge"
110 [ -n "$purge" ] && \
111 for pkg in $(awk -F$'\t' '{printf "%s:%s ", $1, $2}' "$PKGS_DB/installed.info"); do
112 # If installed 'package-version' listed in 'pkglist'
113 grep -q "^${pkg/:/-}$" "$FLAVOR.pkglist" && continue
114 # If installed 'package' listed in 'nonfree'
115 grep -qs "^${pkg%:*}$" "$FLAVOR.nonfree" && continue
116 # Remove other packages
117 tazpkg remove "${pkg%:*}"
118 done
119 else
120 _ "Can't find flavor \"%s\". Abort." "$FLAVOR"
121 fi
122 cd "$TOP_DIR"
123 rm -rf "$TMP_DIR"