I was bored and packaged everything into a foolproof script (windows).
OP, feel free to use it in the OP.
The exe will run all the commands and has adb + apk built it.
To eliminate mistakes it checks for:
-model (Moto X)
-Write Protect = 0
Just download the attached executable and run it.