Last active
July 28, 2022 12:23
-
-
Save takshaktiwari/2ab7a8ba4f0949727a6211059a576ded to your computer and use it in GitHub Desktop.
Setup a Cron on server for specific interval like daily, and the script will check and pull the code from Github if there is any new release in repository. Change the variables according to your project and github account.
This file contains 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 | |
USER="takshaktiwari" | |
PERSONAL_TOKEN="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" | |
AUTHOR="takshaktiwari" | |
PACKAGE="adash" | |
REMOTE_NAME="origin" | |
BRANCH="main" | |
SOURCE_FILE="gitpull.sh" | |
RELEASE_FILE="latest_release.json" | |
TEMP_FILE="temp" | |
NEWLINE=$'\n' | |
[ ! -e .gitignore ] && touch .gitignore | |
if [ -z $(cat .gitignore | grep $RELEASE_FILE) ] | |
then | |
echo $NEWLINE >> .gitignore | |
echo $SOURCE_FILE >> .gitignore | |
echo $RELEASE_FILE >> .gitignore | |
echo $TEMP_FILE >> .gitignore | |
fi | |
[ ! -e $RELEASE_FILE ] && touch $RELEASE_FILE | |
PREV_RELEASE=$(jq '.tag_name' $RELEASE_FILE) | |
which curl > /dev/null 2>&1 | |
[ ! $? == 0 ] && sudo apt install curl -y | |
which jq > /dev/null 2>&1 | |
[ ! $? == 0 ] && sudo apt install jq -y | |
which git > /dev/null 2>&1 | |
[ ! $? == 0 ] && sudo apt install git -y | |
curl -u $USER:$PERSONAL_TOKEN "https://api.github.com/repos/${AUTHOR}/${PACKAGE}/releases/latest" -o $TEMP_FILE | |
LATEST_RELEASE=$(jq '.tag_name' $TEMP_FILE) | |
if [ $PREV_RELEASE != $LATEST_RELEASE ] | |
then | |
git stash | |
git pull $REMOTE_NAME $BRANCH | |
fi | |
rm $TEMP_FILE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment