Last active
August 9, 2018 06:20
-
-
Save Mehran/7ddb2848c2abe9ef475b79175f1b605d to your computer and use it in GitHub Desktop.
Automatic Gist update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Author ### | |
# By : Mehran Goudarzi | |
# Release : 2018-04-07 | |
# Description : Git auto update for repository | |
# Version : 1.2 | |
############### | |
### Colors #### | |
BRed="\033[1;31m" | |
BGreen="\033[1;32m" | |
BYellow="\033[1;33m" | |
BBlue="\033[1;34m" | |
BPurple="\033[1;35m" | |
BWhite="\033[1;37m" | |
NC='\033[0m' # No Color | |
################### | |
#### | |
BACKUP='$HOME/backup' | |
### | |
sudo git pull --dry-run 2>&1 | grep master > /dev/null 2>&1 && sleep 1 | |
if [ $? -eq 0 ] ; then | |
printf "$BYellow[+]Update Available , Try to updating ...$NC\n" | |
# Check Previous Backup # | |
if [ -d "$BACKUP" ]; then | |
printf "$BYellow[+]old backup detected! cleaning it first...$NC\n" | |
sudo rm -rf $BACKUP | |
fi | |
# Create back up # | |
printf "$BGreen[+]Try backup now ...$NC\n" | |
sudo mkdir -p $BACKUP | |
sudo cp -R /$(pwd) /$BACKUP | |
printf "$BYellow[+]Try to updating Git ...$NC\n" | |
sudo git stash > /dev/null 2>&1 | |
sudo git pull > /dev/null 2>&1 | |
sudo git stash pop > /dev/null 2>&1 | |
sudo git pull | grep "Already up-to-date." > /dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
printf "$BGreen[+]Updating Success ...$NC\n" | |
exit | |
fi | |
printf "$BRed[+]Something Wrong ...$NC\n" | |
fi | |
printf "$BGreen[+]No update needed!$NC\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment