From 0efc9a416c1779c5c67fa6c6efec89ee81699deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Austen=E2=80=9D?= Date: Sat, 26 Oct 2019 14:37:11 -0400 Subject: [PATCH] Add excludes --- config.yaml | 4 ++-- excludes | 7 +++++++ init.sh | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 excludes diff --git a/config.yaml b/config.yaml index 138689c..090543d 100644 --- a/config.yaml +++ b/config.yaml @@ -71,8 +71,8 @@ location: # Read exclude patterns from one or more separate named files, one pattern per # line. See the output of "borg help patterns" for more details. - #exclude_from: - # - /etc/borgmatic/excludes + exclude_from: + - EXCLUDE_FROM_PLACEHOLDER # Exclude directories that contain a CACHEDIR.TAG file. See # http://www.brynosaurus.com/cachedir/spec.html for details. Defaults to false. diff --git a/excludes b/excludes new file mode 100644 index 0000000..6933228 --- /dev/null +++ b/excludes @@ -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 diff --git a/init.sh b/init.sh index c370996..454c5ad 100755 --- a/init.sh +++ b/init.sh @@ -12,7 +12,11 @@ die() { exit 1 } 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 install -y python screen wget @@ -35,14 +39,14 @@ install_debs() { replace () { FILE="$1" PLACEHOLDER="${2}_PLACEHOLDER" - PROMT="$3" - DEFAULT="$4" - printf "$PROMT [$DEFAULT] > " - read -r RESP - if [[ -z "$RESP" ]]; then - VALUE="$DEFAULT" - else - VALUE="$RESP" + VALUE="$3" + if (( $# == 4 )); then + PROMT="$4" + printf "%s" "$PROMT [$VALUE] > " + read -r + if [[ -n "$REPLY" ]]; then + VALUE="$REPLY" + fi fi # Do the replacement @@ -51,20 +55,29 @@ replace () { install_templates() { echo "Installling templates" BORGMATIC_CONFIG_FILE="$HOME/.config/borgmatic/config.yaml" + BORGMATIC_EXCLUDES_FILE="$HOME/.config/borgmatic/excludes" if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_CONFIG_FILE" ]]; then mkdir -p "$HOME/.config/borgmatic" cp "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" - set +x - replace "$BORGMATIC_CONFIG_FILE" REPO "What is your repository?" "user@files:$(hostname)" - replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "Cross filesystem?" "true" - replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "Remote borg command?" "borg1" - replace "$BORGMATIC_CONFIG_FILE" PASSWORD "Encryption password?" "$(tr -dc "+|~=[];:\-/.,<>?'#@!$%^&*(){}_A-Z-a-z-0-9" < /dev/urandom | head -c32)" + set -x + replace "$BORGMATIC_CONFIG_FILE" REPO "user@files:$(hostname)" "What is your repository?" + replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "true" "Cross filesystem?" + replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "borg1" "Remote borg command?" + 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 echo "Config file differences:" diff -Nu "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" || : fi + + if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_EXCLUDES_FILE" ]]; then + mkdir -p "$HOME/.config/borgmatic" + cp "$SCRIPT_DIR/excludes" "$BORGMATIC_EXCLUDES_FILE" + fi } install_complete() { @@ -84,8 +97,6 @@ install_complete() { cd "/data/data/com.termux/files/usr/tmp/tmp.k5RE3ly9Hm" # cd "$(mktemp -d)" install_requirements -# get_debs -# install_debs install_templates "$1" install_complete }