Tell me more ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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?

share|improve this question
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

2 Answers

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

rm -f $0
share|improve this answer
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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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