22
22
23
23
function stop_sync {
24
24
echo " [$stat_y ] Trying to stop a running BitTorrent Sync instance"
25
- sleep 0.6
25
+ sleep 0.5
26
26
syncpid=" $( ps aux | grep btsync | grep -v grep | grep -v /bin/bash | awk ' {print $2}' ) "
27
27
if [ -z $syncpid ]; then
28
28
echo " [$stat_ok ] There is no instance of BitTorrent Sync running "
29
- sleep 0.6
29
+ sleep 0.5
30
30
else
31
31
err_cmd=$( sudo pkill -15 -x btsync 2>&1 > /dev/null)
32
32
if [ $? -ne 0 ]; then
33
33
echo " [$stat_x ] Error: There was an error stopping the BitTorrent Sync instance"
34
34
if [ ! $err_cmd == " " ]; then
35
35
echo " [$stat_x ] $err_cmd "
36
36
fi
37
- sleep 0.6
37
+ sleep 0.5
38
38
exit 1
39
39
else
40
40
echo " [$stat_ok ] The running instance of BitTorrent Sync has been stopped (PID: $syncpid )"
41
- sleep 0.6
41
+ sleep 0.5
42
42
fi
43
43
fi
44
44
}
45
45
46
46
function install_preperations {
47
47
if [ ! -d " $btsdir " ]; then
48
48
echo " [$stat_ok ] Trying to create installation folder $btsdir "
49
- sleep 0.6
49
+ sleep 0.5
50
50
err_cmd=$( mkdir $btsdir 2>&1 > /dev/null)
51
51
if [ $? -ne 0 ]; then
52
52
echo " [$stat_x ] Could not create installation folder $btsdir "
53
53
echo " [$stat_x ] $err_cmd "
54
54
exit 1
55
55
fi
56
56
echo " [$stat_ok ] BitTorrent Sync installation folder has been created ($btsdir )"
57
- sleep 0.6
57
+ sleep 0.5
58
58
else
59
59
echo " [$stat_x ] BitTorrent Sync installation folder $btsdir already exists"
60
- sleep 0.6
60
+ sleep 0.5
61
61
read -r -p " [$stat_x ] Delete all files and sub-folders inside $btsdir ? [Y/N]: " response
62
62
if [[ $response =~ ^([yY][eE][sS]| [yY])$ ]]; then
63
63
echo -ne " [$stat_y ] Deleting all files in $btsdir \r"
@@ -71,48 +71,48 @@ function install_preperations {
71
71
fi
72
72
if [ -f $btsdir /btsync_arm.tar.gz ]; then
73
73
echo " [$stat_y ] A binary file already exists"
74
- sleep 0.6
74
+ sleep 0.5
75
75
echo " [$stat_ok ] Trying to remove and re-download the latest binary"
76
76
err_cmd=$( rm $btsdir /btsync_arm.tar.gz 2>&1 > /dev/null)
77
77
if [ $? -ne 0 ]; then
78
78
echo " [$stat_x ] Error: Could not remove $btsdir /btsync_arm.tar.gz"
79
79
echo " [$stat_x ] $err_cmd "
80
- sleep 0.6
80
+ sleep 0.5
81
81
exit 1
82
82
fi
83
83
fi
84
84
fi
85
85
}
86
86
87
87
function install {
88
- sleep 0.6
88
+ sleep 0.5
89
89
err_cmd=$( cd $btsdir 2>&1 > /dev/null)
90
90
if [ $? -ne 0 ]; then
91
91
echo " [$stat_x ] Error: Could not change to $btsdir since it does not exist"
92
92
echo " [$stat_x ] $err_cmd "
93
93
exit 1
94
94
fi
95
95
if [ -z $dllink ]; then
96
- echo " [$stat_ok ] Downloading the latest stable version from BitTorrent Inc"
96
+ echo " [$stat_y ] Downloading the latest stable version from BitTorrent Inc"
97
97
curl -# -o $btsdir /btsync_arm.tar.gz https://download-cdn.getsync.com/stable/linux-arm/BitTorrent-Sync_arm.tar.gz
98
98
if [ $? -ne 0 ]; then
99
99
echo " [$stat_x ] Error: There was an error downloading the BiTorrent Sync binary"
100
100
exit 1
101
101
else
102
- echo " [ $stat_ok ] Successfully downloaded the BiTorrent Sync binary"
102
+ echo -en " \e[1A " ; echo -e " \e[0K\r[ $stat_ok ] Successfully downloaded the binary"
103
103
fi
104
104
else
105
- echo " [$stat_ok ] Downloading the binary from the link provided"
105
+ echo " [$stat_y ] Downloading the binary from the link provided"
106
106
curl -# -o $btsdir /btsync_arm.tar.gz $dllink
107
107
if [ $? -ne 0 ]; then
108
108
echo " [$stat_x ] Error: There was an error downloading the file using the link you provided. Please check the URL and try again"
109
109
exit 1
110
110
else
111
- echo " [ $stat_ok ] Successfully downloaded the BiTorrent Sync binary"
111
+ echo -en " \e[1A " ; echo -e " \e[0K\r[ $stat_ok ] Successfully downloaded the binary"
112
112
fi
113
113
fi
114
114
if [ $? -ne 0 ]; then
115
- echo -ne " [$stat_x ] Error: There was an error downloading the BiTorrent Sync binary\r "
115
+ echo -ne " [$stat_x ] Error: There was an error downloading the binary"
116
116
echo -ne ' \n'
117
117
exit 1
118
118
fi
@@ -122,7 +122,7 @@ function install {
122
122
echo " [$stat_x ] $err_cmd "
123
123
exit 1
124
124
fi
125
- echo " [$stat_ok ] Extraced the BitTorrent Sync binary to /usr/bin/btsync"
125
+ echo " [$stat_ok ] Extraced the binary to /usr/bin/btsync"
126
126
err_cmd=$( rm $btsdir /btsync_arm.tar.gz 2>&1 > /dev/null)
127
127
if [ $? -ne 0 ]; then
128
128
echo " [$stat_x ] Error: Could not remove $btsdir /btsync_arm.tar.gz"
@@ -137,9 +137,9 @@ function btsync_initscript {
137
137
else
138
138
err_cmd=$( curl -o $btsdir /btsync_init https://raw.githubusercontent.com/moritzdietz/pi-syncscript/master/configuration-files/btsync 2>&1 > /dev/null)
139
139
if [ $? -ne 0 ]; then
140
- echo " [$stat_x ] Error: There was an error downloading the BitTorrent Sync init.d script"
140
+ echo " [$stat_x ] Error: There was an error downloading the init.d script"
141
141
echo " [$stat_x ] $err_cmd "
142
- sleep 0.6
142
+ sleep 0.5
143
143
exit 1
144
144
else
145
145
sed -r -i.tmp " s/\bpi\b/$user /g" $btsdir /btsync_init
@@ -154,9 +154,9 @@ function btsyncconfig {
154
154
if [ ! -f /etc/btsync/config.json ]; then
155
155
err_cmd=$( curl -o $btsdir /config.json https://raw.githubusercontent.com/moritzdietz/pi-syncscript/master/configuration-files/config.json 2>&1 > /dev/null)
156
156
if [ $? -ne 0 ]; then
157
- echo " [$stat_x ] Error: There was an error downloading the BitTorrent Sync configuration file"
157
+ echo " [$stat_x ] Error: There was an error downloading the configuration file"
158
158
echo " [$stat_x ] $err_cmd "
159
- sleep 0.6
159
+ sleep 0.5
160
160
exit 1
161
161
else
162
162
sed -r -i.tmp " s/\bpi\b/$user /g" $btsdir /config.json
@@ -173,7 +173,7 @@ function btsyncconfig {
173
173
174
174
function backup {
175
175
backup_date=$( date +" %d-%m-%Y_%H-%M-%S" )
176
- backup_reason=" The BitTorrent Sync is being backed up as (/home/ $user /btsync_backup_ $backup_date .tar.gz) "
176
+ backup_reason=" BitTorrent Sync is being backed up"
177
177
# Look for the 4 common signals that indicate this script was killed.
178
178
# If the background command was started, kill it, too.
179
179
if [ -e ${btsdir} ]; then
@@ -197,7 +197,7 @@ function backup {
197
197
echo -ne " [Ooo] ${backup_reason} \r" && sleep 0.2
198
198
echo -ne " [ooo] ${backup_reason} \r"
199
199
done
200
- echo -e " \e[0K\r[$stat_ok ] BitTorrent Sync has been successfully backed up"
200
+ echo -e " \e[0K\r[$stat_ok ] BitTorrent Sync has been successfully backed up at /home/ $user /btsync_backup_ $backup_date .tar.gz "
201
201
}
202
202
203
203
function remove {
@@ -230,14 +230,20 @@ function remove {
230
230
fi
231
231
}
232
232
233
+ function version_check {
234
+ if [ -f /usr/bin/btsync ]; then
235
+ echo $( /usr/bin/btsync -help | grep " BitTorrent Sync" | awk {' print $3" "$4' })
236
+ fi
237
+ }
238
+
233
239
read -r -p " [$stat_y ] Choose one of the BitTorrent Sync Script options [(i)nstall(default)/(u)pdate/(b)ackup/(r)emove]: " response
234
240
if [[ $response =~ ^([u| U]| [u| U]pdate)$ ]]; then
235
241
stop_sync
236
- echo " [$stat_ok ] Updating BitTorrent Sync from version" $( /usr/bin/btsync -help | grep " BitTorrent Sync " | awk { ' print $3" "$4 ' } ) " to the latest available version"
242
+ echo " [$stat_ok ] Updating BitTorrent Sync from version $( version_check ) to the latest available version"
237
243
install $dllink
238
244
btsync_initscript
239
245
btsyncconfig
240
- echo " [$stat_ok ] Updated BitTorrent Sync to version" $( /usr/bin/btsync -help | grep " BitTorrent Sync " | awk { ' print $3" "$4 ' } )
246
+ echo " [$stat_ok ] Updated BitTorrent Sync to version $( version_check ) "
241
247
echo " [$stat_ok ] You can now start BitTorrent Sync by typing \" sudo service btsync start\" "
242
248
exit 0
243
249
elif [[ $response =~ ^([b| B]| [b| B]ackup)$ ]]; then
@@ -250,7 +256,7 @@ elif [[ $response =~ ^(""|[i|I]|[i|I]nstall)$ ]]; then
250
256
install
251
257
btsync_initscript
252
258
btsyncconfig
253
- echo " [$stat_ok ] Installed BitTorrent Sync version" $( /usr/bin/btsync -help | grep " BitTorrent Sync " | awk { ' print $3" "$4 ' } )
259
+ echo " [$stat_ok ] Installed BitTorrent Sync version $( version_check ) "
254
260
echo " [$stat_ok ] You can now start BitTorrent Sync by typing \" sudo service btsync start\" "
255
261
exit 0
256
262
elif [[ $response =~ ^(" " | [r| R]| [r| R]emove)$ ]]; then
@@ -259,4 +265,4 @@ elif [[ $response =~ ^(""|[r|R]|[r|R]emove)$ ]]; then
259
265
else
260
266
echo " [$stat_x ] You did not choose one of the provided script options. Please try again."
261
267
exit 0
262
- fi
268
+ fi
0 commit comments