Skip to content

Commit

Permalink
Pass commit messages and enable default.
Browse files Browse the repository at this point in the history
  • Loading branch information
None committed Jun 23, 2017
1 parent b4bf45c commit bcf5e2f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Copy contents of `config` directory to `/config` on EdgeRouter.
Edit `/config/user-data/edgerouter-backup.conf` with your information:

#!/bin/bash
# Default commit message
DEFAULT_COMMIT_MESSAGE="Auto commit by edgerouter-backup"

# Path to private key for SSH / SCP
SSH_KEYFILE=/config/user-data/backup_user_private.key
Expand Down
3 changes: 3 additions & 0 deletions config/user-data/edgerouter-backup.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Default commit message
DEFAULT_COMMIT_MESSAGE="Auto commit by edgerouter-backup"

# Path to private key for SSH / SCP
SSH_KEYFILE=/config/user-data/backup_user_private.key
SSH_USER=
Expand Down
20 changes: 19 additions & 1 deletion config/user-data/hooks/03-edgerouter-backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#!/bin/bash
source /config/user-data/edgerouter-backup.conf

commit_via=${COMMIT_VIA:-other}
commit_cmt=${COMMIT_COMMENT:-$DEFAULT_COMMIT_MESSAGE}

if [ "$commit_cmt" == "commit" ];
then
commit_cmt=$DEFAULT_COMMIT_MESSAGE
fi

if [ $# -eq 1 ] && [ $1 = "rollback" ];
then
commit_via="rollback/reboot"
fi

time=$(date +%Y-%m-%d" "%H:%M:%S)
user=$(whoami)

git_commit_msg="$commit_cmt | by $user | via $commit_via | $time"

# Generate temporary config files
sudo cli-shell-api showConfig --show-active-only --show-ignore-edit --show-show-defaults > /config/user-data/$FNAME_CONFIG
sudo cli-shell-api showConfig --show-commands --show-active-only --show-ignore-edit --show-show-defaults > /config/user-data/$FNAME_CLI
Expand All @@ -13,7 +31,7 @@ sudo scp -i $SSH_KEYFILE -o StrictHostKeyChecking=no /config/user-data/$FNAME_CL
sudo ssh -i $SSH_KEYFILE -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST 'bash -s' << ENDSSH
cd $REPO_PATH
git add --all
git commit -m "Auto-commit"
git commit -m "$git_commit_msg"
git push
ENDSSH

Expand Down

0 comments on commit bcf5e2f

Please sign in to comment.