-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbadeline
More file actions
executable file
·89 lines (81 loc) · 2.09 KB
/
Copy pathbadeline
File metadata and controls
executable file
·89 lines (81 loc) · 2.09 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Usage: see below
#
# This is a successor to
# <https://github.com/radian-software/madeline>, which I wrote after I
# realized that the entire project could basically be superseded by
# two tiny shell functions. Really the issue Madeline was solving was
# two separate issues: offloading rarely-used giant files, and
# offloading rarely-used directories with too many inodes. For the
# former issue, I realized there were just not that many of them, and
# I could create a manual organization scheme on my NAS for them. For
# the latter issue, I realized that the files didn't need to
# physically *go* anywhere, they just needed to not have so many
# inodes. Thus a simple pair of shell functions that tars and untars
# the pathname you give it. One nice thing is that because this is
# uncompressed tar, you can change the contents and re-tar, and Borg
# will still mostly deduplicate. Probably.
#
# alias bp='badeline put'
# alias bg='badeline get'
usage() {
cat <<"EOF" >&2
usage:
badeline get ARCHIVE.bad.tar
badeline put DIRECTORY
EOF
}
if (( "$#" == 0 )); then
usage
exit 1
fi
do_get() {
if (( "$#" != 1 )) || [[ "$1" != *.bad.tar ]]; then
usage
exit 1
elif [[ ! -f "$1" ]]; then
echo >&2 "fatal: not a file: $1"
exit 1
fi
target="${1%%.bad.tar}"
if [[ -e "${target}" || -L "${target}" ]]; then
echo >&2 "fatal: already exists: ${target}"
exit 1
fi
tar -C "$(dirname "$1")" -xf "$1"
rm "$1"
echo >&2 "extracted $(basename "$1")"
}
do_put() {
if (( "$#" != 1 )); then
usage
exit 1
elif [[ ! -d "$1" ]]; then
echo >&2 "fatal: no such directory: $1"
exit 1
fi
(
unset CDPATH
cd "$1"
target="$(basename "$PWD")"
cd ..
tar -cf "${target}.bad.tar" "${target}"
rm -rf "${target}"
echo >&2 "archived ${target}.bad.tar"
)
}
cmd="$1"
shift
case "${cmd}" in
get)
do_get "$@"
;;
put)
do_put "$@"
;;
*)
usage
exit 1
;;
esac