-
Notifications
You must be signed in to change notification settings - Fork 15
/
install.sh
executable file
·114 lines (97 loc) · 3.49 KB
/
install.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash -p
#
# Quick'n dirty helper to pickup a Kobo's USBMS mountpoint...
#
##
# Force a cd to the script's directory, because on macOS, a command script has a fixed $PWD set to $HOME...
cd -P -- "$(dirname "${BASH_SOURCE[0]}")" || exit 255
# We're ultimately going to need unzip...
if ! unzip -v &>/dev/null ; then
echo "This script relies on unzip!"
exit 255
fi
# Are we on Linux or macOS?
PLATFORM="$(uname -s)"
# Find out where the Kobo is mounted...
KOBO_MOUNTPOINT="/dev/null"
case "${PLATFORM}" in
"Linux" )
# Use findmnt, it's in util-linux, which should be present in every sane distro.
if ! findmnt -V &>/dev/null ; then
echo "This script relies on findmnt, from util-linux!"
exit 255
fi
# Match on the FS Label, which is common to all models.
KOBO_MOUNTPOINT="$(findmnt -nlo TARGET LABEL=KOBOeReader)"
;;
"Darwin" )
# Same idea, via diskutil
KOBO_MOUNTPOINT="$(diskutil info -plist "KOBOeReader" | grep -A1 "MountPoint" | tail -n 1 | cut -d'>' -f2 | cut -d'<' -f1)"
;;
* )
echo "Unsupported OS!"
exit 255
;;
esac
# Sanity check...
if [[ -z "${KOBO_MOUNTPOINT}" ]] ; then
echo "Couldn't find a Kobo eReader volume! Is one actually mounted?"
exit 255
fi
KOBO_DIR="${KOBO_MOUNTPOINT}/.kobo"
if [[ ! -d "${KOBO_DIR}" ]] ; then
echo "Can't find a .kobo directory, ${KOBO_MOUNTPOINT} doesn't appear to point to a Kobo eReader... Is one actually mounted?"
exit 255
fi
# Ask the user what they want to install...
AVAILABLE_PKGS=()
for file in KOReader-v*.zip Plato-*.zip KFMon-v*.zip KFMon-Uninstaller.zip ; do
[[ -f "${file}" ]] && AVAILABLE_PKGS+=("${file}")
done
# Sanity check...
if [[ ${#AVAILABLE_PKGS[@]} -eq 0 ]] ; then
echo "No supported packages found in the current directory (${PWD})!"
exit 255
fi
echo "* Here are the available packages:"
for i in "${!AVAILABLE_PKGS[@]}" ; do
echo "${i}: ${AVAILABLE_PKGS[${i}]}"
done
read -r -p "* Enter the number corresponding to the one you want to install: " j
# Check if that was a sane reply...
if ! [ "${j}" -eq "${j}" ] 2>/dev/null ; then
echo "That wasn't a number!"
exit 255
fi
if [[ ${j} -lt 0 ]] || [[ ${j} -ge ${#AVAILABLE_PKGS[@]} ]] ; then
echo "That number was out of range!"
exit 255
fi
# NOTE: Since FW 4.17, Nickel will attempt to index content found in hidden directories.
# Since all of this stuff lives in *nix hidden directories, this won't do.
# Thankfully, FW 4.17.13694 introduced a hidden setting to control that behavior.
# We'll enforce the "legacy" behavior of basically ignoring non-default hidden directories.
# c.f., https://www.mobileread.com/forums/showpost.php?p=3892463&postcount=10
# NOTE: We can simply push a (potentially) duplicate section + entry at the end of the file,
# QSettings will do the right thing, that is, pick up this new key, use it,
# and save everything in the right place without leaving duplicates around.
echo "* Preventing Nickel from scanning hidden directories . . ."
cat >> "${KOBO_DIR}/Kobo/Kobo eReader.conf" <<-\EoM
[FeatureSettings]
ExcludeSyncFolders=\\.(?!kobo|adobe).*?
EoM
# We've got a Kobo, we've got a package, let's go!
if [[ "${AVAILABLE_PKGS[${j}]}" == "KFMon-Uninstaller.zip" ]] ; then
echo "* Uninstalling KFMon . . ."
unzip -o "${AVAILABLE_PKGS[${j}]}" -d "${KOBO_DIR}"
else
echo "* Installing ${AVAILABLE_PKGS[${j}]} . . ."
unzip -o "${AVAILABLE_PKGS[${j}]}" -d "${KOBO_MOUNTPOINT}"
fi
ret=$?
if [ ${ret} -eq 0 ] ; then
echo "* Installation successful!"
else
echo "* Installation FAILED! No cleanup will be done!"
exit ${ret}
fi