-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·218 lines (190 loc) · 8.65 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·218 lines (190 loc) · 8.65 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# vim: set bg=dark
USER_BASE=/opt/dart
MEDIA_BASE=/media/storage
GIT_BASE=/tmp/dart
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
LIDARR_PKG_URL='https://ci.appveyor.com/api/buildjobs/pqte2q546889w0yh/artifacts/Lidarr.develop.0.3.0.430.linux.tar.gz'
LIDARR_SAVEFILE='/tmp/lidarr.tgz'
COUCHPOTATO_GIT_REPO='https://github.com/CouchPotato/CouchPotatoServer.git'
VPN_USER=
VPN_PASS=
IP=AUTO
SUBNET=AUTO
# comment this out if you don't have additional subnets to set
ADTL_SUBNET='10.10.20.0/24'
# Make sure it's run as root
if [[ $UID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
echo "try: sudo $0" 1>&2
exit 1
fi
if [[ -z $IPV6_BYPASS ]] && ( ip a s | grep inet6 2>&1 >/dev/null ); then
cat << EOF 1>&2
=================================
=================================
== IPV6 DETECTED ==
== PLEASE DISABLE IPV6 AND ==
== RE-RUN THIS SCRIPT ==
=================================
=================================
EOF
exit
fi
if [ "$IP" = "AUTO" ]; then
IP=$(ip r g 8.8.8.8 | head -n 1 | cut -d " " -f 7)
echo "Auto-detected IP: $IP"
fi
if [ "$SUBNET" = "AUTO" ]; then
SUBNET=$(ip a s | grep ${IP} | sed -e 's/\s\+/ /g;' | cut -d " " -f 3)
echo "Auto-detected subnet: $SUBNET"
fi
if [ -z "$IP" ] || [ -z "$SUBNET" ]; then
echo "Unable to determine IP or subnet." 1>&2
exit
fi
echo "Using IP address: ${IP}"
echo "Using subnet: ${SUBNET}"
echo "Setting up VPN credentials"
if [ -z "$VPN_USER" ]; then
read -p "VPN username: " VPN_USER
fi
if [ -z "$VPN_PASS" ]; then
read -p "VPN password: " -s VPN_PASS
echo
fi
if [ -L /etc/resolv.conf ]; then
echo "Disabling systemd-resolve"
systemd-resolve --status | grep "DNS Servers" | sed -e 's/^\s\+//g' -e "s/DNS Servers:/nameserver/" > /etc/resolv.conf.tmp
systemctl disable --now systemd-resolved.service
rm /etc/resolv.conf
cp /etc/resolv.conf.tmp /etc/resolv.conf
else
echo "Did not detect systemd-resolve. that's good"
fi
echo "Adding repositories"
echo " Mono"
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF >/dev/null 2>&1
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" > /etc/apt/sources.list.d/mono-official-stable.list 2>/dev/null
echo " Sonarr"
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FDA5DFFC >/dev/null 2>&1
echo "deb http://apt.sonarr.tv/ master main" > /etc/apt/sources.list.d/sonarr.list 2>/dev/null
echo "Updating APT and upgrading packages"
apt-get update 2>&1 >/dev/null && apt-get dist-upgrade -y 2>&1 >/dev/null
echo "Installing required packages..."
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean false | debconf-set-selections
apt-get install -y iptables-persistent mono-devel vim git openvpn sabnzbdplus python-sabyenc transmission-daemon nzbdrone 2>&1 >/dev/null
echo " done."
if [ -d $SCRIPT_DIR/.git ] && [ -d $SCRIPT_DIR/files ]; then
echo "Found local repo, using it: $SCRIPT_DIR"
GIT_BASE=$SCRIPT_DIR
else
echo "Fetching files"
git clone https://github.com/rwall/dart ${GIT_BASE} >/dev/null 2>&1 || (echo " Repo already checked out. updating..." && cd ${GIT_BASE} && git pull)
fi
git -C "$GIT_BASE" pull
echo "Making directories"
mkdir -p ${USER_BASE}
mkdir -p ${MEDIA_BASE}/incoming/transmission/complete
mkdir -p ${MEDIA_BASE}/incoming/transmission/incomplete
echo "Disabling IPv6 and IP forwarding"
cat << EOF > /etc/sysctl.d/99-dart.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.ip_forward = 0
EOF
sysctl -p
echo "Installing iptables"
cat << EOF > /etc/iptables/rules.v4
# Generated by iptables-save v1.6.1 on Sat Jun 2 03:59:09 2018
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -s ${SUBNET} -j ACCEPT
-A INPUT -s ${ADTL_SUBNET} -j ACCEPT
-A INPUT -i tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m udp --sport 1194 -j ACCEPT
-A INPUT -i tun+ -p icmp -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -d ${SUBNET} -j ACCEPT
-A OUTPUT -d ${ADTL_SUBNET} -j ACCEPT
-A OUTPUT -p udp -m udp --dport 1194 -j ACCEPT
-A OUTPUT -o tun+ -j ACCEPT
COMMIT
# Completed on Sat Jun 2 03:59:09 2018
EOF
echo "Setting up openvpn VPN"
cat << EOF > /etc/openvpn/ipredator.auth
${VPN_USER}
${VPN_PASS}
EOF
chmod og-rw /etc/openvpn/ipredator.auth
mkdir -p /etc/openvpn/config >/dev/null 2>&1
$(export FILE='etc/openvpn/ipredator.conf'; cp ${GIT_BASE}/files/$FILE /$FILE)
$(export FILE='etc/openvpn/ipredator_dns_up.sh'; cp ${GIT_BASE}/files/$FILE /$FILE)
$(export FILE='etc/openvpn/ipredator_dns_down.sh'; cp ${GIT_BASE}/files/$FILE /$FILE)
chmod +x /etc/openvpn/ipredator_dns_{up,down}.sh
echo "Setting up software"
echo " SabNZB"
USERNAME=sabnzb
useradd -r -d ${USER_BASE}/$USERNAME -m -N $USERNAME >/dev/null 2>&1
$(export FILE='etc/systemd/system/sabnzb.service'; cp ${GIT_BASE}/files/$FILE /$FILE) >/dev/null 2>&1
sed -i -e "s/host =.*/host = ${IP}/" ${USER_BASE}/sabnzb/.sabnzbd/sabnzbd.ini
systemctl enable sabnzb.service >/dev/null 2>&1
SAB_API_KEY=$(grep -E '^api_key = ' ${USER_BASE}/sabnzb/.sabnzbd/sabnzbd.ini | cut -d " " -f 3)
echo "api key: $SAB_API_KEY"
echo " Transmission"
USERNAME=transmission
useradd -r -d ${USER_BASE}/$USERNAME -m -N $USERNAME >/dev/null 2>&1
cp -r /var/lib/transmission-daemon/.config ${USER_BASE}/${USERNAME}/
chown -R ${USERNAME}: ${USER_BASE}/${USERNAME}/.config
ln -s ${USER_BASE}/${USERNAME}/.config/transmission-daemon ${USER_BASE}/${USERNAME}/info >/dev/null 2>&1
chown root:users /etc/transmission-daemon
chown ${USERNAME}:users /etc/transmission-daemon/*
sed -i -e "s#^CONFIG_DIR=.*#CONFIG_DIR=\"${USER_BASE}/${USERNAME}/info\"#" /etc/default/transmission-daemon
sed -i -e "s/^setuid debian-transmission/setuid ${USERNAME}/" /etc/init/transmission-daemon.conf
sed -i -e 's/^setgid debian-transmission/setgid users/' /etc/init/transmission-daemon.conf
sed -i -e 's/"download-dir":.*/"download-dir": "\/media\/storage\/incoming\/transmission\/complete",/' /etc/transmission-daemon/settings.json
sed -i -e 's/"incomplete-dir":.*/"incomplete-dir": "\/media\/storage\/incoming\/transmission\/incomplete",/' /etc/transmission-daemon/settings.json
sed -i -e 's/"incomplete-dir-enabled":.*/"incomplete-dir-enabled": true,/' /etc/transmission-daemon/settings.json
sed -i -e "s/\"rpc-bind-address\":.*/\"rpc-bind-address\": \"${IP}\",/" /etc/transmission-daemon/settings.json
sed -i -e "s/\"rpc-authentication-required\":.*/\"rpc-authentication-required\": false,/" /etc/transmission-daemon/settings.json
#sed -i -e 's/"rpc-host-whitelist":.*/"rpc-host-whitelist": "127.0.0.1",/' /etc/transmission-daemon/settings.json
sed -i -e "s/User=.*/User=${USERNAME}/" /lib/systemd/system/transmission-daemon.service
echo " Sonarr"
USERNAME=sonarr
useradd -r -d ${USER_BASE}/$USERNAME -m -N $USERNAME >/dev/null 2>&1
$(export FILE='etc/systemd/system/sonarr.service'; cp ${GIT_BASE}/files/$FILE /$FILE) >/dev/null 2>&1
sed -i -e "s#<BindAddress>.*</BindAddress>#<BindAddress>${IP}</BindAddress>#" ${USER_BASE}/${USERNAME}/.config/NzbDrone/config.xml
SONARR_API_KEY=$(grep -e "ApiKey" ${USER_BASE}/${USERNAME}/.config/NzbDrone/config.xml | cut -d ">" -f 2 | cut -d "<" -f 1)
echo "sonarr api key: $SONARR_API_KEY"
systemctl enable sonarr.service >/dev/null 2>&1
echo " Lidarr"
USERNAME=lidarr
useradd -r -d ${USER_BASE}/$USERNAME -m -N $USERNAME >/dev/null 2>&1
if [ ! -e ${LIDARR_SAVEFILE} ]; then
wget -O "${LIDARR_SAVEFILE}" "${LIDARR_PKG_URL}" >/dev/null 2>&1
fi
tar -xzf ${LIDARR_SAVEFILE} --directory ${USER_BASE}/${USERNAME}/ >/dev/null 2>&1
chown -R lidarr: ${USER_BASE}/${USERNAME}/Lidarr >/dev/null 2>&1
$(export FILE='etc/systemd/system/lidarr.service'; cp ${GIT_BASE}/files/$FILE /$FILE) >/dev/null 2>&1
sed -i -e "s#<BindAddress>.*</BindAddress>#<BindAddress>${IP}</BindAddress>#" ${USER_BASE}/${USERNAME}/.config/Lidarr/config.xml
LIDARR_API_KEY=$(grep -e "ApiKey" ${USER_BASE}/lidarr/.config/Lidarr/config.xml | cut -d ">" -f 2 | cut -d "<" -f 1)
echo "lidarr api key: $LIDARR_API_KEY"
systemctl enable lidarr.service >/dev/null 2>&1
echo " CouchPotato"
USERNAME=couchpotato
useradd -r -d ${USER_BASE}/$USERNAME -m -N $USERNAME >/dev/null 2>&1
git clone ${COUCHPOTATO_GIT_REPO} ${USER_BASE}/${USERNAME}/CouchPotatoServer >/dev/null 2>&1
$(export FILE='etc/systemd/system/couchpotato.service'; cp ${GIT_BASE}/files/$FILE /$FILE) >/dev/null 2>&1
systemctl enable couchpotato.service >/dev/null 2>&1
systemctl start sabnzb >/dev/null 2>&1
systemctl start transmission-daemon >/dev/null 2<&1
systemctl start sonarr >/dev/null 2>&1
systemctl start lidarr >/dev/null 2>&1
systemctl start couchpotato >/dev/null 2>&1
echo "Done."