/
kindle-delete-ads.sh
executable file
·60 lines (41 loc) · 1.05 KB
/
kindle-delete-ads.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
#!/usr/bin/env bash
if [[ $EUID -ne 0 ]]; then
echo "Run this script with Root priveleges."
exit 1
fi
if [[ -n "$1" ]]; then
kindleDevice="$1"
else
echo -n "Autodetecting Kindle device... "
kindleDevice=`blkid | grep Kindle | cut -f 1 -d ':'`
echo "done"
fi
echo "Kindle device file is $kindleDevice"
mountInfo=`df | grep $kindleDevice`
if [[ $? -eq 0 ]]; then
echo "Kindle is already mounted! unmounting...."
umount $kindleDevice
fi
tmpMount=`mktemp -d`
echo "Mounting Kindle to temporary location: $tmpMount"
mount $kindleDevice $tmpMount
# We are in Kindle filesystem after this point...
cd $tmpMount
adverts="system/.assets"
if [[ -f $adverts ]]; then
echo "Temp ad blocker is still intact! Nothing to do."
elif [[ -d $adverts ]]; then
echo "Ads detected. Cleaning time."
echo -n "Deleting all ads... "
rm -rf $adverts
echo "done"
echo -n "Installing temp ad blocker... "
touch $adverts
echo "done"
fi
# Post-cleanup for this utility
echo -n "Unmounting kindle... "
cd - > /dev/null
umount $kindleDevice
rmdir $tmpMount
echo "done"