forked from philcryer/lipsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·241 lines (209 loc) · 8.12 KB
/
install.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
# Distributed under the terms of the BSD License.
# Copyright (c) 2011 Phil Cryer [email protected]
# Source https://github.com/philcryer/lipsync
#clear
stty erase '^?'
echo "lipsync install script"
########################################
# Check users's privileges
########################################
echo -n "* Checking user's privileges..."
if [ "$(id -u)" != "0" ]; then
sudo -v >/dev/null 2>&1 || { echo; echo " ERROR: User $(whoami) is not root, and does not have sudo privileges" ; exit 1; }
else
echo "ok"
fi
########################################
# Check Linux variant
########################################
echo -n "* Checking Linux variant..."
if [[ $(cat /etc/issue.net | cut -d' ' -f1) == "Debian" ]] || [[ $(cat /etc/issue.net | cut -d' ' -f1) == "Ubuntu" ]];then
echo "ok"
else
echo; echo " ERROR: this installer was written to work with Debian/Ubuntu,"
echo " it could work (tm) with your system - let us know if it does"
fi
########################################
# Check for required software
########################################
echo -n "* Checking for required software..."
type -P ssh &>/dev/null || { echo; echo " ERROR: lipsync requires ssh-client but it's not installed" >&2; exit 1; }
#type -P ssh-copy-id &>/dev/null || { echo; echo " ERROR: lipsync requires ssh-copy-id but it's not installed" >&2; exit 1; }
type -P rsync &>/dev/null || { echo; echo " ERROR: lipsync requires rsync but it's not installed" >&2; exit 1; }
type -P lsyncd &>/dev/null || { echo; echo " ERROR: lipsync requires lsyncd but it's not installed" >&2; exit 1; }
LSYNCD_VERSION=`lsyncd -version | cut -d' ' -f2 | cut -d'.' -f1`
if [ $LSYNCD_VERSION -lt '2' ]; then
echo; echo " ERROR: lipsync requires lsyncd 2.x or greater, but it's not installed" >&2; exit 1
fi
echo "ok"
########################################
# Define functions
########################################
questions(){
echo -n "> SERVER: IP or domainname: "
read remote_server
echo -n "> SERVER: SSH port: "
read port
echo -n "> SERVER: username: "
read username_server
echo -n "> CLIENT: username: "
read username_client
echo -n "> CLIENT: directory to be synced: "
read lipsync_dir_local
echo -n "> SERVER: remote directory to be synced: "
read lipsync_dir_remote
}
ssh.keygen(){
if ssh -i /home/${username_client}/.ssh/id_dsa -p ${port} -o "KbdInteractiveAuthentication=no" -o "PasswordAuthentication=no" ${username_server}@${remote_server} echo "hello" > /dev/null
then
echo " ssh key exists here and on server, skipping key generation and transfer steps"
return
else
if [ -f '/home/${username_client}/.ssh/id_dsa' ]; then
echo "* Existing SSH key found for ${username_client} backing up..."
mv /home/${username_client}/.ssh/id_dsa /home/${username_client}/.ssh/id_dsa-OLD
if [ $? -eq 0 ]; then
echo "done"
else
echo; echo " ERROR: there was an error backing up the SSH key"; exit 1
fi
fi
echo "* Checking for an SSH key for ${username_client}..."
if [ -f /home/${username_client}/.ssh/id_dsa ]; then
echo "* Existing key found, not creating a new one..."
else
echo -n "* No existing key found, creating SSH key for ${username_client}..."
ssh-keygen -q -N '' -f /home/${username_client}/.ssh/id_dsa
if [ $? -eq 0 ]; then
chown -R $username_client:$username_client /home/$username_client/.ssh
echo "done"
else
echo; echo " ERROR: there was an error generating the ssh key"; exit 1
fi
fi
echo "* Transferring ssh key for ${username_client} to ${remote_server} on port ${port} (login as $username_server now)...";
if which ssh-copy-id &> /dev/null; then
su ${username_client} -c "ssh-copy-id -i /home/${username_client}/.ssh/id_dsa.pub '-p ${port} ${username_server}@${remote_server}'" >> /dev/null
if [ $? -eq 0 ]; then
X=0 #echo "done"
else
echo
echo " ERROR: there was an error transferring the ssh key";
exit 1
fi
else
su ${username_client} -c "cat /home/${username_client}/.ssh/id_rsa.pub | ssh ${username_server}@$remote_server -p ${port} 'cat - > /home/${username_server}/.ssh/id_dsa.pub'" >> /dev/null
if [ $? -eq 0 ]; then
X=0 #echo "done"
else
echo
echo " ERROR: there was an error transferring the ssh key";
exit 1
fi
fi
echo -n "* Setting permissions on the ssh key for ${username_server} on ${remote_server} on port ${port}...";
su ${username_client} -c "SSH_AUTH_SOCK=0 ssh ${username_server}@${remote_server} -p ${port} 'chmod 700 .ssh'"
if [ $? -eq 0 ]; then
echo "done"
else
echo; echo " ERROR: there was an error setting permissions on the ssh key for ${username_server} on ${remote_server} on port ${port}..."; exit 1
fi
fi
}
build.conf(){
echo -n "* Creating lipsyncd config..."
sed etc/lipsyncd_template > etc/lipsyncd \
-e 's|LSLOCDIR|'$lipsync_dir_local/'|g' \
-e 's|LSUSERCLIENT|'$username_client'|g' \
-e 's|LSUSERSERVER|'$username_server'|g' \
-e 's|LSPORT|'$port'|g' \
-e 's|LSREMSERV|'$remote_server'|g' \
-e 's|LSREMDIR|'$lipsync_dir_remote/'|g'
echo "done"
}
deploy(){
echo "* Deploying lipsync..."
echo -n " > /usr/local/bin/lipsync..."
cp bin/lipsync /usr/local/bin; chown root:root /usr/local/bin/lipsync; chmod 755 /usr/local/bin/lipsync
cp bin/lipsync-notify /usr/local/bin; chown root:root /usr/local/bin/lipsync-notify; chmod 755 /usr/local/bin/lipsync-notify
echo "done"
echo -n " > /usr/local/bin/lipsyncd..."
if [ -x /usr/local/bin/lsyncd ]; then
ln -s /usr/local/bin/lsyncd /usr/local/bin/lipsyncd
fi
echo "done"
echo -n " > /etc/init.d/lipsyncd..."
cp etc/init.d/lipsyncd /etc/init.d
echo "done"
echo -n " > Installing cron for user $username_client..."
newcronjob="* * * * * /usr/local/bin/lipsync >/dev/null 2>&1" #define entry for crontab
(crontab -u $username_client -l; echo "$newcronjob") | crontab -u $username_client - #list crontab, read entry from crontab, add line from stdin to crontab
echo "done"
echo -n " > /etc/lipsyncd..."
mv etc/lipsyncd /etc/
echo "done"
echo -n " > /usr/share/doc/lipsyncd..."
if [ ! -d /usr/share/doc/lipsyncd ]; then
mkdir /usr/share/doc/lipsyncd
fi
cp README* LICENSE uninstall.sh docs/* /usr/share/doc/lipsyncd
echo "done"
echo -n " > /home/$username_client/.lipsyncd..."
if [ ! -d /home/$username_client/.lipsyncd ]; then
mkdir /home/$username_client/.lipsyncd
chown $username_client:$username_client /home/$username_client/.lipsyncd
fi
echo "done"
echo -n " > /home/$username_client/.lipsyncd/lipsyncd.log..."
touch /home/$username_client/.lipsyncd/lipsyncd.log
chown $username_client:$username_client /home/$username_client/.lipsyncd/lipsyncd.log
chmod g+w /home/$username_client/.lipsyncd/lipsyncd.log
echo "done"
echo -n " > checking for $lipsync_dir_local..."
if [ ! -d $lipsync_dir_local ]; then
echo; echo -n " > $lipsync_dir_local not found, creating..."
mkdir $lipsync_dir_local
chown $username_client:$username_client $lipsync_dir_local
fi
echo "done"
echo "lipsync installed `date`" > /home/$username_client/.lipsyncd/lipsyncd.log
}
initial_sync(){
}
start(){
/etc/init.d/lipsyncd start; sleep 2
. /etc/lipsyncd
if [ -f /home/$USER_NAME_CLIENT/.lipsyncd/lipsyncd.pid ]; then
# echo " NOTICE: lipsyncd is running as pid `cat /home/$username_client/.lipsyncd/lipsyncd.pid`"
echo " NOTICE: lipsyncd is running as pid `pidof lipsyncd`"
echo " Check lipsyncd.log for details"
else
echo " NOTICE: lipsyncd failed to start..."
echo " Check /home/$username_client/.lipsyncd/lipsyncd.log for details"
fi
}
########################################
# Install lipsyncd
########################################
if [ "${1}" = "uninstall" ]; then
echo " ALERT: Uninstall option chosen, all lipsync files and configuration will be purged!"
echo -n " ALERT: To continue press enter to continue, otherwise hit ctrl-c now to bail..."
read continue
uninstall
exit 0
elif [ "${1}" = "restart" ]; then
initial_sync
else
questions
ssh.keygen
build.conf
deploy
initial_sync
fi
########################################
# Start lipsyncd
########################################
echo "lipsync setup complete, starting lipsyncd..."
start
exit 0