When I needed to do this, I used this project and then extracted the logic and made my own script, hope it helps: https://github.com/unixabg/cryptmypi
When I needed to do this, I used this project and then extracted the logic and made my own script, hope it helps: https://github.com/unixabg/cryptmypi