Skip to content

Commit c310c1a

Browse files
committed
Add support for installation on Alpine Linux
1 parent 209ebd4 commit c310c1a

File tree

2 files changed

+88
-23
lines changed

2 files changed

+88
-23
lines changed

DnsServerApp/DnsServerApp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26+
<None Update="openrc.service">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
2629
<None Update="start.bat">
2730
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2831
</None>

DnsServerApp/install.sh

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#!/bin/sh
22

3+
cleanup() {
4+
# On Alpine Linux get rid of virtual packages
5+
if $alpineLinux; then
6+
apk del .deps >> $installLog 2>&1
7+
fi
8+
}
9+
10+
trap cleanup INT TERM EXIT
11+
312
dotnetDir="/opt/dotnet"
413
dotnetVersion="8.0"
514
dotnetRuntime="Microsoft.AspNetCore.App 8.0."
@@ -27,6 +36,29 @@ echo ""
2736
mkdir -p $dnsDir
2837
echo "" > $installLog
2938

39+
if command -v apk >/dev/null 2>&1
40+
then
41+
# On Alpine Linux we need bash & curl to install dotnet
42+
alpineLinux=true
43+
apk update >> $installLog 2>&1
44+
deps=""
45+
# Check for bash
46+
if ! command -v bash >/dev/null 2>&1; then
47+
deps="$deps bash"
48+
fi
49+
# Check for curl
50+
if ! command -v curl >/dev/null 2>&1; then
51+
deps="$deps curl"
52+
fi
53+
# Install missing packages, if any
54+
if [ -n "$deps" ]; then
55+
echo "Installing packages needed for the installation: $deps"
56+
apk add --no-cache --virtual .deps $deps
57+
fi
58+
else
59+
alpineLinux=false
60+
fi
61+
3062
if dotnet --list-runtimes 2> /dev/null | grep -q "$dotnetRuntime";
3163
then
3264
dotnetFound="yes"
@@ -49,6 +81,12 @@ else
4981

5082
curl -sSL $dotnetUrl | bash /dev/stdin -c $dotnetVersion --runtime aspnetcore --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1
5183

84+
# On Alpine Linux dotnet requires libstdc++
85+
if $alpineLinux; then
86+
echo "Installing ASP.NET Core Runtime dependencies..."
87+
apk add --no-cache libstdc++ >> $installLog 2>&1
88+
fi
89+
5290
if [ ! -f "/usr/bin/dotnet" ]
5391
then
5492
ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1
@@ -166,34 +204,58 @@ fi
166204

167205
echo ""
168206

169-
if ! [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ]
207+
installed=false
208+
if [ "$(ps -o comm 1 | grep -v COMMAND)" = "systemd" ]
170209
then
171-
echo "Failed to install Technitium DNS Server: systemd was not detected."
172-
echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html"
173-
exit 1
174-
fi
210+
if [ -f "/etc/systemd/system/dns.service" ]
211+
then
212+
echo "Restarting systemd service..."
213+
systemctl restart dns.service >> $installLog 2>&1
214+
else
215+
echo "Configuring systemd service..."
216+
cp $dnsDir/systemd.service /etc/systemd/system/dns.service
217+
systemctl enable dns.service >> $installLog 2>&1
218+
219+
systemctl stop systemd-resolved >> $installLog 2>&1
220+
systemctl disable systemd-resolved >> $installLog 2>&1
221+
222+
systemctl start dns.service >> $installLog 2>&1
223+
224+
rm /etc/resolv.conf >> $installLog 2>&1
225+
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog
226+
227+
if [ -f "/etc/NetworkManager/NetworkManager.conf" ]
228+
then
229+
echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog
230+
fi
231+
fi
232+
installed=true
175233

176-
if [ -f "/etc/systemd/system/dns.service" ]
234+
elif [ -x "/sbin/rc-service" ]
177235
then
178-
echo "Restarting systemd service..."
179-
systemctl restart dns.service >> $installLog 2>&1
180-
else
181-
echo "Configuring systemd service..."
182-
cp $dnsDir/systemd.service /etc/systemd/system/dns.service
183-
systemctl enable dns.service >> $installLog 2>&1
184-
185-
systemctl stop systemd-resolved >> $installLog 2>&1
186-
systemctl disable systemd-resolved >> $installLog 2>&1
187-
188-
systemctl start dns.service >> $installLog 2>&1
189-
190-
rm /etc/resolv.conf >> $installLog 2>&1
191-
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog
192-
193-
if [ -f "/etc/NetworkManager/NetworkManager.conf" ]
236+
if [ -f "/etc/init.d/dns" ]
194237
then
195-
echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog
238+
echo "Restarting OpenRC service..."
239+
rc-service dns stop >> $installLog 2>&1
240+
rc-service dns start >> $installLog 2>&1
241+
else
242+
echo "Configuring OpenRC service..."
243+
cp $dnsDir/openrc.service /etc/init.d/dns
244+
chmod +x /etc/init.d/dns
245+
rc-update add dns >> $installLog 2>&1
246+
rc-service dns start >> $installLog 2>&1
247+
248+
rm /etc/resolv.conf >> $installLog 2>&1
249+
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog
196250
fi
251+
installed=true
252+
fi
253+
254+
if ! $installed
255+
then
256+
echo "Failed to install Technitium DNS Server: systemd or OpenRC were not detected."
257+
echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html"
258+
exit 1
197259
fi
198260

199261
echo ""

0 commit comments

Comments
 (0)