-
Notifications
You must be signed in to change notification settings - Fork 2
/
calibre-update
executable file
·92 lines (78 loc) · 2.3 KB
/
calibre-update
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
#!/bin/bash
# <SCRIPTNAME>
# <WHAT DOES THIS SCRIPT DO?>
# Copyright (C) 2014-2015 Alexander Swen <alex@swen.nu>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Alexander Swen
# Private contact: alex@swen.nu
# CHANGELOG:
# <DATE> A.Swen created.
# SETTINGS
date=$(date +%Y%m%d)
me=$(basename $0)
mydir=$(dirname $0)
# FUNCTIONS
die () {
rc=$1
shift
echo "==========================">&2
echo "==== FATAL ERROR ====" >&2
echo "==========================">&2
echo "" >&2
echo $@ >&2
exit $rc
}
usage () {
echo "==========================" >&2
echo "==== USAGE ====" >&2
echo "==========================" >&2
echo "" >&2
echo "Usage: ${me} <userfile>" >&2
echo "" >&2
echo "example: ${me} /tmp/userlist" >&2
echo "" >&2
exit 1
}
get_options () {
[ $# -gt 0 ]||usage
while getopts "s:d:D:u:g:" opt;do
case ${opt} in
u) export user=`echo ${OPTARG}` ;;
*) usage;;
esac
done
}
duration () {
before=$1
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
time_running="${hours}:${minutes}:${seconds}"
}
log_msg () {
duration ${before_total}
message="$1"
echo "${time_running} $1"|tee -a ${short_log}
}
# SCRIPT
before_total="$(date +%s)"
log_msg "$(date) started ${me}"
# get_options $@
sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read()); main(install_dir='/opt')"
duration ${before_total}
log_msg "Total time taken: ${hours}:${minutes}:${seconds}"
log_msg "$(date) Backup finished"
# END