6

I would like to run a script that would run only on the first boot. For example, Tom could use it to generate unique SSH certs in How can I copy the same image to many SDs?.

I was thinking that I could get the script to delete itself, is this a good idea?

3
  • Boot scripts are handled differently by different distributions. So re-tagging with what distro you're using would be helpful.
    – Jivings
    Jul 17, 2012 at 12:56
  • I would have preferred a distro agnostic answer... Jul 17, 2012 at 12:57
  • That would have to be a separate answer for each distro then.
    – Jivings
    Jul 17, 2012 at 12:58

2 Answers 2

3

Why should it be a bad idea? Check if your script was succesful and put as last command

rm -f $0
2
  • I couldn't think of a reason! Jul 17, 2012 at 13:10
  • But check if everything went well. Raspbmc does not and tried to boot a zero-byte root filesystem
    – macrojames
    Jul 17, 2012 at 13:11
1

Why not check if the output exists before you try to write it? Here is some pseudo-code:

if( file_exists( '/etc/myfile' ) ) {
    delete( $SELF );
    exit( 0 );

} else {
    create_file( '/etc/myfile' );
}

It makes sure your output exists before it deletes itself. This way, you can be (more) sure that your script did its job (or wasn't required for some reason).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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