Skip to content

How can I flag a script as been executed already? #2282

Answered by twpayne
danielo515 asked this question in Q&A
Discussion options

You must be logged in to vote

This is tricky, but possible.

First, the correct fix is to make all of your scripts, including your run_once_ scripts, idempotent, so it doesn't matter if they run one more than once.

If that is not possible, then you need to create an entry for the script in chezmoi's state. You will need to calculate the SHA256 sum of the script's contents (after template execution) and add it to chezmoi's state.

Say your script is called script.sh, you would do something like:

$ sha256sum script.sh
91ee34a755e613fc83be1e399b024d1dcbd8ce22800fdb004071518e85f66945  script.sh
$ chezmoi state set --bucket=scriptState --key=91ee34a755e613fc83be1e399b024d1dcbd8ce22800fdb004071518e85f66945 --value={}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@danielo515
Comment options

@twpayne
Comment options

Answer selected by danielo515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants