From bcf5e2fc1f4a84871eb33b530f1d35e35a6064d6 Mon Sep 17 00:00:00 2001 From: None Date: Fri, 23 Jun 2017 09:29:14 -0400 Subject: [PATCH] Pass commit messages and enable default. --- README.md | 3 +++ config/user-data/edgerouter-backup.conf | 3 +++ .../user-data/hooks/03-edgerouter-backup.sh | 20 ++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d079bfc..4c81f2a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/user-data/edgerouter-backup.conf b/config/user-data/edgerouter-backup.conf index 236b25b..fa537b2 100644 --- a/config/user-data/edgerouter-backup.conf +++ b/config/user-data/edgerouter-backup.conf @@ -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= diff --git a/config/user-data/hooks/03-edgerouter-backup.sh b/config/user-data/hooks/03-edgerouter-backup.sh index 0da27eb..045590d 100644 --- a/config/user-data/hooks/03-edgerouter-backup.sh +++ b/config/user-data/hooks/03-edgerouter-backup.sh @@ -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 @@ -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