Skip to content

Instantly share code, notes, and snippets.

@guentur
Created October 6, 2022 14:35
Show Gist options
  • Save guentur/95004a6dfeb0878effff22266da44bc6 to your computer and use it in GitHub Desktop.
Save guentur/95004a6dfeb0878effff22266da44bc6 to your computer and use it in GitHub Desktop.
To run it automatically when computer turns off past this file to /etc/init.d/ folder and create a symbol link to it in /etc/rc0.d and /etc/rc6.d. At least that what I have red in this [article](https://askubuntu.com/questions/83473/how-to-execute-script-on-shutdown)
#!/usr/bin/env bash
REPO_PATH='/media/user/Documents/Repo_folder'
BRANCH_NAME='laptop_dell_vostro_3590'
if [ -d '/media/user/Documents/Repo_folder' ]
then
DATE=$(date)
cd '/media/user/Documents/Repo_folder'
EXISTS=`git show-ref refs/heads/$BRANCH_NAME`
if [ -n "$EXISTS" ]
then
git checkout $BRANCH_NAME
else
git checkout master
git checkout -b $BRANCH_NAME
fi
git pull
git add .
git commit -m "Changes added on $DATE"
git push --set-upstream origin $BRANCH_NAME
else
FAILURE_MESSAGE="Directory $REPO_PATH DOES NOT exists."
echo $FAILURE_MESSAGE
exit 9999 # die with error code 9999
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment