summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: c97e388080c6017dc48ed3b85fa0b56b9bbcf365 (plain)
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
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: Matt Parnell <parwok@gmail.com>

# BUG: So far as I can tell updating multiple hosts with a single request is no longer supported by the DNS-O-Matic service.
#    The code could be updated to put out a separate request for each host. This is a big more than sed can do.
# Future BUG: When multiple hosts is implemented, don't wait for IP to change when new hosts are added.
# Until this is fixed server connections are not attempted when multiple hosts are specified.
# FIXED: The interactive stuff in the old PKGBUILD has been moved to install
# FIXED: Connections are not be attempted for default user = userid or password = password
# FIXED: Launches with cron as root or systemd timer as user nobody
# TODO: Implement IP change log
# TODO: Implement all Dynamic DNS services including DNS-O-Matic.
# TODO: Add version to config so we can discard it on same version upgrades and installs.
# TODO: Add settings promotion to new config files.
# TODO: Better variable detection in config (I suspect blank lines aren't handled well)

# If upgrading from an old version you might get a file conflict
#   update-dnsomatic: /etc/update-dnsomatic/myip exists in filesystem
# To solve
#   sudo mv /etc/update-dnsomatic/myip /etc/update-dnsomatic/myip.pacsave

# Starting out it's hard to tell what to put in for myhost. In your DNS-O-Matic account screen you see
#   Service
#   username :: myhost
# For OpenDNS myhost is just a phrase like Home, Office, or Gramma

set -u
pkgname='update-dnsomatic'
pkgver='0.2.1'
pkgrel='1'
pkgdesc='A perl utility that updates OpenDNS DNS-O-Matic, and is simpler than inyadn'
arch=('i686' 'x86_64')
url='http://prawnuk.blogspot.com/2008/11/dnsomatic-updater.html' # Seán Doher
license=('GPL')
depends=('perl' 'perl-libwww' 'perl-crypt-ssleay' 'perl-lwp-protocol-https')
optdepends=('cron: use cron instead of systemd timers')
backup='etc/update-dnsomatic/config'
source=("http://update-dnsomatic.googlecode.com/files/${pkgname}-${pkgver}.tar.gz")
sha256sums=('e4b44ffc8caf1114464ca2ae7a925ca06b632379befa88ac39e36c09253a4715')
install="${pkgname}.install"

package() {
  set -u
  cd "${pkgname}-${pkgver}"
  install -Dpm640 'config' -t "${pkgdir}/etc/update-dnsomatic/"
  chmod 775 "${pkgdir}/etc/update-dnsomatic/"
  # This lets pacman -Qo show us as the owner of this file. It also lets pacman delete this file.
  install -Dm664 /dev/null "${pkgdir}/etc/update-dnsomatic/myip"
  install -Dpm754 'update-dnsomatic' -t "${pkgdir}/usr/bin/"

  local _codedouble='
use Getopt::Long;
my $arg_daemon=0;

if (!GetOptions (
  "daemon" => \$arg_daemon
) or @ARGV > 0) {
  die("$0: Invalid command line options: @ARGV\n");
}'
  _codedouble="$(echo "${_codedouble}" | sed -e 's:\\:\\\\:g' | tr '\n' '\r' | sed -e 's:\r:\\n:g')" # escape \n for sed replacement

  # Fix permissions
  sed -i -e '# Fix permissions on new file creation for systemd to run as nobody' \
         -e 's:^sub write_new_ip {$:&\n  umask 0002;:g' \
         -e '# Fix some horrible spacing' \
         -e 's:\s\+$::g' \
         -e '# Block unsupported multiple hosts rather than spam the servers' \
         -e '# Prevent spamming servers with blank or default userid:password' \
         -e 's:^\(\s\+\)close(CONFIG);$:&\n\1if (index($config{myhost}, ",") >= 0) {\n\1\1write_log("err", "Multiple myhost is not supported by DNS-O-Matic. Fix /etc/update-dnsomatic/config");\n\1\1exit(1);\n\1}\n\1if (!$config{user} or !$config{pass} or $config{user} eq "userid" or $config{pass} eq "password") {\n\1\1write_log("err", "User and pass must be set in /etc/update-dnsomatic/config");\n\1\1exit(1);\n\1}:g' \
         -e '# getopts code for doubled log entries in systemctl status update-dnsomatic.service' \
         -e 's/^use Sys::Syslog;$'"/&${_codedouble}/g" \
         -e '# Stop doubled log entries' \
         -e 's:^\(\s\+print "\$msg\\n"\);$:\1 if (!$arg_daemon);:g' \
    "${pkgdir}/usr/bin/update-dnsomatic"
  unset _codedouble

  install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/

[Unit]
Description=OpenDNS DNS-O-Matic updater ${pkgname}

[Timer]
OnBootSec=5min
OnCalendar=*:0/10
Persistent=true

[Install]
WantedBy=multi-user.target
EOF
  ) "${pkgdir}/usr/lib/systemd/system/${pkgname}.timer"

  install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/

[Unit]
Description=OpenDNS DNS-O-Matic updater ${pkgname}

[Service]
Type=oneshot
ExecStart=/usr/bin/update-dnsomatic --daemon
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
User=nobody
Group=nobody
EOF
  ) "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"

  set +u
}
set +u