-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_calibre_remote.sh
87 lines (67 loc) · 1.38 KB
/
start_calibre_remote.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
#!/bin/bash
server_ip='erficca.lan'
remote_user='calibre'
remote_path='/home/calibre/propirata'
remote_port=22
temp_path='~/temp_calibre_library'
### DO NOT MODIFY UNDER THIS LINE ###
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 calibre installation
which calibre &> /dev/null
if [ $? -ne 0 ]; then
echo "calibre application not found"
exit 2
fi
#test if server is reachable
ping -W 3 -c 1 $server_ip &> /dev/null
if [ $? -ne 0 ]; then
echo "server it's not reachable on \"$server_ip\""
exit 3
fi
#create directory
mkdir $temp_path &> /dev/null
if [ $? -ne 0 ]; then
echo "failed to create $temp_path"
exit 4
fi
#mount remote hdd
sshfs -p $remote_port $remote_user@$server_ip:$remote_path $temp_path
if [ $? -ne 0 ]; then
echo "failed on sshfs"
exit 5
fi
#calibre start
calibre --with-library=$temp_path
if [ $? -ne 0 ]; then
echo "failed to start calibre"
exit 6
fi
_umount
_remove
exit 0