-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-sync-linux.sh
43 lines (35 loc) · 1.92 KB
/
install-sync-linux.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
#!/bin/bash
if [ -n "$(command -v yum)" ]; then
sudo yum -y install unison
sudo yum -y install sshpass
fi
if [ -n "$(command -v apt-get)" ]; then
sudo apt-get -y install unison
sudo apt-get -y install sshpass
fi
mkdir ~/datadisk
mkdir -p ~/.unison/backup
chown -R $USER ~/datadisk
# create shortcut to backups dir and readme
ln -s ~/.unison/backup ~/datadisk/backup
echo 'In the event that you and a colleague are working on the same file simultaneously and changes are lost during the sync process, an old version of the file will be created in the backup folder.' > ~/datadisk/readme.txt
# get SFU credentials
echo 'Please input your SFU computing ID: '
read user
echo 'Please input your SFU computing password: '
read -s pass
# test if ssh key already exists; else generate one
if [ ! -e ~/.ssh/id_rsa.pub ]; then
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ""
fi
sshpass -p $pass ssh-copy-id [email protected]
if [ $? -eq 0 ]; then
echo "Install complete! The /datadisk folder in your home directory will now be automatically synced with any other machines you have running SFU's DataSync, and will be accessible from a browser at http://researchdata.sfu.ca/pydio."
else
echo "Install did not complete successfully. Please verify your credentials and try again. If you continue to have problems, please contact Alex Garnett at [email protected]."
fi
echo -e '#test for network conection\nfor interface in $(ls /sys/class/net/ | grep -v lo);\ndo\n if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then\nif ps aux | grep "~[/].datastage"; then\nexit\nelse\nunison ~/datadisk ssh://'$user'@researchdata.sfu.ca//home/'$user'/.pydiodata -batch -backups -copythreshold 5000 -prefer ~/.datadisk -ignore="Name *.tmp" -ignore="Name *~"\nfi\nfi\ndone' > ~/.datastage.sh
# Add to /etc/crontab
croncommand="bash /home/$user/.datastage.sh"
cronjob="*/5 * * * * $croncommand"
cat <(fgrep -i -v "$croncommand" <(crontab -l)) <(echo "$cronjob") | crontab -