summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b0d8db537d8fe9c3ebcad626f564538a79b4e75f (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
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
# Maintainer: Michael Schantl <floss at schantl dash lx dot at>
# Upstream authors: Tom Keffer, Matthew Wall and contributors

# Supports automatic update checking

pkgbase=weewx
pkgname=("weewx" "weewx-docs")
_MAJOR=5
_MINOR=1
_PATCH=0
pkgver=$_MAJOR.$_MINOR.$_PATCH

function _dl_url {
  echo "https://github.com/weewx/weewx/archive/refs/tags/v$1.$2.$3.tar.gz"
}

pkgrel=1
pkgdesc="Software for logging data from weather stations"
arch=("any")
url="http://www.weewx.com/"
license=("GPL-3.0-or-later")
makedepends=("mkdocs"
             "mkdocs-material"
             "mkdocs-material-extensions"
             "python"
             "python-cheetah3"
             "python-configobj")
source=("$pkgbase-$pkgver.tar.xz::$(_dl_url $_MAJOR $_MINOR $_PATCH)"
        "weewx.sysusers"
        "weewx.tmpfiles")
sha512sums=('858300d210a40f1b72aa3aa19a32dc433ace56ca656661081e3aa1d999994de9e5603f2b0580156c2cd358f51a79b5f1321c148253607291531126862cb36feb'
            '6015b870143f6b8ae094b3f94ad53323be8a083f11c177dc508315fb3bbc20dd318124e6ccd41ba9d0388828e18c4b4ae6ce7c4a35ac0cab442eca9e8bbbca2d'
            'e97b287acf53c55d30f4e1a4d533fe5c649fac44080095fa1052f6f1cc9a55b6b0592d63c63a4a241e7007894e882648d5c4c4a221da69666e284637c5a3e15e')
_watch="http://www.weewx.com/downloads/"

build() {
  cd "$srcdir/${pkgbase}-${pkgver}"

  echo "Compiling Python bytecode"
  python -m compileall -q "src"

  echo "Compiling documentation"
  make --quiet build-docs
}

_install() {
  local dest="$1"
  local mode="$2"
  shift 2
  local sources=("$@")

  mkdir -p "$dest"
  cp -RL ${sources[@]} "$dest"

  chmod -R $mode "$dest"
  find "$dest" -type d -exec chmod a+x {} +
}

package_weewx() {
  depends=("python"
           "python-cheetah3"
           "python-configobj"
           "python-pillow")
  optdepends=("python-pyserial: serial port support"
              "python-pyusb: USB port support"
              "python-pyephem: extended celestial information"
              "python-pymysql: MySQL or MariaDB support")
  backup=("etc/weewx/weewx.conf")

  cd "$srcdir/${pkgbase}-${pkgver}"

  local PYTHON='python'
  local weewx_bindir='/usr/lib/weewx'
  local weewx_sharedir="/usr/share/weewx"
  local weewx_etcdir="/etc/weewx"
  local weewx_vardir="/var/lib/weewx"
  local entrypoints=('weewxd' 'weectl')

  local bindir="$pkgdir/usr/bin"
  local libdir="${pkgdir}${weewx_bindir}"
  local sharedir="${pkgdir}${weewx_sharedir}"
  local licensedir="$pkgdir/usr/share/licenses/weewx"
  local etcdir="${pkgdir}${weewx_etcdir}"
  local unitdir="$pkgdir/usr/lib/systemd/system"
  local sysusersdir="$pkgdir/usr/lib/sysusers.d"
  local tmpfilesdir="$pkgdir/usr/lib/tmpfiles.d"
  local udevdir="$pkgdir/usr/lib/udev/rules.d"

  echo "Copying source files"
  [[ -d "$libdir" ]] || mkdir -p "$libdir"
  _install "$libdir" 644 "src"/*
  _install "$libdir" 755 "src/weewx_data/bin"

  echo "Creating entrypoints"
  [[ -d "$bindir" ]] || mkdir -p "$bindir"
  for f in ${entrypoints[@]}; do
    echo "Creating entrypoint $f"
    sed \
      -e "s%WEEWX_BINDIR=.*%WEEWX_BINDIR=\"${weewx_bindir}\"%" \
      -e "s%WEEWX_PYTHON=.*%WEEWX_PYTHON=\"${PYTHON}\"%" \
      "bin/$f" > "$bindir/$f"
    chmod 755 "$bindir/$f"
  done

  echo "Copying license and copyright"
  install -Dm644 "docs_src/copyright.md" "$licensedir/copyright.md"
  install -Dm644 "LICENSE.txt" "$licensedir/LICENSE.txt"

  echo "Copying skins"
  [[ -d "$sharedir" ]] || mkdir -p "$sharedir"
  _install "$sharedir" 644 "src/weewx_data/skins"

  echo "Copying ancillary files"
  _install "$sharedir" 644 "src/weewx_data/examples"
  _install "$sharedir" 644 "src/weewx_data/util/import"
  _install "$sharedir" 644 "src/weewx_data/util/logwatch"
  _install "$sharedir" 644 "src/weewx_data/util/systemd"
  _install "$sharedir" 644 "src/weewx_data/util/udev"

  echo "Creating configuration file"
  [[ -d "$etcdir" ]] || mkdir -p "$etcdir"
  nl=$'\n'
  sed \
    -e "/version =.*/a\\${nl}\\${nl}# Installation path\\${nl}WEEWX_ROOT = $weewx_bindir" \
    -e "s%SKIN_ROOT =.*%SKIN_ROOT = $weewx_sharedir/skins%" \
    -e "s%HTML_ROOT = public_html%HTML_ROOT = $weewx_vardir/www%" \
    -e "s%SQLITE_ROOT = .*%SQLITE_ROOT = $weewx_vardir%" \
    "src/weewx_data/weewx.conf" > "$etcdir/weewx.conf"
  chmod 644 "$etcdir/weewx.conf"

  echo "Creating systemd unit"
  [[ -d "$unitdir" ]] || mkdir -p "$unitdir"
  sed \
    -e "s%StandardError=journal+console%StandardError=journal%" \
    "$srcdir/$pkgbase-$pkgver/pkg/etc/systemd/system/weewx.service" > "$unitdir/weewx.service"
  chmod 644 "$unitdir/weewx.service"
  sed \
    -e "s%StandardError=journal+console%StandardError=journal%" \
    "$srcdir/$pkgbase-$pkgver/pkg/etc/systemd/system/weewx@.service" > "$unitdir/weewx@.service"
  chmod 644 "$unitdir/weewx@.service"

  echo "Creating system user definition"
  install -Dm644 "$srcdir/weewx.sysusers" "$sysusersdir/weewx.conf"

  echo "Creating tmpfiles definition"
  install -Dm644 "$srcdir/weewx.tmpfiles" "$tmpfilesdir/weewx.conf"

  echo "Creating udev ruleset"
  install -Dm644 "src/weewx_data/util/udev/rules.d/weewx.rules" "$udevdir/weewx.rules"
}

package_weewx-docs() {
  pkgdesc="Documentation for WeeWX"

  cd "$srcdir/${pkgbase}-${pkgver}"

  local docdir="$pkgdir/usr/share/doc/weewx"

  echo "Copying documentation"
  [[ -d "$docdir" ]] || mkdir -p "$docdir"
  _install "$docdir" 644 "build/docs"/*
}