-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
komga.sh
executable file
·138 lines (128 loc) · 3.89 KB
/
komga.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# Thanks to Snd from Komga Discord for telling us about how to re-bind tmpdir.
user=$(whoami)
mkdir -p "$HOME/.logs/"
export log="$HOME/.logs/komga.log"
touch "$log"
function java_install() {
type java || {
echo "Java not installed..."
# Java 8
echo "Downloading java"
curl -sL "https://download.oracle.com/java/17/archive/jdk-17.0.10_linux-x64_bin.tar.gz" -o /tmp/jre.tar.gz >> "$log" 2>&1
echo "Extracting java"
tar -xvf /tmp/jre.tar.gz --strip-components=1 -C "/home/${user}/.local/" >> "$log" 2>&1
rm /tmp/jre.tar.gz
. "/home/${user}/.profile"
}
}
function port() {
LOW_BOUND=$1
UPPER_BOUND=$2
comm -23 <(seq ${LOW_BOUND} ${UPPER_BOUND} | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1
}
function github_latest_version() {
# Argument expects the author/repo format
# e.g. swizzin/swizzin
repo=$1
curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/${repo}/releases/latest | grep -o '[^/]*$'
}
function _install() {
echo "Beginning installation..."
mkdir -p "$HOME/komga"
mkdir -p "$HOME/.tmp"
java_install
echo "Downloading Komga"
version=$(github_latest_version gotson/komga)
dlurl="https://github.com/gotson/komga/releases/download/$version/komga-${version//v}.jar"
wget "$dlurl" -O "$HOME/komga/komga.jar" >> "${log}" 2>&1 || {
echo "Download failed"
exit 1
}
mkdir "$HOME/.config/systemd/user"
echo "Figuring out a port to host komga on..."
port=$(port 5900 9900)
echo "Writing Service File"
cat > "$HOME/.config/systemd/user/komga.service" <<- SERV
[Unit]
Description=Komga server
[Service]
WorkingDirectory=$HOME/komga/
ExecStart=$HOME/.local/bin/java -jar -Xmx1g -Djava.io.tmpdir=$HOME/.tmp $HOME/komga/komga.jar --server.servlet.context-path="/komga" --server.port="${port}"
Type=simple
Restart=on-failure
RestartSec=10
StandardOutput=null
StandardError=syslog
[Install]
WantedBy=default.target
SERV
echo "Starting service..."
systemctl enable --user --now komga -q
echo "Service stared."
touch "$HOME/.install/.komga.lock"
echo "Komga has been installed and should be running at http://$(hostname -f):${port}/komga/"
}
function _upgrade() {
if [ ! -f /install/.komga.install ]; then
echo "You ain't got no komga, whacha doen"
exit 1
fi
echo "Downloading komga"
version=$(github_latest_version gotson/komga)
dlurl="https://github.com/gotson/komga/releases/download/$version/komga-${version//v}.jar"
wget "$dlurl" -O "$HOME/komga/komga.jar" >> "${log}" 2>&1 || {
echo_error "Download failed"
exit 1
}
systemctl try-restart --user komga
}
function _remove() {
systemctl stop --user komga
systemctl disable --user komga
rm -rf "$HOME/komga/"
rm -f "$HOME/.config/systemd/user/komga.service"
rm -f "$HOME/.install/.komga.lock"
}
echo 'This is unsupported software. You will not get help with this, please answer `yes` if you understand and wish to proceed'
if [[ -z ${eula} ]]; then
read -r eula
fi
if ! [[ $eula =~ yes ]]; then
echo "You did not accept the above. Exiting..."
exit 1
else
echo "Proceeding with installation"
fi
echo "Welcome to the Komga installer..."
echo ""
echo "What do you like to do?"
echo "Logs are stored at ${log}"
echo "install = Install Komga"
echo "upgrade = upgrades Komga to latest version"
echo "uninstall = Completely removes Komga"
echo "exit = Exits Installer"
while true; do
read -r -p "Enter it here: " choice
case $choice in
"install")
_install
break
;;
"upgrade")
_upgrade
break
;;
"uninstall")
_remove
break
;;
"exit")
break
;;
*)
echo "Unknown Option."
;;
esac
done
exit