-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtmexcludes.sh
executable file
·93 lines (72 loc) · 1.55 KB
/
tmexcludes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
set -Cefu
plist='/Library/Preferences/com.apple.TimeMachine.plist'
tm_exclude_list() {
defaults read $plist SkipPaths
}
tm_exclude_write() {
sudo defaults write $plist SkipPaths -array "$@"
}
tm_exclude_load() {
file="$1"
eval tm_exclude_write "$(cat "$file")"
}
tm_exclude_system() {
sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"
}
tm_exclude_dump() {
tm_exclude_list | awk '
/\(/ { in_array=1; next }
/^\)/ { in_array=0 }
in_array {
gsub(/^[ \t]+|[,)\\]+$/,"",$0)
gsub(/^"+|"+$/,"",$0)
printf "\"%s\"\n", $0
}' | usort_join
}
usort_join() {
sort -u | paste -d ' ' -s -
}
case $- in
*i*)
set +Cefu
return 0
esac
errmsg() {
msg="${1:?}"
printf "${red}error:${reset} %s\n" "$msg"
exit 1
} >&2
checkfile() {
file=$1
[ -e "$file" ] || errmsg "$file: No such file or directory"
[ -d "$file" ] && errmsg "$file: Is a directory."
[ -r "$file" ] || errmsg "$file: Permission denied."
}
usage() {
progname=${0##*/}
progname="${progname%.*}"
printf '%s\n' "usage: $progname <command> ..." "" \
"Commands:" \
" list List current exclusions" \
" dump Write exclusions to output" \
" load <file> Load excludes from file" \
" system List built-in system excludes" \
exit 1
} >&2
main() {
[ $# -lt 1 ] || [ $# -gt 2 ] && usage
cmd=${1:-}
file=${2:-}
reset='\033[0m'
red='\033[31m'
[ -n "$file" ] && checkfile "$file"
case $cmd in
list) tm_exclude_list ;;
dump) tm_exclude_dump ;;
load) tm_exclude_load "$file" ;;
sys) tm_exclude_system ;;
*) usage
esac
}
main "$@"