Skip to content

Instantly share code, notes, and snippets.

@yogendratamang48
Last active September 17, 2020 12:22
Show Gist options
  • Save yogendratamang48/e9d30be309a7ba571857e50979f04f71 to your computer and use it in GitHub Desktop.
Save yogendratamang48/e9d30be309a7ba571857e50979f04f71 to your computer and use it in GitHub Desktop.
Gist Track File from particular branch using script
#! /bin/bash
cd "$(dirname "$0")"
echo "Starting file sync program..."
echo "Start time: $(date)"
GIT_TOKEN=""
GIT_OWNER=""
GIT_BRANCH=""
GIT_REPO=""
GIT_FILE="<git_file_you_want_to_track>"
TMP_FILE="/var/tmp/file_sync.txt"
TARGET_FILE="<path_to_target_filetarget>"
GIT_URL="https://raw.githubusercontent.com/$GIT_OWNER/$GIT_REPO/$GIT_BRANCH/$GIT_FILE"
curl -H "Authorization: token $GIT_TOKEN" \
-H 'Accept: application/vnd.github.v3.raw' \
-o $TMP_FILE \
-L $GIT_URL
DIFF=$(diff $TMP_FILE $TARGET_FILE)
if [ "$DIFF" != "" ]; then
echo "-- New updates found --"
lineCounts=$(wc -l <$TMP_FILE)
echo "Lines: $lineCounts"
if [[ $lineCounts ]]; then
echo "- Found More than 100 lines, moving to production"
cp $TMP_FILE $TARGET_FILE
echo "- Moved: Updated: $TARGET_FILE"
fi
else
echo "--> No updates found"
fi
echo "End time: $(date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment