tazpkg rev 386
Improvement: Add simple repository priority control with file /var/lib/tazpkg/priority
author | Antoine Bodin <gokhlayeh@slitaz.org> |
---|---|
date | Wed Dec 08 18:36:03 2010 +0100 (2010-12-08) |
parents | 85e885ecb314 |
children | 9cf5ea2f246e |
files | tazpkg |
line diff
1.1 --- a/tazpkg Wed Dec 08 16:26:45 2010 +0100 1.2 +++ b/tazpkg Wed Dec 08 18:36:03 2010 +0100 1.3 @@ -181,6 +181,28 @@ 1.4 fi 1.5 } 1.6 1.7 +# Get repositories priority using $LOCALSTATE/priority. 1.8 +# In this files, undigest are called by their name and main mirror 1.9 +# by main. Sort order : priority 1.10 +look_for_priority() 1.11 +{ 1.12 +[ -s $LOCALSTATE/priority ] && priority=$(cat $LOCALSTATE/priority) 1.13 +for rep in main $(ls $LOCALSTATE/undigest 2>/dev/null); do 1.14 + if [ ! -s $LOCALSTATE/priority ] || \ 1.15 + ! grep -q ^$rep$ $LOCALSTATE/priority; then 1.16 + priority=$(echo -e "$priority\n$rep") 1.17 + fi 1.18 +done 1.19 +priority=$(echo "$priority" | sed '/^$/d' | \ 1.20 + while read line; do 1.21 + if [ "$line" = main ]; then 1.22 + echo $LOCALSTATE 1.23 + else 1.24 + echo $LOCALSTATE/undigest/$line 1.25 + fi 1.26 +done) 1.27 +} 1.28 + 1.29 # Get package name in a directory 1.30 package_fullname_in_dir() 1.31 { 1.32 @@ -259,8 +281,9 @@ 1.33 # get a virtual package from packages.equiv 1.34 virtual_pkg() 1.35 { 1.36 - for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \ 1.37 - $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do 1.38 + for i in $(for rep in $priority; do 1.39 + grep -hs "^$1=" $rep/packages.equiv 1.40 + done | sed "s/^$1=//"); do 1.41 if echo $i | grep -q : ; then 1.42 # format 'alternative:newname' 1.43 # if alternative is installed then substitute newname 1.44 @@ -281,18 +304,17 @@ 1.45 get_package_filename() 1.46 { 1.47 local pkg 1.48 - pkg=$(grep -A 1 -sh "^$1$" $LOCALSTATE/packages.txt \ 1.49 - $LOCALSTATE/undigest/*/packages.txt | tail -1) 1.50 - pkg=$(echo $pkg) 1.51 - [ -n "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \ 1.52 - $LOCALSTATE/packages.list \ 1.53 - $LOCALSTATE/undigest/*/packages.list | head -1) 1.54 - [ -n "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \ 1.55 - $LOCALSTATE/packages.list \ 1.56 - $LOCALSTATE/undigest/*/packages.list | head -1) 1.57 - [ -n "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \ 1.58 - $LOCALSTATE/packages.list \ 1.59 - $LOCALSTATE/undigest/*/packages.list | head -1) 1.60 + for rep in $priority; do 1.61 + pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | \ 1.62 + sed 's/^ *//') 1.63 + [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \ 1.64 + $rep/packages.list | head -1) 1.65 + [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \ 1.66 + $rep/packages.list | head -1) 1.67 + [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \ 1.68 + $rep/packages.list | head -1) 1.69 + [ "$pkg" ] && break 1.70 + done 1.71 if [ -z "$pkg" ]; then 1.72 # Check for vitual package 1.73 local equiv 1.74 @@ -358,12 +380,13 @@ 1.75 local i 1.76 case "$1" in 1.77 *.tazpkg) 1.78 - for i in $LOCALSTATE $LOCALSTATE/undigest/* ; do 1.79 - grep "^${1%.tazpkg}$" $i/packages.list || continue 1.80 + for i in $priority ; do 1.81 + grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue 1.82 download_from "$(cat $i/mirror)" "$@" && return 1.83 done 1.84 esac 1.85 - for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do 1.86 + for i in $(cat `for rep in $priority; do echo $rep/mirror; done` \ 1.87 + 2> /dev/null); do 1.88 download_from "$i" "$@" && break 1.89 done 1.90 } 1.91 @@ -862,6 +885,10 @@ 1.92 install_flavor() 1.93 { 1.94 check_root 1.95 + 1.96 + # Get repositories priority list. 1.97 + look_for_priority 1.98 + 1.99 FLAVOR=$1 1.100 ARG=$2 1.101 mkdir -p $TMP_DIR 1.102 @@ -1651,6 +1678,10 @@ 1.103 check_root 1.104 check_for_package_on_cmdline 1.105 check_for_package_file 1.106 + 1.107 + # Get repositories priority list. 1.108 + look_for_priority 1.109 + 1.110 # Check if forced install. 1.111 DO_CHECK="yes" 1.112 ROOT="" 1.113 @@ -2130,6 +2161,7 @@ 1.114 # Recharge packages.list from a mirror. 1.115 # 1.116 check_root 1.117 + 1.118 for path in $LOCALSTATE $LOCALSTATE/undigest/*; do 1.119 [ -f $path/mirror ] || continue 1.120 echo "" 1.121 @@ -2206,6 +2238,10 @@ 1.122 # 1.123 check_root 1.124 check_for_packages_list 1.125 + 1.126 + # Get repositories priority list. 1.127 + look_for_priority 1.128 + 1.129 cd $LOCALSTATE 1.130 # Touch the blocked pkgs list to avoid errors and remove any old 1.131 # upgrade list. 1.132 @@ -2368,6 +2404,10 @@ 1.133 # Check installed packages set. 1.134 # 1.135 check_root 1.136 + 1.137 + # Get repositories priority list. 1.138 + look_for_priority 1.139 + 1.140 cd $INSTALLED 1.141 for PACKAGE in `ls`; do 1.142 if [ ! -f $PACKAGE/receipt ]; then 1.143 @@ -2494,6 +2534,10 @@ 1.144 # 1.145 check_for_package_on_cmdline 1.146 check_for_packages_list 1.147 + 1.148 + # Get repositories priority list. 1.149 + look_for_priority 1.150 + 1.151 check_for_package_in_list 1.152 echo "" 1.153 if [ -f $PACKAGE.tazpkg ]; then 1.154 @@ -2511,6 +2555,10 @@ 1.155 check_root 1.156 check_for_package_on_cmdline 1.157 check_for_packages_list 1.158 + 1.159 + # Get repositories priority list. 1.160 + look_for_priority 1.161 + 1.162 DO_CHECK="" 1.163 while [ -n "$3" ]; do 1.164 case "$3" in