tazpkg annotate modules/list @ rev 846
Remove "busybox" "prefixes" (thanks llev)
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Oct 09 13:14:01 2015 +0300 (2015-10-09) |
parents | 48496086d8c9 |
children | 45d90da42ede |
rev | line source |
---|---|
al@828 | 1 #!/bin/sh |
al@828 | 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg |
al@828 | 3 # list - TazPkg module |
al@828 | 4 # Produce various lists |
al@828 | 5 |
al@828 | 6 |
al@828 | 7 # Commands and options: |
al@828 | 8 # blocked List of blocked packages |
al@828 | 9 # categories List of categories |
al@828 | 10 # linked List of linked packages |
al@828 | 11 # installed List of installed packages |
al@828 | 12 # installed_of_category <category> List of installed packages of asked category |
al@828 | 13 # mirrored List packages available on the mirror |
al@828 | 14 # mirrored --diff Last mirrored packages diff |
al@828 | 15 # installed_files List files installed with the package |
al@828 | 16 # activity TazPkg activity log |
al@828 | 17 # activity --nb=30 Show asked number of lines of TazPkg activity log |
al@828 | 18 # config_files [<package>] List configuration files installed |
al@828 | 19 # config_files [<package>] --box List formatted for Yad-based TazPkg boxes |
al@828 | 20 # suggested List of suggested packages (not installed only) |
al@828 | 21 # suggested --all List of suggested packages (both installed and not installed) |
al@828 | 22 |
al@828 | 23 |
al@828 | 24 # Connect function libraries |
al@828 | 25 . /lib/libtaz.sh |
al@840 | 26 |
al@840 | 27 # Get TazPkg working environment |
al@840 | 28 . @@MODULES@@/getenv |
al@840 | 29 |
al@840 | 30 |
al@828 | 31 |
al@828 | 32 |
al@828 | 33 # Interactive mode |
al@828 | 34 |
al@828 | 35 im() { tty -s; } |
al@828 | 36 |
al@828 | 37 |
al@828 | 38 # Functions set for translate categories |
al@828 | 39 # -------------------------------------- |
al@828 | 40 |
al@828 | 41 # Translate category names (must be last in line) |
al@828 | 42 |
al@828 | 43 translate_category() { |
al@832 | 44 sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|; |
al@832 | 45 s|utilities$|$(_ utilities)|; s|network$|$(_ network)|; |
al@832 | 46 s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|; |
al@832 | 47 s|office$|$(_ office)|; s|development$|$(_ development)|; |
al@832 | 48 s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|; |
al@832 | 49 s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|; |
al@832 | 50 s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|" |
al@828 | 51 } |
al@828 | 52 |
al@828 | 53 |
al@828 | 54 # Make array of pre-translated categories |
al@828 | 55 |
al@828 | 56 cat_i18n='' |
al@828 | 57 for c in 'base-system' 'x-window' 'utilities' 'network' 'graphics' \ |
al@828 | 58 'multimedia' 'office' 'development' 'system-tools' 'security' 'games' \ |
al@828 | 59 'misc' 'meta' 'non-free'; do |
al@828 | 60 cat_i18n="$cat_i18n |
al@828 | 61 $(gettext "$c") $c" |
al@828 | 62 done |
al@828 | 63 |
al@828 | 64 |
al@828 | 65 # If category is not one of those translated in native language, keep it |
al@828 | 66 # untranslated. This allows both native and English language support. |
al@828 | 67 # This also supports custom categories. |
al@828 | 68 # And now we support spaces in translated categories |
al@828 | 69 |
al@828 | 70 reverse_translate_category() { |
al@828 | 71 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}" |
al@828 | 72 } |
al@828 | 73 |
al@828 | 74 |
al@828 | 75 # Main code |
al@828 | 76 # --------- |
al@828 | 77 |
al@828 | 78 case $1 in |
al@828 | 79 |
al@828 | 80 blocked) |
al@828 | 81 # List of blocked packages |
al@828 | 82 title 'Blocked packages' |
al@828 | 83 |
al@828 | 84 if [ -s "$BLOCKED" ];then |
al@840 | 85 cat "$BLOCKED" |
al@840 | 86 num=$(wc -l < "$BLOCKED") |
al@828 | 87 footer "$(_p '%s package' '%s packages' "$num" \ |
al@828 | 88 "$(colorize 31 $num)")" |
al@828 | 89 else |
al@828 | 90 _ 'No blocked packages found.'; newline |
al@828 | 91 fi |
al@828 | 92 ;; |
al@828 | 93 |
al@828 | 94 |
al@828 | 95 categories) |
al@828 | 96 # List of categories |
al@828 | 97 title 'Packages categories' |
al@828 | 98 |
al@828 | 99 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \ |
al@828 | 100 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{ |
al@828 | 101 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}' |
al@828 | 102 |
al@828 | 103 num=$(echo -n "$PKGS_CATEGORIES" | wc -l) |
al@828 | 104 footer "$(_p '%s category' '%s categories' "$num" \ |
al@828 | 105 "$(colorize 33 $num)")" |
al@828 | 106 ;; |
al@828 | 107 |
al@828 | 108 |
al@828 | 109 linked) |
al@828 | 110 # List of linked packages |
al@828 | 111 title 'Linked packages' |
al@828 | 112 |
al@840 | 113 linked="$(find "$INSTALLED" -type l -maxdepth 1)" |
al@828 | 114 if [ -n "$linked" ]; then |
al@828 | 115 for pkg in $linked; do |
al@828 | 116 awk -F$'\t' -vp="$(basename "$pkg")" \ |
al@840 | 117 '$1==p{printf "%-34s %-17s %s\n", $1, $2, $3}' \ |
al@840 | 118 "$PKGS_DB/installed.info" | translate_category |
al@828 | 119 done |
al@828 | 120 num=$(echo "$linked" | wc -l) |
al@828 | 121 footer "$(_p '%s package' '%s packages' "$num" \ |
al@828 | 122 "$(colorize 31 $num)")" |
al@828 | 123 else |
al@828 | 124 _ 'No linked packages found.'; newline |
al@828 | 125 fi |
al@828 | 126 ;; |
al@828 | 127 |
al@828 | 128 |
al@828 | 129 installed) |
al@828 | 130 # List of installed packages |
al@828 | 131 title 'List of all installed packages' |
al@828 | 132 |
al@828 | 133 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \ |
al@840 | 134 "$PKGS_DB/installed.info" | translate_category |
al@840 | 135 num=$(wc -l < "$PKGS_DB/installed.info") |
al@828 | 136 |
al@828 | 137 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \ |
al@828 | 138 "$(colorize 32 $num)")" |
al@828 | 139 ;; |
al@828 | 140 |
al@828 | 141 |
al@828 | 142 installed_of_category) |
al@828 | 143 # List of installed packages of asked category |
al@828 | 144 shift |
al@828 | 145 ASKED_CATEGORY_I18N="$@" |
al@828 | 146 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N") |
al@828 | 147 title 'Installed packages of category "%s"' "$ASKED_CATEGORY_I18N" |
al@828 | 148 |
al@828 | 149 TMPLIST=$(mktemp) |
al@828 | 150 awk -F$'\t' -vcat="$ASKED_CATEGORY" \ |
al@840 | 151 '$3==cat{printf "%-34s %s\n", $1, $2}' \ |
al@840 | 152 "$PKGS_DB/installed.info" | tee "$TMPLIST" | translate_category |
al@840 | 153 num=$(wc -l < "$TMPLIST"); rm "$TMPLIST" |
al@828 | 154 |
al@828 | 155 footer "$(emsg $(_p \ |
al@828 | 156 '%s package installed of category "%s".' \ |
al@828 | 157 '%s packages installed of category "%s".' $num \ |
al@828 | 158 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))" |
al@828 | 159 ;; |
al@828 | 160 |
al@828 | 161 |
al@828 | 162 mirrored) |
al@828 | 163 # List packages available on the mirror |
al@828 | 164 # Option --diff displays last mirrored packages diff (see recharge). |
al@828 | 165 if [ -n "$diff" ]; then |
al@828 | 166 if [ -f "$PKGS_DB/packages.diff" ]; then |
al@828 | 167 title 'Mirrored packages diff' |
al@840 | 168 cat "$PKGS_DB/packages.diff" |
al@840 | 169 num=$(wc -l < "$PKGS_DB/packages.diff") |
al@828 | 170 footer "$(_p \ |
al@828 | 171 '%s new package listed on the mirror.' \ |
al@828 | 172 '%s new packages listed on the mirror.' "$num" \ |
al@828 | 173 "$(colorize 32 $num)")" |
al@828 | 174 else |
al@828 | 175 newline |
al@828 | 176 _ 'Unable to list anything, no packages.diff found.' |
al@828 | 177 _ 'Recharge your current list to create a first diff.' |
al@828 | 178 newline |
al@828 | 179 fi |
al@828 | 180 else |
al@828 | 181 title 'List of available packages on the mirror' |
al@828 | 182 awk -F$'\t' '{ |
al@828 | 183 split($7, s, " "); |
al@828 | 184 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2]; |
al@840 | 185 }' "$PKGS_DB/packages.info" |
al@840 | 186 num=$(wc -l < "$PKGS_DB/packages.info") |
al@828 | 187 footer "$(_p \ |
al@828 | 188 '%s package in the last recharged list.' \ |
al@828 | 189 '%s packages in the last recharged list.' "$num" \ |
al@828 | 190 "$(colorize 32 $num)")" |
al@828 | 191 fi |
al@828 | 192 ;; |
al@828 | 193 |
al@828 | 194 |
al@828 | 195 installed_files) |
al@828 | 196 # List files installed with the package |
al@828 | 197 PACKAGE="$2" |
al@828 | 198 if [ -d "$INSTALLED/$PACKAGE" ]; then |
al@828 | 199 # installed package |
al@828 | 200 title 'Installed files by "%s"' "$PACKAGE" |
al@828 | 201 sort < "$INSTALLED/$PACKAGE/files.list" |
al@828 | 202 num=$(wc -l < "$INSTALLED/$PACKAGE/files.list") |
al@828 | 203 footer "$(_p '%s file' '%s files' $num \ |
al@828 | 204 "$(colorize 32 $num)")" |
al@840 | 205 elif [ -n "$(grep "^$PACKAGE"$'\t' "$PKGS_DB/packages.info")" ]; then |
al@828 | 206 # available package |
al@828 | 207 title 'Installed files by "%s"' "$PACKAGE" |
al@828 | 208 |
al@828 | 209 TMPLIST=$(mktemp) |
al@840 | 210 lzcat "$PKGS_DB/files.list.lzma" | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee "$TMPLIST" |
al@840 | 211 num=$(wc -l < "$TMPLIST"); rm "$TMPLIST" |
al@828 | 212 |
al@828 | 213 footer "$(_p '%s file' '%s files' $num \ |
al@828 | 214 "$(colorize 32 $num)")" |
al@828 | 215 else |
al@828 | 216 newline |
al@828 | 217 _ 'Package "%s" not available.' "$PACKAGE" |
al@828 | 218 newline |
al@828 | 219 fi |
al@828 | 220 ;; |
al@828 | 221 |
al@828 | 222 |
al@828 | 223 activity) |
al@828 | 224 # Show activity log |
al@840 | 225 : ${nb=18} |
al@828 | 226 title 'TazPkg Activity' |
al@828 | 227 IFS=' ' |
al@840 | 228 tail -n $nb "$LOG" | tac | \ |
al@828 | 229 while read date hour none action none pkg vers none; do |
al@828 | 230 case $action in |
al@828 | 231 Installed) |
al@828 | 232 action=$(colorize 32 $action) ;; |
al@828 | 233 Removed) |
al@828 | 234 action=$(colorize 31 $action) ;; |
al@828 | 235 *) |
al@828 | 236 action=$(boldify $action) ;; |
al@828 | 237 esac |
al@828 | 238 date_locale="$(date -d "$date $hour" '+%x %X')" |
al@828 | 239 echo "$date_locale : $action $pkg $vers" |
al@828 | 240 done |
al@828 | 241 unset IFS |
al@828 | 242 footer |
al@828 | 243 ;; |
al@828 | 244 |
al@828 | 245 |
al@828 | 246 config_files) |
al@828 | 247 # List configuration files installed |
al@828 | 248 # Option --box displays list formatted for Yad-based TazPkg boxes |
al@840 | 249 FILES="$INSTALLED/${2:-*}/volatile.cpio.gz" |
al@828 | 250 |
al@828 | 251 if [ -n "$box" ]; then |
al@828 | 252 TMP_DIR=$(mktemp -d) |
al@828 | 253 |
al@828 | 254 for i in $FILES; do |
al@840 | 255 mkdir -p "$TMP_DIR/temp"; cd "$TMP_DIR/temp" |
al@828 | 256 |
al@828 | 257 zcat $i | cpio -idm --quiet >/dev/null |
al@828 | 258 |
al@828 | 259 find . -type f 2>/dev/null | while read file; do |
al@840 | 260 if [ ! -e "/$file" ]; then |
al@828 | 261 echo -n "----------|----|----|$(_n 'File lost')" |
al@828 | 262 else |
al@840 | 263 echo -n "$(stat -c "%A|%U|%G|%s|" "/$file")" |
al@840 | 264 cmp "$file" "/$file" >/dev/null 2>&1 || \ |
al@840 | 265 echo -n "$(stat -c "%.16y" "/$file")" |
al@828 | 266 fi |
al@828 | 267 echo "|/$file" |
al@828 | 268 done |
al@840 | 269 rm -r "$TMP_DIR/temp" |
al@828 | 270 done |
al@840 | 271 rm -r "$TMP_DIR" |
al@828 | 272 else |
al@828 | 273 im && title 'Configuration files' |
al@828 | 274 for i in $FILES; do |
al@828 | 275 [ -f "$i" ] || continue |
al@840 | 276 zcat "$i" | cpio -t --quiet |
al@828 | 277 done | sed 's|^|/|' | sort |
al@828 | 278 im && footer |
al@828 | 279 fi |
al@828 | 280 ;; |
al@828 | 281 |
al@828 | 282 |
al@828 | 283 suggested) |
al@828 | 284 # List of suggested packages |
al@828 | 285 # By default list only not installed suggested packages |
al@828 | 286 # Option --all displays all (installed and not installed) suggested packages |
al@840 | 287 for i in $(ls -d "$INSTALLED"/*/receipt); do |
al@828 | 288 unset SUGGESTED |
al@828 | 289 . $i |
al@828 | 290 if [ -n "$SUGGESTED" ]; then |
al@828 | 291 if [ -z "$all" ]; then |
al@828 | 292 for s in $SUGGESTED; do |
al@828 | 293 [ -d "$INSTALLED/$s" ] && \ |
al@828 | 294 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")" |
al@828 | 295 done |
al@828 | 296 fi |
al@828 | 297 [ -n "$SUGGESTED" ] && cat <<EOT |
al@828 | 298 $(boldify $(echo "$PACKAGE"):) $SUGGESTED |
al@828 | 299 EOT |
al@828 | 300 fi |
al@828 | 301 done |
al@828 | 302 ;; |
al@828 | 303 |
al@828 | 304 esac |
al@828 | 305 exit 0 |