pastebin - collaborative debugging tool
rovema.kpaste.net RSS


Xorg: print Debian packages used by Xorg process
Posted by Anonymous on Mon 2nd May 2022 17:39
raw | new post
modification of post by Anonymous (view diff)

  1. #!/usr/bin/ksh93
  2.  
  3. #
  4. # xorg_proc_package_list.ksh - get list of packages used by Xorg process
  5. #
  6. #
  7. #
  8.  
  9. set -o xtrace
  10. set -o errexit
  11. set -o nounset
  12.  
  13. #
  14. # builtins&vars
  15. #
  16. builtin cat
  17. typeset s1
  18. typeset s2
  19. typeset -a a1
  20.  
  21. compound c=(
  22.         integer xorg_pid
  23.         typeset -a mapped_files_ar
  24.         typeset -A package_list
  25. )
  26.  
  27. c.xorg_pid="$(pgrep Xorg)"
  28.  
  29. c.mapped_files_ar=(
  30.         $(
  31.                 cat "/proc/${c.xorg_pid}/maps" | \
  32.                 sed -r 's/[[:xdigit:]]+?-[[:xdigit:]]+? [rwxp-]+ [[:xdigit:]]+? .+? (\/.+?$)/\1/' | \
  33.                 egrep '^/' |
  34.                 sort -u
  35.         )
  36. )
  37.  
  38. for s1 in "${c.mapped_files_ar[@]}" ; do
  39.         s1="$(apt-file search "$s1" 2>'/dev/null' || true)"
  40.         [[ $s1 != '' ]] || continue
  41.  
  42.         # apt-file can return multiple results, one per line
  43.         # we stuff them into the array a1 here and then
  44.         # process them one-by-one
  45.         IFS=$'\n'
  46.         a1=( $s1 )
  47.         IFS=$' \t\n' # restore
  48.         printf $"# apt-file %d results\n" "${#a1[@]}"
  49.        
  50.         for s2 in "${a1[@]}" ; do
  51.                 # extract package name
  52.                 s2="${s2/~(El)(.+?):.+/\1}"
  53.  
  54.                 # add result, use package name as index to eliminate duplicates
  55.                 c.package_list["$s2"]="$s2"
  56.         done
  57. done
  58.  
  59. #
  60. # debug data
  61. #
  62. print -v c
  63.  
  64. #
  65. # print results
  66. #
  67. printf "# Package list:\n"
  68. printf "%s\n" "${c.package_list[@]}"
  69.  
  70. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at