Skip to content

Instantly share code, notes, and snippets.

@nickw444
Last active August 8, 2021 08:43
Show Gist options
  • Select an option

  • Save nickw444/e17d35ae2d6d748183aa53939d02798b to your computer and use it in GitHub Desktop.

Select an option

Save nickw444/e17d35ae2d6d748183aa53939d02798b to your computer and use it in GitHub Desktop.
USG Scripts
#!/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
#!/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