You might want to start using a proper configuration management tool like Ansibe,Chef,Puppet, or Salt
Use ansible. It's like shell scripts on steroid.
Basically, imagine a list of simple tasks, executing one by one in order.
Instead of having bash commands which have crazy long arguments list and screw the whole script on failure, you get to use ansible commands (aka. modules) which are a lot easier to use and handle failures nicely (by stopping the run).
And you'll never have to worry again about what happens when a command is ran twice. It simply doesn't do anything if there is nothing to change.
Python and Plumbum ( https://plumbum.readthedocs.io/en/latest/ ). All kinds of binary-running / process-managing / file-manipulating goodness, inside of a sane language with actual logic and control structures. Plus, useful bits like SSH execution and CLI arg handling.