Last active
August 8, 2021 08:43
-
-
Save nickw444/e17d35ae2d6d748183aa53939d02798b to your computer and use it in GitHub Desktop.
USG Scripts
This file contains hidden or 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 | |
| set -eu | |
| WORKDIR=$(set -eu; mktemp -d); | |
| DESTINATION="changeme@hostname:~/usg-backup/" | |
| echo "Dumping configuration" | |
| mca-ctrl -t dump > "$WORKDIR/info.json" | |
| mca-ctrl -t dump-cfg > "$WORKDIR/config.json" | |
| echo "Uploading" | |
| scp -r -q $WORKDIR/* "$DESTINATION" | |
| scp -r -q /{config,home,root} "$DESTINATION" | |
| # For some reason, copying /etc exits with exit code 130. Ignore that... | |
| scp -r -q /etc "$DESTINATION" || true | |
| echo "Done!" | |
| curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/changeme |
This file contains hidden or 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 | |
| SCRIPTS_DIR="/config/scripts/post-provision.d"; | |
| LOG_FILE="/var/log/postprovision.log"; | |
| PID_FILE="/var/run/postprovision.pid"; | |
| if [ "$1" != "-" ]; then | |
| exec 3>&1 4>&2 | |
| trap 'exec 2>&4 1>&3' 0 1 2 3 | |
| exec 1>"${LOG_FILE}" 2>&1 | |
| fi | |
| if [ -f $PID_FILE ]; then | |
| PID=$(cat $PID_FILE); | |
| ps -p $PID > /dev/null 2>&1 | |
| if [ $? -eq 0 ]; then | |
| echo "Process already running" | |
| exit 1 | |
| fi | |
| fi | |
| echo $$ > $PID_FILE; | |
| echo "Started post provision at $(date -R)" | |
| while read -r file; do | |
| # Execute the script! | |
| echo "Executing ${file}"; | |
| $file; | |
| done < <(find "${SCRIPTS_DIR}" -type f | grep ".sh$") | |
| echo "Post provision successful at $(date -R)"; | |
| echo "Cleaning up"; | |
| source /opt/vyatta/etc/functions/script-template | |
| set -v | |
| configure | |
| delete system task-scheduler task post-provision | |
| commit | |
| save | |
| rm $PID_FILE | |
| exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment