summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 23c0f5ecf7a1e6f97af582e25f7154e9d4a4512a (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
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
219
# Maintainer: Terrabade <terrabade@protonmail.com>
# Upstream Maintainer: Zoey Bauer <zoey.erin.bauer@gmail.com>
# Upstream Maintainer: Caroline Snyder <hirpeng@gmail.com>
pkgbase=shelly-gnome
pkgname=('shelly-gnome' 'shelly-gnome-flatpak-backend')
pkgver=3.1.2.gnome1
pkgrel=1
arch=('x86_64' 'aarch64')
url="https://github.com/Terrabade/Shelly-ALPM-GNOME"
license=('GPL-3.0-only')
makedepends=('git' 'pkgconf' 'gtk4' 'libadwaita' 'zig>=0.16' 'clang' 'gettext' 'flatpak' 'ripgrep' 'go-md2man')

# Source tarball from GitHub release
# Upstream lists shellybuild.conf, the two .desktop files and
# shelly-flatpak-integrate as separate source entries, which requires keeping
# copies of them next to the PKGBUILD. They are already in the repo root, so we
# install them straight out of the extracted tarball instead and the AUR repo
# stays down to PKGBUILD + .SRCINFO.
source=("${pkgbase}-${pkgver}.tar.gz::https://github.com/Terrabade/Shelly-ALPM-GNOME/archive/v${pkgver}.tar.gz")

sha256sums=('1fc9cf0a7a82c59b7b1a884717bc5522a7a72f92263a0c8156f2cee85aa49ba7')
# GitHub sanitises '+' to '-' in the archive's root directory, so the extracted
# tree is Shelly-ALPM-GNOME-3.0.0-9.gnome1 even though the tag is v3.0.0+9.gnome1.
_source_dir="Shelly-ALPM-GNOME-${pkgver//+/-}"

build() {
  cd "$srcdir/${_source_dir}"

  (cd Shelly.Flatpak.Backend && zig build --verbose \
    --prefix "${srcdir}/${_source_dir}/out-flatpak-backend" \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache" \
    -Dcpu=baseline \
    -Doptimize=ReleaseSafe)

  (cd Shelly.Ui.Gtk && zig build --verbose \
    --prefix "${srcdir}/${_source_dir}/out" \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache" \
    -Dflatpak-backend-package=shelly-gnome-flatpak-backend \
    -Dcpu=baseline \
    -Doptimize=ReleaseSafe)

  (cd Shelly.Cli.Zig && zig build --verbose \
    --prefix "${srcdir}/${_source_dir}/out-cli" \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache" \
    -Dcpu=baseline \
    -Doptimize=ReleaseSmall)

  (cd Shelly.Key && zig build --verbose \
    --prefix "${srcdir}/${_source_dir}/out-key" \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache" \
    -Dcpu=baseline \
    -Doptimize=ReleaseSmall)

   (cd Shelly.Notifications.Zig && zig build --verbose \
     --prefix "${srcdir}/${_source_dir}/out-notifications" \
     --cache-dir "${srcdir}/zig-cache" \
     --global-cache-dir "${srcdir}/zig-global-cache" \
     -Dcpu=baseline \
     -Doptimize=ReleaseSmall)

  ./out-cli/bin/shelly utility --completions bash > shelly.bash
  ./out-cli/bin/shelly utility --completions fish > shelly.fish
  ./out-cli/bin/shelly utility --completions zsh  > _shelly

  ./out-cli/bin/shelly utility --docs | go-md2man > shelly.1
  sed -i "s|^\\.TH .*|.TH \"SHELLY\" \"1\" \"\" \"Shelly ${pkgver}\" \"Shelly CLI Manual\"|" shelly.1
  printf '\n.SH AUTHORS\nSeafoam Labs.\n' >> shelly.1

  for po_file in Shelly.Ui.Gtk/po/*.po; do
    [ -f "$po_file" ] || continue
    lang=$(basename "$po_file" .po)
    msgfmt "$po_file" -o "shelly-ui-${lang}.mo"
  done

  for po_file in Shelly.Notifications.Zig/po/*.po; do
    [ -f "$po_file" ] || continue
    lang=$(basename "$po_file" .po)
    msgfmt "$po_file" -o "shelly-notifications-${lang}.mo"
  done
}

check() {
  cd "$srcdir/${_source_dir}"

  (cd Shelly.Flatpak.Backend && zig build test abi-test integration-test \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache")
  (cd Shelly.PackageManager && zig build flatpak-test \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache")
  (cd Shelly.Cli.Zig && zig build test \
    --cache-dir "${srcdir}/zig-cache" \
    --global-cache-dir "${srcdir}/zig-global-cache")
}

package_shelly-gnome() {
  pkgdesc="Shelly for GNOME: Libadwaita port of the Shelly Arch Linux Package Manager."
  provides=('shelly')
  conflicts=('shelly' 'shelly-bin' 'shelly-git')
  backup=('etc/shellybuild.conf')
  depends=(
      'pacman'
      'gtk4'
      'libadwaita'
      'glib2'
      'sudo'
      'tar'
      'bash'
      'git'
      'hicolor-icon-theme'
      'dbus'
      'glibc'
      'libarchive'
      'dconf'
      'gnupg'
      'zstd'
      'json-glib'
  )
  optdepends=(
      'arch-install-scripts: provision fresh roots for --isolated builds'
      'fish: Fish shell completions'
      'zsh: Zsh shell completions'
      'libstarfish: dependency viewer for arch packages'
      'shelly-gnome-flatpak-backend: Flatpak package management support'
      'fuse2: run AppImages that require FUSE 2'
  )

  cd "$srcdir/${_source_dir}"
  install -Dm755 out-notifications/bin/shelly-notifications "$pkgdir/usr/bin/shelly-notifications"
  install -Dm755 out/bin/Shelly_Ui_Gtk "$pkgdir/usr/bin/shelly-ui"
  install -Dm755 out-cli/bin/shelly "$pkgdir/usr/bin/shelly"
  install -Dm755 out-key/bin/shelly-key "$pkgdir/usr/bin/shelly-key"
  install -Dm644 "$srcdir/${_source_dir}/shellybuild.conf" "$pkgdir/etc/shellybuild.conf"

  # Install desktop entries
  install -Dm644 "$srcdir/${_source_dir}/com.shellyorg.shelly.desktop" \
    "$pkgdir/usr/share/applications/com.shellyorg.shelly.desktop"
  install -Dm644 "$srcdir/${_source_dir}/com.shellyorg.shelly-notifications.desktop" \
    "$pkgdir/usr/share/applications/com.shellyorg.shelly-notifications.desktop"

  # Ensure the polkit directory exists
  install -m0755 -d "${pkgdir}"/usr/share/polkit-1/actions

  # Install Polkit policy for privileged Shelly CLI execution via pkexec
  cat <<'EOF' | install -Dm644 /dev/stdin "$pkgdir/usr/share/polkit-1/actions/com.shellyorg.shelly.policy"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
  <vendor>Shelly</vendor>
  <vendor_url>https://github.com/Seafoam-Labs/Shelly-ALPM</vendor_url>
  <action id="com.shellyorg.shelly.pkexec.cli">
    <description>Run Shelly CLI as administrator</description>
    <message>Run Shelly CLI with administrator privileges.</message>
    <icon_name>shelly</icon_name>
    <defaults>
      <allow_any>auth_admin</allow_any>
      <allow_inactive>auth_admin</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/shelly</annotate>
  </action>
</policyconfig>
EOF

  # Install icon
  install -Dm644 assets/shellylogo.png "$pkgdir/usr/share/icons/hicolor/256x256/apps/shelly.png"
  install -Dm644 assets/shelly-updates-symbolic.svg "$pkgdir/usr/share/icons/hicolor/symbolic/apps/shelly-updates-symbolic.svg"
  install -Dm644 assets/shelly-shell-symbolic.svg "$pkgdir/usr/share/icons/hicolor/symbolic/apps/shelly-shell-symbolic.svg"

  install -Dm644 assets/shellylogo-tray.png "$pkgdir/usr/share/icons/hicolor/256x256/apps/shelly-tray.png"
  install -Dm644 assets/shellylogo-update.png "$pkgdir/usr/share/icons/hicolor/256x256/apps/shelly-update.png"

  # Install shell completions
  install -Dm644 shelly.bash "$pkgdir/usr/share/bash-completion/completions/shelly"
  install -Dm644 shelly.fish "$pkgdir/usr/share/fish/vendor_completions.d/shelly.fish"
  install -Dm644 _shelly "$pkgdir/usr/share/zsh/site-functions/_shelly"

  # Install man page
  install -Dm644 shelly.1 "$pkgdir/usr/share/man/man1/shelly.1"

  # Install translations
  for mo_file in shelly-ui-*.mo; do
    if [ -f "$mo_file" ]; then
      lang=$(echo "$mo_file" | sed 's/shelly-ui-\(.*\)\.mo/\1/')
      install -Dm644 "$mo_file" "$pkgdir/usr/share/locale/$lang/LC_MESSAGES/shelly-ui.mo"
    fi
  done

  # Install tray service translations
    for mo_file in shelly-notifications-*.mo; do
      if [ -f "$mo_file" ]; then
        lang=$(echo "$mo_file" | sed 's/shelly-notifications-\(.*\)\.mo/\1/')
        install -Dm644 "$mo_file" "$pkgdir/usr/share/locale/$lang/LC_MESSAGES/shelly-notifications.mo"
      fi
    done

  # Install Flatpak integration script
  install -Dm755 "$srcdir/${_source_dir}/shelly-flatpak-integrate" \
    "$pkgdir/usr/bin/shelly-flatpak-integrate"
}

package_shelly-gnome-flatpak-backend() {
  pkgdesc="Optional native Flatpak backend for Shelly for GNOME"
  depends=("shelly-gnome=${pkgver}" 'flatpak')
  provides=("shelly-flatpak-backend=${pkgver}")
  conflicts=('shelly-flatpak-backend' 'shelly-flatpak-backend-git' 'shelly-flatpak-backend-bin')

  cd "$srcdir/${_source_dir}"
  install -Dm755 \
    out-flatpak-backend/lib/libshelly-flatpak-backend.so.1.0.0 \
    "$pkgdir/usr/lib/shelly/libshelly-flatpak-backend.so.1.0.0"
  ln -s libshelly-flatpak-backend.so.1.0.0 \
    "$pkgdir/usr/lib/shelly/libshelly-flatpak-backend.so.1"
}