3

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?

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

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

rm -f $0
  • I couldn't think of a reason! – Alex Chamberlain Jul 17 '12 at 13:10
  • But check if everything went well. Raspbmc does not and tried to boot a zero-byte root filesystem – macrojames Jul 17 '12 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, privacy policy and cookie policy

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