5

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?

4
  • 3
    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). Commented Jan 8, 2019 at 13:22
  • Then it needs at least an sh extension and at least a name which * sorts them? Commented Jan 8, 2019 at 13:23
  • It needs the .sh as the extension to be read.... Commented Jan 8, 2019 at 13:30
  • 1
    Order of wildcard expansion should follow LC_COLLATE (Unix Spec). Commented Jan 8, 2019 at 13:30

1 Answer 1

7

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....

6
  • I would have expected numbering would work, but is ls -l really accurate? I think the ordering depends on locale? Commented Jan 8, 2019 at 13:12
  • So its about ascii values being last? Commented Jan 8, 2019 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... Commented Jan 8, 2019 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. Commented Jan 8, 2019 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. Commented Jan 8, 2019 at 13:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.