-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
overseerr.sh
executable file
·151 lines (138 loc) · 4.12 KB
/
overseerr.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
#!/bin/bash
# thx flyingsausages and swizzin team
export user=$(whoami)
mkdir -p ~/.logs/
touch ~/.logs/overseerr.log
export log="$HOME/.logs/overseerr.log"
function _deps() {
## Function for installing nvm.
if [[ ! -d /home/$user/.nvm ]]; then
echo "Installing node"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash >> "$log" 2>&1
echo "nvm installed."
else
echo "nvm is already installed."
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install --lts >> "$log" 2>&1 || {
echo "node failed to install"
exit 1
}
echo "Node LTS installed."
echo "Installing Yarn"
npm install -g yarn >> "$log" 2>&1 || {
echo "Yarn failed to install"
exit 1
}
echo "Yarn installed."
}
function _overseer_install() {
echo "Downloading and extracting source code"
dlurl="$(curl -sS https://api.github.com/repos/sct/overseerr/releases/latest | jq .tarball_url -r)"
wget "$dlurl" -q -O /home/${user}/overseerr.tar.gz >> "$log" 2>&1 || {
echo "Download failed"
exit 1
}
mkdir -p ~/overseerr
tar --strip-components=1 -C ~/overseerr -xzvf /home/${user}/overseerr.tar.gz >> "$log" 2>&1
rm /home/${user}/overseerr.tar.gz
echo "Code extracted"
# Changing baseurl before build
# export OVERSEERR_BASEURL='/baseurl'
echo "Installing dependencies via yarn"
yarn install --cwd ~/overseerr >> "$log" 2>&1 || {
echo "Failed to install dependencies"
exit 1
}
echo "Dependencies installed"
echo "Building overseerr"
yarn --cwd ~/overseerr build >> "$log" 2>&1 || {
echo "Failed to build overseerr sqlite"
exit 1
}
echo "Succesfully built"
}
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 _service() {
mkdir -p "/home/$user/.config/systemd/user/"
mkdir -p "/home/$user/.install/"
mkdir -p "/home/$user/.config/overseerr/"
# Adapted from https://aur.archlinux.org/cgit/aur.git/tree/overseerr.service?h=overseerr
cat > ~/.config/systemd/user/overseerr.service << EOF
[Unit]
Description=Overseerr Service
Wants=network-online.target
After=network-online.target
[Service]
EnvironmentFile=/home/$user/overseerr/env.conf
Environment=NODE_ENV=production
Type=exec
Restart=on-failure
WorkingDirectory=/home/$user/overseerr
ExecStart=$(which node) dist/index.js
[Install]
WantedBy=default.target
EOF
port=$(_port 1000 18000)
cat > ~/overseerr/env.conf << EOF
# specify on which port to listen
PORT=$port
EOF
systemctl --user daemon-reload
systemctl --user enable --now -q overseerr
touch ~/.install/.overseerr.lock
echo "Overseerr is up and running on http://$(hostname -f):$port/overseerr"
}
function _remove() {
systemctl --user disable --now overseerr
sleep 2
rm -rf ~/overseerr
rm -rf ~/.config/overseerr
rm -rf ~/.config/systemd/user/overseerr.service
rm -rf ~/.install/.overseerr.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 Overseerr installer..."
echo ""
echo "What do you like to do?"
echo ""
echo "install = Install Overseerr"
echo "uninstall = Completely removes Overseerr"
echo "exit = Exits Installer"
while true; do
read -r -p "Enter it here: " choice
case $choice in
"install")
clear
_deps
_overseer_install
_service
break
;;
"uninstall")
_remove
break
;;
"exit")
break
;;
*)
echo "Unknown Option."
;;
esac
done
exit