|
1 | 1 | #!/bin/sh |
2 | 2 |
|
| 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 | + |
3 | 12 | dotnetDir="/opt/dotnet" |
4 | 13 | dotnetVersion="8.0" |
5 | 14 | dotnetRuntime="Microsoft.AspNetCore.App 8.0." |
@@ -27,6 +36,29 @@ echo "" |
27 | 36 | mkdir -p $dnsDir |
28 | 37 | echo "" > $installLog |
29 | 38 |
|
| 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 | + |
30 | 62 | if dotnet --list-runtimes 2> /dev/null | grep -q "$dotnetRuntime"; |
31 | 63 | then |
32 | 64 | dotnetFound="yes" |
|
49 | 81 |
|
50 | 82 | curl -sSL $dotnetUrl | bash /dev/stdin -c $dotnetVersion --runtime aspnetcore --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1 |
51 | 83 |
|
| 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 | + |
52 | 90 | if [ ! -f "/usr/bin/dotnet" ] |
53 | 91 | then |
54 | 92 | ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1 |
|
166 | 204 |
|
167 | 205 | echo "" |
168 | 206 |
|
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" ] |
170 | 209 | 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 |
175 | 233 |
|
176 | | -if [ -f "/etc/systemd/system/dns.service" ] |
| 234 | +elif [ -x "/sbin/rc-service" ] |
177 | 235 | 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" ] |
194 | 237 | 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 |
196 | 250 | 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 |
197 | 259 | fi |
198 | 260 |
|
199 | 261 | echo "" |
|
0 commit comments