-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
audiobookshelf.sh
177 lines (149 loc) · 5.3 KB
/
audiobookshelf.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# Installer modified by TL27
user=$(whoami)
BASE_DIR="${HOME}/.config/audiobookshelf"
if [[ ! -d $HOME/.logs ]]; then
mkdir -p $HOME/.logs
fi
touch "$HOME/.logs/audiobookshelf.log"
log="$HOME/.logs/audiobookshelf.log"
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 audiobookshelf_install() {
declare -a paths
paths[1]="$BASE_DIR/ffmpeg"
paths[2]="${HOME}/.config/systemd/user"
paths[3]="${HOME}/bin"
paths[4]="$BASE_DIR/tmp"
for i in {1..4}; do
if [ ! -d "${paths[${i}]}" ]; then
mkdir -p "${paths[${i}]}"
fi
done
ssl_port=$(port 14000 16000)
port=$(port 10000 14000)
domain=$(hostname -f)
echo "Downloading Audiobookshelf..."
mkdir -p "${HOME}/tmp/audiobookshelf" && cd "${HOME}/tmp/audiobookshelf"
version=$(github_latest_version advplyr/audiobookshelf)
wget -qO audiobookshelf.deb "https://github.com/advplyr/audiobookshelf-ppa/blob/master/audiobookshelf_${version//v/}_amd64.deb?raw=true" || {
echo "Download failed."
exit 1
}
ar x audiobookshelf.deb data.tar.xz
tar xf data.tar.xz
cp usr/share/audiobookshelf/audiobookshelf "$BASE_DIR"
cd "${HOME}" && rm -rf "${HOME}/tmp"
echo
echo "Getting latest version of audiobookshelf-ffmpeg..."
mkdir -p "${HOME}/.audiobookshelf-ffmpeg-tmp" && cd "${HOME}/.audiobookshelf-ffmpeg-tmp"
rm -rf "$BASE_DIR/ffmpeg/*"
wget -qO ffmpeg.tar.xz "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz" || {
echo "Failed to get latest release of audiobookshelf-ffmpeg." && exit 1
}
tar xf ffmpeg.tar.xz -C "$BASE_DIR/ffmpeg" --strip-components 1
echo
echo "Getting latest version of audiobookshelf-ffmpeg-tone..."
$((curl -s https://github.com/sandreas/tone | grep -om1 .*linux-x64.tar.gz) | sed s'/wget/wget -qO tone.tar.gz/g')
tar xf tone.tar.gz -C "$BASE_DIR/ffmpeg" --strip-components 1
cd "${HOME}" && rm -rf "${HOME}/.audiobookshelf-ffmpeg-tmp"
echo
if [[ ! -d $HOME/.config/systemd/user/ ]]; then
mkdir -p $HOME/.config/systemd/user/
fi
echo "create systemd userservice"
cat > "$HOME/.config/systemd/user/audiobookshelf.service" << EOF
[Unit]
Description=Self-hosted audiobook server for managing and playing audiobooks
[Service]
Type=simple
Environment=SOURCE=local
Environment=PORT=${port}
Environment=TMPDIR=$BASE_DIR/tmp
Environment=CONFIG_PATH=$BASE_DIR/config
Environment=METADATA_PATH=$BASE_DIR/metadata
Environment=FFMPEG_PATH=$BASE_DIR/ffmpeg/ffmpeg
Environment=FFPROBE_PATH=$BASE_DIR/ffmpeg/ffprobe
Environment=TONE_PATH=$BASE_DIR/ffmpeg/tone
WorkingDirectory=$BASE_DIR
ExecStart=$BASE_DIR/audiobookshelf
ExecReload=/bin/kill -HUP \$MAINPID
Restart=always
[Install]
WantedBy=default.target
EOF
echo "Starting Audiobookshelf"
systemctl enable --now --user audiobookshelf.service
echo
echo "================================"
echo "Audiobookshelf will be accessible at $(tput setaf 2)http://${domain}:${port}$(tput sgr0)"
echo "================================"
echo
echo "Your library paths have to be entered manually as the File Browser function does not work on non-docker installs."
echo "Click where it says $(tput setaf 4)New folder path$(tput sgr0)."
echo "Your path MUST start with $(tput setaf 2)$(pwd -P)/$(tput sgr0) followed with with path to your audio books. e.g. $(tput setaf 2)$(pwd -P)/media/AudioBooks$(tput sgr0)"
echo "Then TAB out of the field and click on $(tput setaf 4)Create $(tput sgr0)"
}
function _remove() {
echo
echo "Uninstalling audiobookshelf.."
if systemctl --user is-enabled --quiet "audiobookshelf.service" || [ -f "${HOME}/.config/systemd/user/audiobookshelf.service" ]; then
systemctl --user stop audiobookshelf.service
systemctl --user disable audiobookshelf.service
fi
rm -f "${HOME}/.config/systemd/user/audiobookshelf.service"
systemctl --user daemon-reload
systemctl --user reset-failed
rm -rf "${HOME}/.config/audiobookshelf"
rm -rf "${HOME}/bin"/audiobookshelf*
echo
echo "Uninstallation Complete."
}
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 Audiobookshelf installer..."
echo "Logs are stored at ${log}"
echo ""
echo "What do you like to do?"
echo ""
echo "install = Install Audiobookshelf"
echo "uninstall = Completely removes Audiobookshelf"
echo "exit = Exits Installer"
echo ""
while true; do
read -r -p "Enter it here: " choice
case $choice in
"install")
audiobookshelf_install
break
;;
"uninstall")
_remove
break
;;
"exit")
break
;;
*)
echo "Unknown Option."
;;
esac
done
exit