2

I'm writing an installer script on Ubuntu for an application which needs multiple parts such as

  • install a specific g++ version, put a script in profile.d, reboot
  • install drivers for some hardware, remove old script, put new script in profile.d, reboot
  • set environment variables, remove script from profile.d, add new script, compile source code (c++),
  • set environment variables script int profile.d

At each part of the installation, I'm copying a script to the /etc/profile.d directory to be run at login from ssh. But I don't know if the script runs after all other scripts in same directory (for example, drivers may have put their own scripts in there which my script may need to work).

How can I make sure my script in profile.d runs as a last step? Is it something about file name or creation date or something else?

  • 1
    Have a look into /etc/profile. The scripts are sourced in this loop for i in /etc/profile.d/*.sh; do (on Ubuntu 16.04). – Ralf Jan 8 at 13:22
  • Then it needs at least an sh extension and at least a name which * sorts them? – huseyin tugrul buyukisik Jan 8 at 13:23
  • It needs the .sh as the extension to be read.... – Luciano Andress Martini Jan 8 at 13:30
  • Order of wildcard expansion should follow LC_COLLATE (Unix Spec). – Ralf Jan 8 at 13:30
4

Just number the scripts, like 01-firstscript.sh, 99-lastscript.sh, if it is showing in last in ls -l, you're done.

If the files are not supposed to be numbered (installed by distribution), just change the name of your own scripts to have something like a zzz-001.sh, zzz-002.sh, zzz-003.sh etc....

  • I would have expected numbering would work, but is ls -l really accurate? I think the ordering depends on locale? – Sparhawk Jan 8 at 13:12
  • So its about ascii values being last? – huseyin tugrul buyukisik Jan 8 at 13:12
  • It is all about the file name. If the files are not numbered, just change the name to have something like a zzz... – Luciano Andress Martini Jan 8 at 13:12
  • And I just "hope" for driver not use a naming like this :) At least I can check for a specific driver version. Thank you. I can accept this at least 7 minutes in future. – huseyin tugrul buyukisik Jan 8 at 13:13
  • If you number all the scripts them locale probably not a problem in most languages.The only trouble is that maybe you need to care about installing or upgrading system depending on your distribution (the files can be installed with wrong names). A way to avoid this is to create your local scripts like zzz01, zzz02, etc. – Luciano Andress Martini Jan 8 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.