Has nothing to do with the existence of those .pkgsave copies.
Just runfind /usr/local -type f -name '*.pkgsave' -delete
and be done. And I hope you didn't install things manually that ended up in /etc and/or {,/usr}/{,s}bin.
/usr/local/lib/libgnutls.so.30.34.2.pkgsave
/usr/local/lib/libIntelXvMC.so.1.0.0.pkgsave
/usr/local/lib/libruby30.so.30.pkgsave
/usr/local/lib/libgconf-2.so.4.1.5.pkgsave
/usr/local/lib/libICE.so.6.3.0.pkgsave
/usr/local/lib/libabsl_flags_commandlineflag.so.2111.0.0.pkgsave
/usr/local/lib/libabsl_random_internal_randen.so.2111.0.0.pkgsave
/usr/local/lib/libabsl_cord_internal.so.2111.0.0.pkgsave
/usr/local/lib/libxcb-present.a.pkgsave
/usr/local/lib/libxkbcommon-x11.so.0.0.0.pkgsave
/usr/local/lib/libsoxr-lsr.so.0.1.9.pkgsave
/usr/local/lib/libodbc.a.pkgsave
/usr/local/lib/libxcb.so.1.1.0.pkgsave
/usr/local/lib/libraptor2.la.pkgsave
/usr/local/lib/libfm.so.4.1.3.pkgsave
/usr/local/lib/libpangoft2-1.0.so.0.5000.9.pkgsave
You wanted to clean up your system, or not? If you want to clean up, remove everything that ends with *.pkgsave.your script will delete everything. But why should I do that ?
No, those are libraries. Probably installed by whatever you built from source yourself. Get rid of them, they've been replaced by proper port/package versions anyway (that's why those *.pkgsave files exist in the first place). They will never be referenced or loaded as their naming convention doesn't match what is expected of libraries.the pkgsave files you see aren't executables.
find /usr/local -type f -name '*.pkgsave' | xargs rm -i
Just runfind /usr/local -type f -name '*.pkgsave' -delete
and be done. And I hope you didn't install things manually that ended up in /etc and/or {,/usr}/{,s}bin.
I suspect that your command is not able to distinguish between a .pkgsave that's an executable and a .pkgsave that's a configuration file. Is this right ? I find useful to have a backup of the old configuration files. The script should detect if the .pkgsave file is +x before to remove it.
find /usr/local -type f -name '*.pkgsave' -exec chmod a-x {} \;
How's it possible that a script like /usr/local/etc/rc.d/tor.pkgsave started automatically?No, that has nothing to do with it. It's the /usr/local/etc/rc.d/tor.pkgsave that caused it to get started twice. And that script will simply execute /usr/local/bin/tor, not /usr/local/bin/tor.pkgsave. The rc(8) file itself has been renamed, its contents aren't modified.
onestart
switch.Because all scripts in /usr/local/etc/rc.d/ are executed during boot?How's it possible that a script like /usr/local/etc/rc.d/tor.pkgsave started automatically?
Simple, it hadIt's hard to believe it's enabled in /etc/rc.conf, thus the corresponding daemon/service must be started withonestart
switch.
tor_enabled="YES"
in rc.conf intended to start /usr/local/etc/rc.d/tor, but /usr/local/etc/rc.d/tor.pkgsave uses that same variable, thus it also gets started. The variable that defines if the service is enabled or not isn't depending on the name of the rc.d(8) script, it's set by the rcvar
variable that's defined within that script. The contents of the tor.pkgsave rc(8) script hasn't changed, only the name of the script itself has.Because all scripts in /usr/local/etc/rc.d/ are executed during boot?
run_rc_script
from rc.subr(8), which specifically ignores non-executable files, right? case "$_file" in
/etc/rc.d/*.sh) # no longer allowed in the base
warn "Ignoring old-style startup script $_file"
;;
*[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
warn "Ignoring scratch file $_file"
;;
*) # run in subshell
if [ -x $_file ]; then
if [ -n "$rc_fast_and_loose" ]; then
set $_arg; . $_file
else
( trap "echo Script $_file interrupted >&2 ; kill -QUIT $$" 3
trap "echo Script $_file interrupted >&2 ; exit 1" 2
trap "echo Script $_file running >&2" 29
set $_arg; . $_file )
fi
fi
Because all scripts in /usr/local/etc/rc.d/ are executed during boot?
Simple, it hadtor_enabled="YES"
in rc.conf intended to start /usr/local/etc/rc.d/tor, but /usr/local/etc/rc.d/tor.pkgsave uses that same variable, thus it also gets started. The variable that defines if the service is enabled or not isn't depending on the name of the rc.d(8) script, it's set by thercvar
variable that's defined within that script. The contents of the tor.pkgsave rc(8) script hasn't changed, only the name of the script itself has.
No, it shouldn't touch the permissions of the file. A better solution is to get /etc/rc.subr changed and add *.pkgsave to the list of files to ignore from /etc/rc.d and /usr/local/etc/rc.d. You should create a PR for this, you have a good use-case for the change.I think that the fix could be to set -x to the executables .pgksave files.
No, it shouldn't touch the permissions of the file. A better solution is to get /etc/rc.subr changed and add *.pkgsave to the list of files to ignore from /etc/rc.d and /usr/local/etc/rc.d.
Your own argument:what's the problem with my approach ? I don't understand this.
Changing the permissions of those files wouldn't preserve them.My ultimate goal is to preserve the system files as much as possible as they are.
On a properly maintained system those files shouldn't get created in the first place. I've never had a single one in all the years I've been using pkg(8) (I originally started using it on 9.x when the old pkg_* tools were still the default).And anyway,I don't understand when I should run your script. Before to see that the .pkgsave / executable files have been ran or after that ?
For now you can just run it to clean up the mess. No need to save it anywere, unless you want to keep it. /root/bin is a nice place for ad-hoc scripts like this.should I place your script somewhere ? into which directory ?
find(1) is super powerful and useful, you'd do well to learn how to use it. It'll come in handy in many situations. I'll try to break down the command for you:Can you explain how it works ?
find /usr/local -type f -name '*.pkgsave' -delete
-type f
tells it to only look for files, -name '*.pkgsave'
then further constrains the search to only look for files matching the file glob, in other words, every file that ends with .pkgsave. This results in a list of files and -delete
tells find(1) to delete everything on that list. -type t
True if the file is of the specified type. Possible file types
are as follows:
b block special
c character special
d directory
f regular file
l symbolic link
p FIFO
s socket
-name pattern
True if the last component of the pathname being examined matches
pattern. Special shell pattern matching characters (“[”, “]”,
“*”, and “?”) may be used as part of pattern. These characters
may be matched explicitly by escaping them with a backslash
(“\”).
-delete
Delete found files and/or directories. Always returns true.
This executes from the current working directory as find recurses
down the tree. It will not attempt to delete a filename with a
“/” character in its pathname relative to “.” for security
reasons. Depth-first traversal processing is implied by this
option. The -delete primary will fail to delete a directory if
it is not empty. Following symlinks is incompatible with this
option.
There once was a time when I didn't know how to use find(1) either. Read my signature.You have more experienced than me. What for you is an easy solution,for me it's too much complicated.
Run the command without theI could try to run your script,but before to do that,please can you reply to my questions ?
-delete
at the end, that will simply produce a list of files and you can verify it doesn't contain anything you wanted to keep. Then if you're satisfied that list is good add the -delete
at the end. I always do the same, keep fiddling with the search parameters until I'm satisfied it only matches with the things I want. Then I'll add the -delete
to have them deleted.find /usr/local -type f -name '*.pkgsave' -delete
case "$_file" in
/etc/rc.d/*.sh) # no longer allowed in the base
warn "Ignoring old-style startup script $_file"
;;
*[~#]|*.OLD|*.bak|*.orig|*,v) # scratch file; skip
warn "Ignoring scratch file $_file"
;;
*) # run in subshell
if [ -x $_file ]; then
if [ -n "$rc_fast_and_loose" ]; then
set $_arg; . $_file
else
( trap "echo Script $_file interrupted >&2 ; kill -QUIT $$" 3
trap "echo Script $_file interrupted >&2 ; exit 1" 2
trap "echo Script $_file running >&2" 29
set $_arg; . $_file )
fi
fi
find /usr/local -type f -name '*.pkgsave' -delete
That was a couple of lines from /etc/rc.subr where the issue could easily be fixed. It already filters a couple of other file postfixes (like .bak and .orig). Adding *.pkgsave would prevent the system from ever executing a *.pkgsave file in /etc/rc.d/ and /usr/local/etc/rc.d/ (and any directory referenced inI can understand and manipulate the first one,but not the second. I'd thought you were talking about the 2.
local_startup
).That was a couple of lines from /etc/rc.subr where the issue could easily be fixed. It already filters a couple of other file postfixes (like .bak and .orig). Adding *.pkgsave would prevent the system from ever executing a *.pkgsave file in /etc/rc.d/ and /usr/local/etc/rc.d/.
Correct, the part I copy/pasted is 'vanilla', I didn't make any changes to it.You haven't fixed anything,right ?
Correct, the part I copy/pasted is 'vanilla', I didn't make any changes to it.