~sotirisp/kindleto

ref: faaff15151ac14fbdf0cb20b3b6a145bf127af3a kindleto/kindleto-init -rwxr-xr-x 2.2 KiB
faaff151Sotiris Papatheodorou Reduce the TOFU cache save interval 4 months ago
                                                                                
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
#!/bin/sh
# SPDX-FileCopyrightText: 2010-2015 NiLuJe
# SPDX-FileCopyrightText: 2021 Sotiris Papatheodorou

# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appears in all copies and that both the
# copyright notice and this permission notice appear in supporting
# documentation, and that the same name not be used in advertising or publicity
# pertaining to distribution of the software without specific, written prior
# permission. We make no representations about the suitability this software
# for any purpose. It is provided "as is" without express or implied warranty.

_functions=/etc/rc.d/functions
[ -f "$_functions" ] && . "$_functions"

hack_name='kindleto'
hack_basedir="/mnt/us/$hack_name"
hack_script="$hack_basedir/bin/$hack_name"
hack_emergency="$hack_basedir/bin/emergency.sh"
hack_enable="$hack_basedir/auto"

# The Kindle 4 has a different directory for binaries.
if grep -q '^Kindle 4' /etc/prettyversion.txt; then
    kindle_bindir='/usr/local/bin'
else
    kindle_bindir='/test/bin'
fi
# Ensure the symlink to the hack script exists and create it if not.
kindle_hack_script="$kindle_bindir/$hack_name"
if [ ! -L $kindle_hack_script ]; then
	msg "the $hack_name command symlink was missing, creating it..." W
	mntroot_rw
	mkdir -p "$kindle_bindir"
	ln -fs "$hack_script" "$kindle_hack_script"
	mntroot_ro
fi

hack_start() {
	# If an emergency script is available, run it and exit.
	if [ -f "$hack_emergency" ]; then
		chmod +x "$hack_emergency"
		$hack_emergency
		exit 0
	fi
	# Start normally.
	if [ -f "$hack_enable" ] && [ -f "$hack_script" ]; then
		chmod +x "$hack_script"
		$hack_script -webroot "$hack_basedir/web" \
			-certfile "$hack_basedir/client-certs.json" \
			-tofucache "$hack_basedir/kindleto-tofu.txt" &
	else
		msg "$hack_name is disabled" I
	fi
}

hack_stop() {
	killall "$hack_name"
}

hack_status() {
	msg "No idea" I
}

hack_reload() {
	msg "Nothing to reload" I
}

case "$1" in
	start)
		hack_start
		;;
	stop)
		hack_stop
		;;
	status)
		hack_status
		;;
	reload)
		hack_reload
		;;
	restart)
		hack_stop
		sleep 1
		hack_start
		;;
	*)
		msg "Usage: $0 start|stop|status|reload|restart" W >&2
		exit 1
		;;
esac

exit 0