I am trying to write a script which will download git using apt and after successful download of git I want to set the config for git. I wrote a script that does the work. But I am curious to know is there a way to know that the git installation properly done or not. If git installed then i will set config otherwise I will retry or perhaps show an error message.
My Code:
#!/bin/bash
# Read Password
echo -n Sudo Password:
read -s password
# Run Command
setup_git_config(){
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
}
install_git(){
echo $password | sudo -S apt-get install git -y
# here i want to check above command successfully ran or not
setup_git_config
}
#Execute commands
install_git
I am asking this question because I want to write a script to install few essential program and configuration.
Updated:
install_git(){
typeset ret_code
ret_code=$?
echo 'xyz' | sudo -S apt-get install git -y
if [ $ret_code != 0 ]; then
printf "Error " $ret_code
exit $ret_code
fi
echo $ret_code #always echo 0
setup_git_config
}
Always print 0