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?

Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113

2 Answers2

3

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

rm -f $0
macrojames
  • 96
  • 3
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).

Oliver Salzburg
  • 1,774
  • 1
  • 19
  • 33