-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_unison.sh
executable file
·138 lines (115 loc) · 3.61 KB
/
set_unison.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# ## dependency: prepare_ubuntu_user.sh
local_dir=$(dirname $0)
cd $local_dir
. ./common.sh
usage="
Installs synchronization with the given server. It assumes the server is already setup and the user can ssh to it without password.
Usage:
$(basename $0) --server <ip/dns_name of the server> --server-doc-root <root of the documents in server>
--local-doc-root <root of the local documents> [--unison-settings <relative path of the unison settings>]
[--server-history-root <path of the history snapshots in the server>] [--user <username>]
where
--server - Address of the server. Can be IP or DNS name.
--server-doc-root - Full path of the copy of the documents in the server.
--local-doc-root - Full path of the local copy of the documents. Synchronization
strives to keep contents of this folder the same as --server-doc-root.
--unison-settings - Folder with the unison settings. This folder will be synchronized first.
Defaults to Unison
--server-history-root - Full path to the folder with history snapshots in the server. If not
specified, synchronization will not make history snapshot.
--user <username> - Name of the user for which context the synchronization will be run.
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
Example:
$(basename $0) --server szesciodysk --server-doc-root /nas_zfs/adam --local-doc-root /home/Adama-docs/Adam
"
dir_resolve()
{
cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
echo "`pwd -P`" # output full, link-resolved path
}
mypath=${0%/*}
mypath=`dir_resolve $mypath`
cd $mypath
unison_settings_relpath=Unison
user=$USER
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--help)
echo "$usage"
exit 0
;;
--log)
log=$1
shift
;;
--server)
server="$1"
shift
;;
--server-doc-root)
server_doc_root=$1
shift
;;
--local-doc-root)
local_doc_root=$1
shift
;;
--unison-settings)
unison_settings_relpath=$1
shift
;;
--server-history-root)
server_history_root=$1
shift
;;
--user)
user=$1
shift
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
;;
esac
done
if [ -n "$debug" ]; then
if [ -z "$log" ]; then
log=/dev/stdout
fi
fi
if [ -z $server ]; then
errcho "--server cannot be empty"
exit 1
fi
if [ -z $server_doc_root ]; then
errcho "--server-doc-root cannot be empty"
exit 1
fi
if [ -z $local_doc_root ]; then
errcho "--local-doc-root cannot be empty"
exit 1
fi
# 1. Install unison & unison-gtk
homedir=$(get_home_dir $user)
install_apt_packages unison unison-gtk
# 2. Make sure local docs exist
logmkdir "${local_doc_root}/${unison_settings_relpath}/do" $user
logmkdir "${local_doc_root}/${unison_settings_relpath}/roots" $user
# 3. Make sure Unison roots contain minimum files
textfile ${homedir}/.unison/roots.prf "root = ${local_doc_root}
root = ssh://${server}/${server_doc_root}" $user
make_symlink ${homedir}/.unison/roots.prf ${local_doc_root}/${unison_settings_relpath}/roots/roots.prf
# 4. Upload standard unison bootstrap files
install_file ${DIR}/files/unison/unison.prf "${local_doc_root}/${unison_settings_relpath}" $user
install_file ${DIR}/files/unison/do/do-unison.prf "${local_doc_root}/${unison_settings_relpath}/do" $user
# 5. Upload synchronization script
install_script files/sync-local "/usr/local/bin/sync-local" root
#TODO: dokończ skrypt sync-local.