Skip to content

Instantly share code, notes, and snippets.

@adunstan
Created November 25, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adunstan/6d5169b6c2c63a638ec5 to your computer and use it in GitHub Desktop.
Save adunstan/6d5169b6c2c63a638ec5 to your computer and use it in GitHub Desktop.
etckeeper script for mirroring outside files
#!/bin/sh
set -e
# Based on nealmcb's + ErebusBat's script from http://serverfault.com/questions/211425/
# put this file in etckeeeper's commit.d directory
# in the config file set MIRROR_ROOT (somewhere under /etc) MIRROR_FILES and MIRROR_DIRS
# the latter two can contain wildcards
# all three symbols must be exported or they won't be seen by this script
# If you want other configuration data or files on the system also
# opportunistically tracked via etckeeper, use this script to copy them in.
# If there is a hook of some sort available related to the files
# you're mirroring, you can call etckeeper directly and track them
# proactively, rather than just opportunistically here.
mirror_dir() {
LOCAL_PATH=$1
# echo " $LOCAL_PATH"
mkdir -p $MIRROR_ROOT/$LOCAL_PATH
rsync -a $LOCAL_PATH/ $MIRROR_ROOT/$LOCAL_PATH
}
mirror_file() {
LOCAL_PATH=$1
DIRPATH=`dirname $LOCAL_PATH`
# echo " $LOCAL_PATH"
mkdir -p $MIRROR_ROOT/$DIRPATH
rsync -a $LOCAL_PATH $MIRROR_ROOT/$DIRPATH
}
for file in $MIRROR_FILES
do
test -e $file || continue
mirror_file $file
done
for dir in $MIRROR_DIRS
do
test -d $dir || continue
mirror_dir $dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment