-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhousekeep
More file actions
executable file
·62 lines (55 loc) · 1.22 KB
/
housekeep
File metadata and controls
executable file
·62 lines (55 loc) · 1.22 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
#!/usr/bin/env bash
tags_dir=${TNU_TAG_DIR:-$HOME/tags}
store_dir=${TNU_STORE_DIR:-$HOME/store}
today=$store_dir/$(date -I)
err() {
2>&1 printf 'an error occured: %s' "$1"
exit 1
}
parseargs() {
while [ $# -gt 0 ]
do
arg=$1
case $arg in
# handle options
-s|--store-dir)
store_dir=$2
test -d "$store_dir" ||
err "$arg must specify a valid directory"
shift
;;
-t|--tags-dir)
tags_dir=$2
test -d "$tags_dir" ||
err "$arg must specify a valid directory"
shift
;;
# treat all other flags as basic switches and set a new variable
# with the same name as the switch to the value of "true"
# do this for both short and long options
-?)
opt="${arg:1}";
printf -v "$opt" '%s' "true" 2> /dev/null ||
err "Invalid switch: $arg" # printf will likely only fail if
# $opt is an invalid variable name
;;
--*)
opt="${arg:2}"
printf -v "$opt" '%s' "true" 2> /dev/null ||
err "Invalid switch: $arg"
;;
esac
shift
done
}
# flags
v=
parseargs "$@"
for dir in "$store_dir"/*
do
if [[ $dir < $today ]]; then
[ "$v" ] && printf 'Removing write permisson from %s\n' "$dir"
chmod -w -R "$dir"
fi
done
symlinks -cr "$tags_dir"