DevOps session 13: Automate git SETUP using bash scripting.
Bash scripting:
A Bash Shell Script is a plain text file containing a set of various commands that we usually type in the command line. It is used to automate repetitive tasks on Linux filesystem. It might include a set of commands, or a single command.
For example ,to install GIT we need to update the packages, then install git and check if installation is done using Linux commands.
We can write all the command in a .sh file and we can execute the file to do all the steps mentioned above.
Lets start with example from hello-world.
1.Open terminal and check the root of the bash using below command.
2.Create a hello-world.sh file and paste the below lines.
CMD: nano hello-world.sh
You can see editor ,add below lines
#!/bin/bash
# declare MSG variable
MSG="Hello World"
# print variable on a screen
echo $MSG
To save the file use CTRL+X, then CTRL+Y and press ENTER
3. To execute the file we need to add the permissions.
CMD: chmod +x hello-world.sh
4. Now we can execute the shell script using below command.
CMD: ./hello-world.sh
Result: it should display the message we provided in the hello-world.sh file.
We are not going deep into Shell scripting now.
I have created a sample git-setup.sh file to Automate GIT installation and configure locally. To use this ,you can clone from
https://github.com/NAVEENINTEL/devopsDemo
Once you are done with cloning the code. Go to the directory where git-setup.sh file is present and use below command to setup the git on your system.
CMD: ./git-setup.sh
You can see that git will install locally and asked to provide user name, email to configure with git. Provide user name and email.
Now you're system is ready to use git.
Comments
Post a Comment