Add excludes

This commit is contained in:
Austen Adler 2019-10-26 14:37:11 -04:00
parent 58aa9b95e6
commit 0efc9a416c
3 changed files with 36 additions and 18 deletions

View File

@ -71,8 +71,8 @@ location:
# Read exclude patterns from one or more separate named files, one pattern per # Read exclude patterns from one or more separate named files, one pattern per
# line. See the output of "borg help patterns" for more details. # line. See the output of "borg help patterns" for more details.
#exclude_from: exclude_from:
# - /etc/borgmatic/excludes - EXCLUDE_FROM_PLACEHOLDER
# Exclude directories that contain a CACHEDIR.TAG file. See # Exclude directories that contain a CACHEDIR.TAG file. See
# http://www.brynosaurus.com/cachedir/spec.html for details. Defaults to false. # http://www.brynosaurus.com/cachedir/spec.html for details. Defaults to false.

7
excludes Normal file
View File

@ -0,0 +1,7 @@
/storage/emulated/0/*/.thumbnails
/storage/emulated/0/Android
/storage/emulated/0/Download/*.bin
/storage/emulated/0/Download/*.exe
/storage/emulated/0/Download/Images
/storage/emulated/0/Movies
/storage/emulated/0/syncthing

43
init.sh
View File

@ -12,7 +12,11 @@ die() {
exit 1 exit 1
} }
install_requirements() { install_requirements() {
apt-get update LAST_UPDATE="$(stat -c %Y /data/data/com.termux/files/usr/var/cache/apt/pkgcache.bin)"
NOW="$(date +%s)"
if ((NOW - LAST_UPDATE > 60 * 60 * 24)); then
apt-get update
fi
apt-get upgrade -y apt-get upgrade -y
apt-get install -y python screen wget apt-get install -y python screen wget
@ -35,14 +39,14 @@ install_debs() {
replace () { replace () {
FILE="$1" FILE="$1"
PLACEHOLDER="${2}_PLACEHOLDER" PLACEHOLDER="${2}_PLACEHOLDER"
PROMT="$3" VALUE="$3"
DEFAULT="$4" if (( $# == 4 )); then
printf "$PROMT [$DEFAULT] > " PROMT="$4"
read -r RESP printf "%s" "$PROMT [$VALUE] > "
if [[ -z "$RESP" ]]; then read -r
VALUE="$DEFAULT" if [[ -n "$REPLY" ]]; then
else VALUE="$REPLY"
VALUE="$RESP" fi
fi fi
# Do the replacement # Do the replacement
@ -51,20 +55,29 @@ replace () {
install_templates() { install_templates() {
echo "Installling templates" echo "Installling templates"
BORGMATIC_CONFIG_FILE="$HOME/.config/borgmatic/config.yaml" BORGMATIC_CONFIG_FILE="$HOME/.config/borgmatic/config.yaml"
BORGMATIC_EXCLUDES_FILE="$HOME/.config/borgmatic/excludes"
if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_CONFIG_FILE" ]]; then if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_CONFIG_FILE" ]]; then
mkdir -p "$HOME/.config/borgmatic" mkdir -p "$HOME/.config/borgmatic"
cp "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" cp "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE"
set +x set -x
replace "$BORGMATIC_CONFIG_FILE" REPO "What is your repository?" "user@files:$(hostname)" replace "$BORGMATIC_CONFIG_FILE" REPO "user@files:$(hostname)" "What is your repository?"
replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "Cross filesystem?" "true" replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "true" "Cross filesystem?"
replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "Remote borg command?" "borg1" replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "borg1" "Remote borg command?"
replace "$BORGMATIC_CONFIG_FILE" PASSWORD "Encryption password?" "$(tr -dc "+|~=[];:\-/.,<>?'#@!$%^&*(){}_A-Z-a-z-0-9" < /dev/urandom | head -c32)" replace "$BORGMATIC_CONFIG_FILE" PASSWORD "$(tr -dc "+|~=[];:\-/.,<>?'#@!$%^&*(){}_A-Z-a-z-0-9" < /dev/urandom | head -c32)" "Encryption password?"
replace "$BORGMATIC_CONFIG_FILE" EXCLUDE_FROM "$BORGMATIC_EXCLUDES_FILE"
set -x set -x
echo "Config file differences:" echo "Config file differences:"
diff -Nu "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" || : diff -Nu "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" || :
fi fi
if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_EXCLUDES_FILE" ]]; then
mkdir -p "$HOME/.config/borgmatic"
cp "$SCRIPT_DIR/excludes" "$BORGMATIC_EXCLUDES_FILE"
fi
} }
install_complete() { install_complete() {
@ -84,8 +97,6 @@ install_complete() {
cd "/data/data/com.termux/files/usr/tmp/tmp.k5RE3ly9Hm" cd "/data/data/com.termux/files/usr/tmp/tmp.k5RE3ly9Hm"
# cd "$(mktemp -d)" # cd "$(mktemp -d)"
install_requirements install_requirements
# get_debs
# install_debs
install_templates "$1" install_templates "$1"
install_complete install_complete
} }