Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script: xorphan #221

Open
Anachron opened this issue Dec 24, 2021 · 7 comments
Open

Script: xorphan #221

Anachron opened this issue Dec 24, 2021 · 7 comments

Comments

@Anachron
Copy link

Anachron commented Dec 24, 2021

#!/bin/sh

xoi="/tmp/xorphan-install" xos="/tmp/xorphan-search";
xox="/tmp/xorphan-xloc";

if test "${1}" = "batch"; then
  shift; fl=$(while test "$#" -gt 0; do printf '%s\n' "${1}"; shift; done)
  rgx=$(printf '%s' "${fl}" | tr '\n' '|' | sed 's;|$;;g; s;|;\\|;g; s;\[;\\[;g;')
  printf '%s\n' "${fl}" >> "${xos}"
  xlocate "${rgx}" >> "${xox}"
elif test "${1}" = "filt"; then
  shift; $0 "${@}" | awk '$2 ~ /(orphan|unknown)/ { print $0 }'
else
  rm -rf /tmp/xorphan-*; # trap 'rm -rf /tmp/xorphan-*' EXIT
  test -p /dev/stdin && fl=$(cat) || fl=$(sudo find "${1:-${PWD}}" -mindepth 1 -type f);
  xbps-query -l | awk '{print $2}' > "${xoi}"
  ca=$(printf '%s\n' "${fl}" | while read fn; do printf '"%s"\n' "${fn}"; done)
  printf '%s\n' "${ca}" | xargs -s 4096 ${0} batch
  awk -v xoi="${xoi}" -v xos="${xos}" -v xox="${xox}" '
function pkgname(str) {
  return gensub(/(.+)-(.+)/,"\\1", "g", str);
}

function append(str, new) {
  split(str, arr, ",")
  for (key in arr) { if (arr[key] == new) { return str; } }
  return str","new;
}

{
  if (FILENAME == xoi) { i[pkgname($1)] = 1; }
  else if (FILENAME == xox) { x[$2] = append(x[$2], pkgname($1)); }
  else if (FILENAME == xos) {
    if ($1 == "") { next; }
    if (x[$1] != "") {
      p = x[$1]; gsub(/^,/,"",p); split(p, l, ","); c = 0;
      for (k in l) {
        if (i[l[k]] == 1) { c++; }
      }
      if ( c != 0 ) {
        printf "\"%s\" found [%s]\n", $1, p;
      } else {
        printf "\"%s\" orphan [%s]\n", $1, p;
      }
    } else {
      printf "\"%s\" unknown []\n", $1;
    }
  }
}
' "${xox}" "${xoi}" "${xos}" | eval "${flt:-cat}"
fi

Usage: xorphan <PathToFiles>

Searches for files in the directory and checks if the file is an orphan using xlocate and xbps-query.

Edit: The rewrite has been improving the performance a lot.

@triallax
Copy link
Contributor

triallax commented Mar 6, 2023

I also think an xadopt script would be quite useful.

@Anachron
Copy link
Author

Anachron commented Mar 6, 2023

This script doesn't look for orphan packages but for orphan files!

But it would be nice if xbump would check for maintainer and adopt if not fitting.

@triallax
Copy link
Contributor

triallax commented Mar 7, 2023

Thanks for the heads-up, but what does an "orphan file" mean?

@Anachron
Copy link
Author

Anachron commented Mar 7, 2023

A ophaned file is a file that does not belong to any package you've installed, but before belonged to one.

This could be due to some packages being uninstalled, for example.

@Anachron
Copy link
Author

Anachron commented Mar 7, 2023

I've updated the xorphan script.

Now it includes a filt command to only list orphaned/unknown files.

@mhmdanas for example, these files have been found to be orphaned on my setup:

$ xorphan filt /etc/ | grep orphan
"/etc/printcap" orphan [lprng]
"/etc/asound.conf" orphan [alsa-plugins-pulseaudio]

@paper42
Copy link
Contributor

paper42 commented Mar 7, 2023

But it would be nice if xbump would check for maintainer and adopt if not fitting.

Definitely no, adopting a package should never be automatic when someone touches a template. We don't want one time contributors to adopt a package and then disappear.

@Anachron
Copy link
Author

Anachron commented Mar 7, 2023

Yes, that should probably be an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants