tazpkg annotate modules/list @ rev 976

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