tazpkg rev 701
Introduce installed.info; use it with 'list', 'install' and 'remove' commands for maximum speed.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Dec 04 13:57:43 2014 +0200 (2014-12-04) |
parents | 1d7f3c9ce99c |
children | 0e50306e492a |
files | tazpkg |
line diff
1.1 --- a/tazpkg Thu Dec 04 01:41:59 2014 +0200 1.2 +++ b/tazpkg Thu Dec 04 13:57:43 2014 +0200 1.3 @@ -55,6 +55,20 @@ 1.4 done 1.5 1.6 1.7 +# Translate category names (must be last in line) 1.8 + 1.9 +translate_category() 1.10 +{ 1.11 + sed "s|base-system$|$(_ base-system)|g; s|x-window$|$(_ x-window)|g; 1.12 + s|utilities$|$(_ utilities)|g; s|network$|$(_ network)|g; 1.13 + s|graphics$|$(_ graphics)|g; s|multimedia$|$(_ multimedia)|g; 1.14 + s|office$|$(_ office)|g; s|development$|$(_ development)|g; 1.15 + s|system-tools$|$(_ system-tools)|g; s|security$|$(_ security)|g; 1.16 + s|games$|$(_ games)|g; s|misc$|$(_ misc)|g; s|meta$|$(_ meta)|g; 1.17 + s|non-free$|$(_ non-free)|g" 1.18 +} 1.19 + 1.20 + 1.21 # If category is not one of those translated in native language, keep it 1.22 # untranslated. This allows both native and english language support. 1.23 # This also supports custom categories. 1.24 @@ -361,6 +375,33 @@ 1.25 } 1.26 1.27 1.28 +# Check for installed.info - local file with format of packages.info 1.29 +# It absent on not clean installs; check it and re-generate if needed. 1.30 + 1.31 +check_for_installed_info() 1.32 +{ 1.33 + info_path="$PKGS_DB/installed.info" 1.34 + if [ ! -f "$info_path" ]; then 1.35 + if [ "$(id -u)" == "0" ]; then 1.36 + _ 'File installed.info generated. Please wait...' 1.37 + for pkg in $PKGS_DB/installed/*/receipt; do 1.38 + unset_receipt 1.39 + . $pkg 1.40 + SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') 1.41 + DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts 1.42 + cat >> $info_path << EOT 1.43 +$PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS 1.44 +EOT 1.45 + done 1.46 + else 1.47 + _ 'Unable to find: installed.info' 1.48 + _ 'Please run tazpkg as root.' 1.49 + exit 1 1.50 + fi 1.51 + fi 1.52 +} 1.53 + 1.54 + 1.55 get_cache_dir() 1.56 { 1.57 echo $rep > $tmp/rep 1.58 @@ -608,6 +649,7 @@ 1.59 mkdir -p $TMP_DIR 1.60 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE 1.61 . $TMP_DIR/receipt 1.62 + # FIXME: legacy? 1.63 if grep -q ^pre_depends $TMP_DIR/receipt; then 1.64 pre_depends $ROOT 1.65 fi 1.66 @@ -653,6 +695,7 @@ 1.67 . $PWD/receipt 1.68 cd $ROOT$INSTALLED 1.69 1.70 + # FIXME: legacy? 1.71 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then 1.72 action "Checking post install dependencies..." 1.73 [ -f $INSTALLED/$PACKAGE/receipt ] 1.74 @@ -804,6 +847,13 @@ 1.75 updatedepmod=yes 1.76 fi 1.77 1.78 + # Update installed.info 1.79 + SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') 1.80 + DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts 1.81 + cat >> $PKGS_DB/installed.info << EOT 1.82 +$PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS 1.83 +EOT 1.84 + 1.85 cd $TOP_DIR 1.86 pkg_name="$PACKAGE ($VERSION$EXTRAVERSION)" 1.87 footer "$(_ '$pkg_name is installed.')" 1.88 @@ -1305,67 +1355,65 @@ 1.89 1.90 case "$COMMAND" in 1.91 list|-l) 1.92 + # List all installed packages or a specific category. 1.93 shift 1.94 - 1.95 - # List all installed packages or a specific category. 1.96 - if [ "$1" = "blocked" ]; then 1.97 - title 'Blocked packages' 1.98 - if [ -s "$BLOCKED" ];then 1.99 - cat $BLOCKED 1.100 - else 1.101 - _ 'No blocked packages found.' 1.102 - fi 1.103 - newline; exit 0 1.104 - fi 1.105 - 1.106 - # Display the list of categories. 1.107 - if [ "$1" = "cat" -o "$1" = "categories" ]; then 1.108 - title 'Packages categories' 1.109 - num=0 1.110 - for i in $PKGS_CATEGORIES; do 1.111 - _ $i 1.112 - num=$(($num+1)) 1.113 - done 1.114 - footer "$(eval_ngettext '$num category' '$num categories' $num)"; echo 1.115 - exit 0 1.116 - fi 1.117 - 1.118 - # Check for an asked category. 1.119 - ASKED_CATEGORY_I18N="$@" 1.120 - if [ -n "$ASKED_CATEGORY_I18N" ]; then 1.121 - ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N") 1.122 - title 'Installed packages of category: $ASKED_CATEGORY_I18N' 1.123 - for pkg in $INSTALLED/*; do 1.124 - [ -f $pkg/receipt ] || continue 1.125 - EXTRAVERSION="" 1.126 - . $pkg/receipt 1.127 - if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then 1.128 - echo -e "$PACKAGE\033[24G $VERSION$EXTRAVERSION" 1.129 - packages=$(($packages+1)) 1.130 + check_for_installed_info 1.131 + 1.132 + case $1 in 1.133 + b|blocked) 1.134 + # Display the list of blocked packages. 1.135 + title 'Blocked packages' 1.136 + if [ -s "$BLOCKED" ];then 1.137 + cat $BLOCKED 1.138 + else 1.139 + _ 'No blocked packages found.' 1.140 fi 1.141 - done 1.142 - num="<c 32>$packages</c>"; cat_name="<c 34>$ASKED_CATEGORY_I18N</c>" 1.143 - footer "$(emsg $(eval_ngettext \ 1.144 - '$num package installed of category $cat_name.' \ 1.145 - '$num packages installed of category $cat_name.' \ 1.146 - $packages))"; echo 1.147 - else 1.148 - 1.149 - # By default list all packages and versions. 1.150 - title 'List of all installed packages' 1.151 - for pkg in $INSTALLED/*; do 1.152 - [ -f $pkg/receipt ] || continue 1.153 - EXTRAVERSION="" 1.154 - . $pkg/receipt 1.155 - echo -e "$PACKAGE\033[35G $VERSION$EXTRAVERSION\033[53G $(_ $CATEGORY)" 1.156 - packages=$(($packages+1)) 1.157 - done 1.158 - num="<c 32>$packages</c>" 1.159 - footer "$(emsg $(eval_ngettext \ 1.160 - '$num package installed.' \ 1.161 - '$num packages installed.' $packages))" 1.162 - fi ;; 1.163 - 1.164 + newline; exit 0 1.165 + ;; 1.166 + c|cat|categories) 1.167 + # Display the list of categories. 1.168 + title 'Packages categories' 1.169 + echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \ 1.170 + sed 's|\(.*\)|\1'$'\033''[15G \1|' | translate_category 1.171 + num=$(echo -n "$PKGS_CATEGORIES" | wc -l) 1.172 + footer "$(eval_ngettext '$num category' '$num categories' $num)"; echo 1.173 + exit 0 1.174 + ;; 1.175 + '') 1.176 + # By default list all packages and versions. 1.177 + title 'List of all installed packages' 1.178 + TMPLIST=$(mktemp) 1.179 + awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \ 1.180 + $PKGS_DB/installed.info | tee $TMPLIST | translate_category 1.181 + 1.182 + packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST 1.183 + num="<c 32>$packages</c>" 1.184 + footer "$(emsg $(eval_ngettext \ 1.185 + '$num package installed.' \ 1.186 + '$num packages installed.' $packages))" 1.187 + ;; 1.188 + *) 1.189 + # Check for an asked category. 1.190 + ASKED_CATEGORY_I18N="$@" 1.191 + ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N") 1.192 + title 'Installed packages of category: $ASKED_CATEGORY_I18N' 1.193 + TMPLIST=$(mktemp) 1.194 + awk -F$'\t' ' 1.195 + { 1.196 + if ($3 == "'$ASKED_CATEGORY'") 1.197 + print $1"\033[35G "$2 1.198 + }' \ 1.199 + $PKGS_DB/installed.info | tee $TMPLIST | translate_category 1.200 + 1.201 + packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST 1.202 + num="<c 32>$packages</c>" 1.203 + cat_name="<c 34>$ASKED_CATEGORY_I18N</c>" 1.204 + footer "$(emsg $(eval_ngettext \ 1.205 + '$num package installed of category $cat_name.' \ 1.206 + '$num packages installed of category $cat_name.' \ 1.207 + $packages))"; echo 1.208 + ;; 1.209 + esac ;; 1.210 1.211 list-mirror|-lm) 1.212 # List all available packages on the mirror. Option --diff displays 1.213 @@ -1597,6 +1645,7 @@ 1.214 check_root $@ 1.215 check_for_package_on_cmdline 1.216 check_for_package_file 1.217 + check_for_installed_info 1.218 1.219 [ "$root" ] && ROOT="$root" && check_base_dir "$root" 1.220 [ "$list" ] && INSTALL_LIST="$list" 1.221 @@ -1713,6 +1762,7 @@ 1.222 # Remove packages. 1.223 check_root $@ 1.224 check_for_package_on_cmdline 1.225 + check_for_installed_info 1.226 1.227 [ -n "$root" ] && ROOT="$root" 1.228 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then 1.229 @@ -1785,8 +1835,12 @@ 1.230 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \ 1.231 $PKGS_DB/installed.$SUM 2> /dev/null 1.232 1.233 + # Update installed.info 1.234 + sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info 1.235 + 1.236 # Log this activity 1.237 log_pkg Removed 1.238 + 1.239 if [ "$ALTERED" ]; then 1.240 if [ "$auto" ]; then 1.241 answer=0 1.242 @@ -2168,7 +2222,7 @@ 1.243 sed -i s/+// packages.diff 1.244 title 'Mirrored packages diff' 1.245 cat packages.diff 1.246 - new_pkgs=$(wc -l packages.diff) 1.247 + new_pkgs=$(wc -l < packages.diff) 1.248 if [ "$new_pkgs" != 0 ]; then 1.249 num=$(emsg "<c 32>$new_pkgs</c>") 1.250 footer "$(eval_ngettext \