-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·96 lines (83 loc) · 2.03 KB
/
deploy
File metadata and controls
executable file
·96 lines (83 loc) · 2.03 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
90
91
92
93
94
95
96
#!/usr/bin/env bash
#TODO make the -mount option a user preference
finddeploy() {
find $1 -mount -name ".deploy" 2>/dev/null | tr '\n' ' '
}
rsync_args() {
echo "--recursive --update --executability --human-readable --progress"
}
build_longargs(){
awk -F ':' '{
for (i=1; i<=NF; i++)
printf "--'$argstring'='"'"'"$i"'"'"' "
}'
}
rsync_exclude() {
( argstring=exclude; echo "$@" | build_longargs )
}
rsync_include() {
( argstring=include; echo "$@" | build_longargs )
}
rsync_host() {
test -v
}
#convert an xdg user directory to its root equivalent and vice-versa
xdg_dir_convert() {
if [ "$1" -ef "$XDG_CONFIG_DIRS" ]; then
echo "$XDG_CONFIG_HOME"
elif [ "$1" -ef "$XDG_CACHE_DIRS" ]; then
echo "$XDG_CACHE_HOME"
elif [ "$1" -ef "$XDG_DATA_DIRS" ]; then
echo "$XDG_DATA_HOME"
elif [ "$1" -ef "$XDG_CONFIG_HOME" ]; then
echo "$XDG_CONFIG_DIRS"
elif [ "$1" -ef "$XDG_CACHE_HOME" ]; then
echo "$XDG_CACHE_DIRS"
elif [ "$1" -ef "$XDG_DATA_HOME" ]; then
echo "$XDG_DATA_DIRS"
else
return 1
fi
}
#true of the given file is within the HOME of its owner
is_user_file() {
usr=$(stat -c '%U' $1)
realpath $1 | grep -E "^$(eval echo "~$usr")"
}
deploy_dir() { #takes path to .deploy file as argument
set -u
src="$(dirname $1)/"
source $1
#there are 4 possible modes for deployment: user to root, user to user, root to root, root to user
#for now, only user to root is being implemented
#TODO add ROOTEXCLUDE, ROOTINCLUDE, USEREXCLUDE, USERINCLUDE
test -v ROOTDIR ||
ROOTDIR="$(xdg_dir_convert $src/..)/$(basename $src)" || {
echo "Could not resolve destination for $src"
return 1
}
dest="$ROOTDIR"
{ rsync_include $(test -v INCLUDE && echo $INCLUDE)
rsync_exclude $(test -v EXCLUDE && echo $EXCLUDE):.deploy
rsync_args
echo "$src kico:$dest"
} | xargs rsync
}
while getopts ":u:h" opt; do
case $opt in
u)
user="$OPTARG"
;;
h)
echo "you are beyond help"
exit
;;
:)
echo "Option -$OPTARG requires an argument" >&2
exit 1
;;
esac
done
for d in $(finddeploy); do
(deploy_dir $d)
done