-
Notifications
You must be signed in to change notification settings - Fork 59
/
install.sh
executable file
·240 lines (210 loc) · 7.91 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
#!/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/CLIENT: username (must exist on both): "
read username
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 ~${username}/.ssh/id_dsa -p ${port} -o "KbdInteractiveAuthentication=no" -o "PasswordAuthentication=no" ${username}@${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 '~${username}/.ssh/id_dsa' ]; then
echo "* Existing SSH key found for ${username} backing up..."
mv ~${username}/.ssh/id_dsa ~${username}/.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}..."
if [ -f ~${username}/.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}..."
ssh-keygen -q -N '' -f ~${username}/.ssh/id_dsa
if [ $? -eq 0 ]; then
chown -R $username:$username ~${username}/.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} to ${remote_server} on port ${port} (login as $username now)...";
if which ssh-copy-id &> /dev/null; then
su ${username} -c "ssh-copy-id -i ~${username}/.ssh/id_dsa.pub '-p ${port} ${username}@${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} -c "cat ~${username}/.ssh/id_dsa.pub | ssh $remote_server -p ${port} 'cat - >> ~${username}/.ssh/authorized_keys'" >> /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} on ${remote_server} on port ${port}...";
su ${username} -c "SSH_AUTH_SOCK=0 ssh ${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} 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|LSUSER|'$username'|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
if [ -x /usr/bin/lsyncd ]; then
ln -s /usr/bin/lsyncd /usr/local/bin/lipsyncd
fi
echo "done"
echo -n " > /etc/init.d/lipsyncd..."
install -m 755 etc/init.d/lipsyncd /etc/init.d/
echo "done"
echo -n " > Installing cron for user $username..."
newcronjob="* * * * * /usr/local/bin/lipsync >/dev/null 2>&1" #define entry for crontab
(crontab -u $username -l; echo "$newcronjob") | crontab -u $username - #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 " > ~$username/.lipsyncd..."
if [ ! -d ~$username/.lipsyncd ]; then
mkdir ~$username/.lipsyncd
chown $username:$username ~$username/.lipsyncd
fi
echo "done"
echo -n " > ~$username/.lipsyncd/lipsyncd.log..."
touch ~$username/.lipsyncd/lipsyncd.log
chown $username:$username ~$username/.lipsyncd/lipsyncd.log
chmod g+w ~$username/.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:$username $lipsync_dir_local
fi
echo "done"
echo "lipsync installed `date`" > ~$username/.lipsyncd/lipsyncd.log
}
initial_sync(){
echo -n "* Doing inital sync with server..."
. /etc/lipsyncd
su $USER_NAME -c 'rsync -rav --stats --log-file=~'$USER_NAME'/.lipsyncd/lipsyncd.log -e "ssh -l '$USER_NAME' -p '$SSH_PORT'" '$REMOTE_HOST':'$REMOTE_DIR' '$LOCAL_DIR''
echo "Initial sync `date` Completed" > ~$username/.lipsyncd/lipsyncd.log
}
start(){
/etc/init.d/lipsyncd start; sleep 2
if [ -f ~$username/.lipsyncd/lipsyncd.pid ]; then
# echo " NOTICE: lipsyncd is running as pid `cat ~$username/.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 ~$username/.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
else
questions
ssh_keygen
build_conf
deploy
initial_sync
fi
########################################
# Start lipsyncd
########################################
echo "lipsync setup complete, starting lipsyncd..."
start
exit 0