I am fan of deployment using git, where do a git push and the code gets deployed to the server.

But it is somewhat tedious to do all the setup, so I decided to write a shell script which would automatically do all the stuff like:

1. Checking if SSH keys present in the System, if not then generating SSH Keys

2. Adding your Public Key into the server’s authorized_keys, so that you can login without a password.

3. Initialising a bare repo on the server

4. Setup POST deploy to move code from bare repo after each push

5. Run the commands which user have specified after each push

6. Adding the server as git remote in the local git repository

After running the script, you can push the code to the server using git push server master.

The code will be deployed to the server, and the script will run the commands which you have entered during the initialisation process.

Run the following command in your terminal:

1. Download the script

wget https://gist.githubusercontent.com/mlakkadshaw/

18ef45096e47d8626b43/raw/e05fbca813545617657e58e3ffc08052b81a26a0/setup.sh

2. Make it executable

chmod +x ./setup.sh

3. Run it!

./setup.sh

Here is the Script:

Let me know if you face any issues in the comments.