Run command once only after sysupgrade

Hi,
I want to make some mv commands only once after Attendant Sysupgrade ...
I tought of Idea to install useless package and disable it, and add startup command:

if /etc/init.d/<pkg> enabled; then

cd <path>
mv <old name> <new name>
/etc/init.d/<pkg> disable
/etc/init.d/<pkg> stop

fi

Is there another way to do that?

uci-defaults

3 Likes

Thank you, I read about it yesterday but i'm not sure about something...
If

exit 0

Removes the script after the first boot, how it will be kept for next sysupgrades?

If your goal is to always stop/disable a specific package (i.e. you will never ever run it), there's no real harm in this script running post-firstboot.... it will evaluate the if statement (which will be false once the package is disabled the first time), and exit out.

1 Like

You need to bake it into the next sysupgrade image as a custom file. Like you would need to do in any case, as extra files are not included in the sysupgrade backups.

(Not sure if you can do that with attendedsysupgrade, but you can do it with the normal Imagebuilder that you should use, if you want any extra files to be included)

@hnyman - If this was in a script and that was called by rc.local, wouldn't this work by nature as long as both rc.local and the other script were included in the standard backup files? Wouldn't this also work with ASU? I'm trying to figure out if I'm missing something (i.e. why it needs to be baked in vs part of the standard backup set).

Sure, that would work if you configure it as a file to be saved in sysupgrade.

1 Like

I found a better option (add to rc.local) thanks to @xNUTx

if [ ! -e "<path>/modified" ]; then
  mv <old name> <new name>
  touch <path>/modified
fi

Thank you all

I'm not real clear as to what you want to keep around across upgrades, but you can see what sysupgrade will retain with its --list-backup option:

$ sysupgrade -l
/etc/config/dhcp
... a bunch of files to keep ...

And you can extend that list by putting file or directory names in /etc/sysupgrade.conf. For example, I'll often do echo /root/test.sh >> /etc/sysupgrade.conf when I want to run a sysupgrade and keep some experiment around.

Also...

for i in daemon1 daemon2 daemon3; do
  if /etc/init.d/"$i" enabled; then
    /etc/init.d/"$i" disable
    /etc/init.d/"$i" stop
  fi
done

put in rc.local does the trick

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.