WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] /etc vs. /usr/local/etc pain  (Read 572 times)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11817
Re: /etc vs. /usr/local/etc pain
« Reply #15 on: February 04, 2025, 01:50:32 AM »
Hi GNUser
... Tinkering with the relevant step in  tce-load  seems unwise given that it's a key step ...
Agreed. But it might be possible to fix after tce-load.

Keep the link from /usr/local/etc->/etc

Add this to bootsync.sh before it calls bootlocal.sh:
Code: [Select]
for E in $(ls -1 /usr/local/tce.installed/)
do
if [ -e "/tmp/tcloop/$E/usr/local/etc" ]
then
sudo cp -ais "/tmp/tcloop/$E/usr/local/etc" /
[ -s /usr/local/tce.installed/"$E" ] && sudo /usr/local/tce.installed/"$E"
fi
done

/opt/Monitor.sh &
It tests loaded extensions for usr/local/etc and links it to /etc
if it exists. It then runs the tce.installed script if it exists.

It then launches the Monitor.sh script:
Code: [Select]
#!/bin/sh

PIPE="/tmp/Load"
mkfifo "$PIPE"

inotifywait --quiet --monitor --recursive -e create --format '%f' /usr/local/tce.installed > "$PIPE" &

while true
do
IFS= read -r E <"$PIPE"
if [ -e "/tmp/tcloop/$E/usr/local/etc" ]
then
sudo cp -ais "/tmp/tcloop/$E/usr/local/etc" /
[ -s /usr/local/tce.installed/"$E" ] && sudo /usr/local/tce.installed/"$E"
fi
done

The next time tce-load installs an extension, inotifywait sends
the extension name to the FIFO. The read command retrieves
name and processes it if usr/local/etc exists.

I haven't tested it but I think it should work.
Check it for accuracy and typos.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1558
Re: /etc vs. /usr/local/etc pain
« Reply #16 on: February 04, 2025, 10:15:44 AM »
Hi Rich. Thank you for such an interesting and thoughtful solution involving  inotifywait  . That should work just fine but I confess it's a bit more complex than the solution I was hoping to find.

I found something simpler that works, albeit with a caveat (which your solution does not suffer from). My solution is to add these lines to end of my /opt/bootlocal.sh:

Code: [Select]
rsync -a /usr/local/etc/ /etc
rm -rf /usr/local/etc
ln -s /etc /usr/local/etc

After boot is complete,  /usr/local/etc  is a symlink to  /etc  and everything is inside  /etc  , just as expected :)

Having just  etc/  in  /opt/.filetool.lst  (rather than both  etc/  and  usr/local/etc/ ) works just fine, too  :)

The caveat is that after boot process is complete, I need to refrain from loading any extensions that would try to put files in  /usr/local/etc  because the  cp -ais  step of  tce-load  cannot handle the symlink. In my opinion this as a minor bug in how  tce-load  works, but I cannot think of an elegant way to fix this at the moment.
« Last Edit: February 04, 2025, 10:28:49 AM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1558
Re: /etc vs. /usr/local/etc pain
« Reply #17 on: February 04, 2025, 10:59:55 AM »
Never mind my simple solution :'(

I looked in /etc/tc-config and found that bootsync.sh (and therefore bootlocal.sh) (line 641) runs user's backup is restored  (tc-restore.sh on line 626). So to avoid the rsync from clobbering the files in etc restored in user's backup, we need this in bootlocal.sh:

Code: [Select]
rsync -a --ignore-existing /usr/local/etc/ /etc
rm -rf /usr/local/etc
ln -s /etc /usr/local/etc

The only problem with the above is that it breaks how /etc/sysconfig is built, and also seems to break fonts. What a can of worms.

I need a little break from this. Thank you all for your time and assistance.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1558
Re: /etc vs. /usr/local/etc pain
« Reply #18 on: February 04, 2025, 11:44:36 AM »
I figured it out. The order of the steps is very important.

1. On system with default configuration (both /etc and /usr/local/etc exist, nothing etc-related in bootlocal.sh), do:

Code: [Select]
sudo rsync -a /usr/local/etc/ /etc

2. Look inside /etc and make sure fonts, sysconfig, and everything else looks good. Then, before rebooting, put etc/ in /opt/.filetool.lst and do a backup:
Code: [Select]
filetool.sh -b
3. Finally, add this to end of /opt/bootlocal.sh:
Code: [Select]
rsync -a --ignore-existing /usr/local/etc/ /etc
rm -rf /usr/local/etc
ln -s /etc /usr/local/etc

4. Reboot

After reboot everything is as expected.

As I mentioned before, the one issue is that any extensions that put files in /usr/local/etc must be loaded during boot. This is due to the  cp -ais  step in  tce-load  .

I think I may just live with the pain of having both /etc and /usr/local/etc after all. This may have been just a (worthwhile?) learning experience.

Thread may be marked as solved.

P.S. Come to think of it, the  rsync  command in  bootlocal.sh  is probably unnecessary, since everything the user needs is already in the backup created by  filetool.sh  .
« Last Edit: February 04, 2025, 12:11:14 PM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11817
Re: [Solved] /etc vs. /usr/local/etc pain
« Reply #19 on: February 04, 2025, 12:54:37 PM »
Hi GNUser
... I looked in /etc/tc-config and found that bootsync.sh (and therefore bootlocal.sh) (line 641) runs user's backup is restored  (tc-restore.sh on line 626). ...
These were all intentional.
Because  cp -ais  does not clobber files, running the restore first is safe.

bootsync.sh was chosen because it blocks and runs synchronously in
the foreground. This makes it possible to  link local/etc /  and run any
install scripts before any of those extensions get used.

bootlocal.sh runs asynchronously in the background allowing X, your
desktop, and other apps to start, potentially creating a race condition.

... Then, before rebooting, put etc/ in /opt/.filetool.lst and do a backup: ...
Generally you only want to backup files you've modified to minimize size
and time required to run your backup (and restore).

There may be some things in /etc that should not be backed up, possibly
things like fstab and udev.

Quote
Thread may be marked as solved. ...
Done.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1558
Re: [Solved] /etc vs. /usr/local/etc pain
« Reply #20 on: February 04, 2025, 01:36:53 PM »
Generally you only want to backup files you've modified to minimize size
and time required to run your backup (and restore).

There may be some things in /etc that should not be backed up, possibly
things like fstab and udev.
Hi Rich. I've gone back and forth between backing up only the files I've modified (to minimize size and so that .filetool.lst can serve as a record to remind me which files I've touched) and backing up all of /etc (for convenience). I never felt confident of which approach was superior until I read your reply today. Thank you very much for sharing your thoughts on this.