tazpkg rev 10
Add block|unblock cmds and modified the way upgrade works
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Nov 28 13:41:59 2007 +0100 (2007-11-28) |
parents | edcb3320b2cf |
children | a39072973190 |
files | tazpkg |
line diff
1.1 --- a/tazpkg Mon Nov 26 21:20:21 2007 +0100 1.2 +++ b/tazpkg Wed Nov 28 13:41:59 2007 +0100 1.3 @@ -8,7 +8,7 @@ 1.4 # also relolv dependencies and can upgrade packages from a mirror. 1.5 # 1.6 # (C) 2007 SliTaz - GNU General Public License v3. 1.7 -# Author : <pankso@slitaz.org> 1.8 +# Initial author : <pankso@slitaz.org> 1.9 # 1.10 VERSION=1.4pre 1.11 1.12 @@ -17,12 +17,18 @@ 1.13 #################### 1.14 1.15 # Packages categories. 1.16 -CATEGORIES="base-system base-apps x-window extra" 1.17 +CATEGORIES="base-system base-apps x-window extra devel" 1.18 1.19 # Initialize some variables to use words 1.20 # rater than numbers for functions and actions. 1.21 COMMAND=$1 1.22 -PACKAGE=$(basename ${2%.tazpkg}) 1.23 +if [ -f $2 ]; then 1.24 + # Set pkg basename for install, extract 1.25 + PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null) 1.26 +else 1.27 + # Pkg name for remove, search and all other cmds 1.28 + PACKAGE=${2%.tazpkg} 1.29 +fi 1.30 PACKAGE_FILE=$2 1.31 TARGET_DIR=$3 1.32 TOP_DIR=`pwd` 1.33 @@ -34,7 +40,10 @@ 1.34 CACHE_DIR=/var/cache/tazpkg 1.35 MIRROR=$LOCALSTATE/mirror 1.36 PACKAGES_LIST=$LOCALSTATE/packages.list 1.37 +BLOCKED=$LOCALSTATE/blocked-packages.list 1.38 1.39 +# Bold red warnig for upgrade. 1.40 +WARNING="\\033[1;31mWARNING\\033[0;39m" 1.41 1.42 # Check if the directories and files used by Tazpkg 1.43 # exists. If not and user is root we creat them. 1.44 @@ -74,10 +83,11 @@ 1.45 pack Pack an unpacked or prepared package tree. 1.46 recharge Recharge your packages.list from the mirror. 1.47 upgrade Upgrade all installed and listed packages on the mirror. 1.48 + block|unblock Block an installed package version or unblock it for upgrade. 1.49 get Download a package into the current directory. 1.50 get-install Download and install a package from the mirror. 1.51 clean-cache Clean all packages downloaded in cache directory. 1.52 - setup-mirror Change the mirror url configuration.\n" 1.53 + setup-mirror Change the mirror url configuration." 1.54 } 1.55 1.56 # Status function with color (supported by Ash). 1.57 @@ -253,7 +263,7 @@ 1.58 install_deps() 1.59 { 1.60 echo "" 1.61 - echo -n "Install all missing dependencies(y/N) ? "; read anser 1.62 + echo -n "Install all missing dependencies (y/N) ? "; read anser 1.63 if [ "$anser" = "y" ]; then 1.64 for pkg in $DEPENDS 1.65 do 1.66 @@ -281,22 +291,6 @@ 1.67 fi 1.68 } 1.69 1.70 -# Sed package version temp file. we need 123 not 1.2.3 to use -gt. Few 1.71 -# pacakges also use letters, so a is 1, b is 2, c is 3, etc. 1.72 -# 1.73 -sed_tmpfile() 1.74 -{ 1.75 - sed -i s/"$PACKAGE-"/''/ $tmpfile 1.76 - sed -i s/'\.'//g $tmpfile 1.77 - sed -i s/'-'//g $tmpfile 1.78 - sed -i s/'pre'// $tmpfile 1.79 - sed -i s/'a'/'1'/ $tmpfile 1.80 - sed -i s/'b'/'2'/ $tmpfile 1.81 - sed -i s/'c'/'3'/ $tmpfile 1.82 - sed -i s/'d'/'4'/ $tmpfile 1.83 - sed -i s/'e'/'5'/ $tmpfile 1.84 -} 1.85 - 1.86 ################### 1.87 # Tazpkg commands # 1.88 ################### 1.89 @@ -649,6 +643,9 @@ 1.90 check_root 1.91 check_for_packages_list 1.92 cd $LOCALSTATE 1.93 + # Touch the blocked pkgs list to avoid errors and remove any old 1.94 + # upgrade list. 1.95 + touch blocked-packages.list 1.96 rm -f upradable-packages.list 1.97 echo "" 1.98 echo -e "\033[1mAvalaible upgrade\033[0m" 1.99 @@ -656,47 +653,76 @@ 1.100 for pkg in $INSTALLED/* 1.101 do 1.102 . $pkg/receipt 1.103 - # We need a temp file to sed the package version. 1.104 - tmpfile=/tmp/pkg.version 1.105 - # Check if the installed package is in the current list (other 1.106 - # mirror or local). 1.107 - if grep -q "^$PACKAGE-[0-9]" packages.list; then 1.108 - newpkg=`grep ^$PACKAGE-[0-9] packages.list` 1.109 - # Get last and current version without points using 1.110 - # function sed_tmpfile(). 1.111 - echo $newpkg > $tmpfile 1.112 - sed_tmpfile 1.113 - NEW_VERSION=`cat $tmpfile` 1.114 - echo $VERSION > $tmpfile 1.115 - sed_tmpfile 1.116 - CURRENT_VERSION=`cat $tmpfile` 1.117 - # Compare version. 1.118 - if [ "$NEW_VERSION" -gt "$CURRENT_VERSION" ]; then 1.119 - echo $newpkg > $tmpfile 1.120 - sed -i s/"$PACKAGE-"/''/ $tmpfile 1.121 - newversion=`cat $tmpfile` 1.122 - rm -f $tmpfile 1.123 - echo -n "$PACKAGE" 1.124 - echo -en "\033[24G $VERSION" 1.125 - echo -en "\033[38G --->" 1.126 - echo -en "\033[48G $newversion" 1.127 - echo -e "\033[68G $CATEGORY" 1.128 - up=$(($up+1)) 1.129 - echo "$PACKAGE" >> upradable-packages.list 1.130 + # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list 1.131 + if grep -q "^$PACKAGE" $BLOCKED; then 1.132 + blocked=$(($blocked+1)) 1.133 + else 1.134 + # Check if the installed package is in the current list (other 1.135 + # mirror or local). 1.136 + if grep -q "^$PACKAGE-[0-9]" packages.list; then 1.137 + # Set new kg and version for futur comparaison 1.138 + NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list` 1.139 + NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/` 1.140 + # Compare version. Upgrade are only avalaible for official 1.141 + # packages, so we control de mirror and it should be ok if 1.142 + # we just check for egality. 1.143 + if [ "$VERSION" != "$NEW_VERSION" ]; then 1.144 + # Version seems different. Check for major, minor or 1.145 + # revision 1.146 + PKG_MAJOR=`echo $VERSION | cut -f1 -d"."` 1.147 + NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."` 1.148 + PKG_MINOR=`echo $VERSION | cut -f2 -d"."` 1.149 + NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."` 1.150 + # Major 1.151 + if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then 1.152 + RELEASE=major 1.153 + fi 1.154 + if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then 1.155 + RELEASE=$WARNING 1.156 + FIXE=yes 1.157 + fi 1.158 + # Minor 1.159 + if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then 1.160 + RELEASE=minor 1.161 + fi 1.162 + if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then 1.163 + RELEASE=$WARNING 1.164 + FIXE=yes 1.165 + fi 1.166 + # Default to revision. 1.167 + if [ -z $RELEASE ]; then 1.168 + RELEASE=revision 1.169 + fi 1.170 + echo -n "$PACKAGE" 1.171 + echo -en "\033[24G $VERSION" 1.172 + echo -en "\033[38G --->" 1.173 + echo -en "\033[48G $NEW_VERSION" 1.174 + echo -en "\033[60G $CATEGORY" 1.175 + echo -e "\033[72G $RELEASE" 1.176 + up=$(($up+1)) 1.177 + echo "$PACKAGE" >> upradable-packages.list 1.178 + fi 1.179 + packages=$(($packages+1)) 1.180 fi 1.181 - packages=$(($packages+1)) 1.182 - fi 1.183 + fi 1.184 done 1.185 rm -f $tmpfile 1.186 if [ ! "$up" = "" ]; then 1.187 echo "================================================================================" 1.188 - echo "$packages installed and listed packages to consider, $up to upgrade." 1.189 + echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked." 1.190 echo "" 1.191 else 1.192 - echo "$packages installed and listed packages to consider, 0 to upgrade." 1.193 + echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked." 1.194 echo "" 1.195 exit 0 1.196 fi 1.197 + # What to do if major or minor version is smaller. 1.198 + if [ "$FIXE" == "yes" ]; then 1.199 + echo -e "$WARNING ---> Installed package seems more recent than the mirrored one." 1.200 + echo "You can block packages using the command : 'tazpkg block package'" 1.201 + echo "Or upgrade package at you own risks." 1.202 + echo "" 1.203 + fi 1.204 # Ask for upgrade, it can be done an other time. 1.205 echo -n "Upgrade now (y/N) ? "; read anser 1.206 if [ ! "$anser" = "y" ]; then 1.207 @@ -709,6 +735,41 @@ 1.208 tazpkg get-install $pkg --forced 1.209 done 1.210 ;; 1.211 + block) 1.212 + # Add a pkg name to the list of blocked packages. 1.213 + # 1.214 + check_root 1.215 + check_for_package_on_cmdline 1.216 + echo "" 1.217 + if grep -q "^$PACKAGE" $BLOCKED; then 1.218 + echo "$PACKAGE is already in the blocked packages list." 1.219 + echo "" 1.220 + exit 0 1.221 + else 1.222 + echo -n "Add $PACKAGE to : $BLOCKED..." 1.223 + echo $PACKAGE >> $BLOCKED 1.224 + status 1.225 + fi 1.226 + echo "" 1.227 + ;; 1.228 + unblock) 1.229 + # Remove a pkg name to the list of blocked packages. 1.230 + # 1.231 + check_root 1.232 + check_for_package_on_cmdline 1.233 + echo "" 1.234 + if grep -q "^$PACKAGE" $BLOCKED; then 1.235 + echo -n "Removing $PACKAGE from : $BLOCKED..." 1.236 + sed -i s/$PACKAGE/''/ $BLOCKED 1.237 + sed -i '/^$/d' $BLOCKED 1.238 + status 1.239 + else 1.240 + echo "$PACKAGE is not in the blocked packages list." 1.241 + echo "" 1.242 + exit 0 1.243 + fi 1.244 + echo "" 1.245 + ;; 1.246 get) 1.247 # Downlowd a package with wget. 1.248 #