-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_calibre_remote_dryrun.sh
73 lines (60 loc) · 1.21 KB
/
start_calibre_remote_dryrun.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
#!/bin/bash
server_ip="erficca.lan"
remote_user="calibre"
remote_path="/home/calibre/propirata"
#remote_path="/home/calibre/test_script"
temp_path="~/temp_calibre_library"
eval temp_path=$temp_path
#signal handling
trap \
"echo 'intercepted signal: closing...';\
_umount;\
_remove;\
exit 1" SIGHUP SIGINT SIGTERM
#umount path
function _umount {
fusermount -uz $temp_path &> /dev/null
if [ $? -ne 0 ]; then
echo "failed umounting $temp_path"
fi
}
#remove temp folder
function _remove {
mount | grep " $temp_path " &> /dev/null
if [ $? -ne 0 ]; then
rm -R $temp_path &> /dev/null
fi
}
#test sshfs installation
which sshfs &> /dev/null
if [ $? -ne 0 ]; then
echo "sshfs is not installed"
exit 1
fi
#test if server is reachable
ping -W 3 -c 1 erficca.lan &> /dev/null
if [ $? -ne 0 ]; then
echo "server it's not reachable on \"$server_ip\""
exit 3
fi
#create directory
mkdir -p $temp_path &> /dev/null
if [ $? -ne 0 ]; then
echo "failed to create $temp_path"
exit 4
fi
#mount remote hdd
sshfs $remote_user@$server_ip:$remote_path $temp_path
if [ $? -ne 0 ]; then
echo "failed on sshfs"
exit 5
fi
#test folder
ls $temp_path
if [ $? -ne 0 ]; then
echo "failed to start calibre"
exit 6
fi
_umount
_remove
exit 0