Skip to content

Commit a5154d2

Browse files
committed
chore(snap): Updated the Snapcraft build scripts.
1 parent 8013446 commit a5154d2

8 files changed

Lines changed: 245 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ lib/app.dart
5656
/assets/images/**/*.si
5757

5858
# Snap
59-
snap/meta/polkit
6059
open-authenticator_*.snap
6160

6261
# Flatpak

snap-build.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
set -x
4+
5+
script_dir=$(cd "$(dirname "$0")" && pwd)
6+
snap_dir="$script_dir/snap"
7+
env_file="${SNAP_ENV_FILE:-}"
8+
9+
docker_image="${SNAPCRAFT_DOCKER_IMAGE:-ghcr.io/canonical/snapcraft:8_core24}"
10+
container_workspace="${SNAPCRAFT_CONTAINER_WORKSPACE:-/project}"
11+
output_dir="${SNAP_OUTPUT_DIR:-$script_dir}"
12+
platform="${SNAPCRAFT_DOCKER_PLATFORM:-}"
13+
apt_update="${SNAPCRAFT_APT_UPDATE:-1}"
14+
15+
load_env_file() {
16+
local candidate="$1"
17+
18+
if [[ -z "$candidate" || ! -f "$candidate" ]]; then
19+
return 0
20+
fi
21+
22+
set -a
23+
# shellcheck disable=SC1090
24+
. "$candidate"
25+
set +a
26+
}
27+
28+
strip_trailing_cr() {
29+
printf '%s' "${1%$'\r'}"
30+
}
31+
32+
if [[ -n "$env_file" ]]; then
33+
load_env_file "$env_file"
34+
else
35+
load_env_file "$script_dir/.env"
36+
load_env_file "$snap_dir/.env"
37+
fi
38+
39+
docker_image=$(strip_trailing_cr "${SNAPCRAFT_DOCKER_IMAGE:-$docker_image}")
40+
container_workspace=$(strip_trailing_cr "${SNAPCRAFT_CONTAINER_WORKSPACE:-$container_workspace}")
41+
output_dir=$(strip_trailing_cr "${SNAP_OUTPUT_DIR:-$output_dir}")
42+
platform=$(strip_trailing_cr "${SNAPCRAFT_DOCKER_PLATFORM:-$platform}")
43+
apt_update=$(strip_trailing_cr "${SNAPCRAFT_APT_UPDATE:-$apt_update}")
44+
45+
if [[ "$output_dir" != /* ]]; then
46+
output_dir="$script_dir/$output_dir"
47+
fi
48+
49+
if ! command -v docker >/dev/null 2>&1; then
50+
echo "Docker is required to build the snap without a local snapcraft installation." >&2
51+
exit 1
52+
fi
53+
54+
if ! command -v rsync >/dev/null 2>&1; then
55+
echo "rsync is required to prepare a clean Docker build context." >&2
56+
exit 1
57+
fi
58+
59+
if [[ ! -f "$snap_dir/snapcraft.yaml" ]]; then
60+
echo "snap/snapcraft.yaml was not found." >&2
61+
exit 1
62+
fi
63+
64+
mkdir -p "$output_dir"
65+
66+
build_context=$(mktemp -d)
67+
cleanup_host() {
68+
if [[ -d "$build_context" ]]; then
69+
chmod -R u+rwX "$build_context" 2>/dev/null || true
70+
rm -rf "$build_context" || true
71+
fi
72+
}
73+
trap cleanup_host EXIT
74+
75+
rsync -a --no-owner --no-group --delete \
76+
--exclude '.git' \
77+
--exclude '.dart_tool' \
78+
--exclude '.flatpak-builder' \
79+
--exclude '.pub-cache' \
80+
--exclude '.snapcraft' \
81+
--exclude 'build' \
82+
--exclude 'parts' \
83+
--exclude 'prime' \
84+
--exclude 'stage' \
85+
--exclude '*.snap' \
86+
"$script_dir/" \
87+
"$build_context/"
88+
89+
docker_args=(
90+
run
91+
--rm
92+
--entrypoint /bin/sh
93+
--volume "$build_context:$container_workspace"
94+
--workdir "$container_workspace"
95+
--env "HOST_UID=$(id -u)"
96+
--env "HOST_GID=$(id -g)"
97+
--env "SNAPCRAFT_APT_UPDATE=$apt_update"
98+
)
99+
100+
if [[ -n "$platform" ]]; then
101+
docker_args+=(--platform "$platform")
102+
fi
103+
104+
docker_args+=(
105+
"$docker_image"
106+
-c
107+
'set -eu
108+
cleanup() {
109+
chown -R "$HOST_UID:$HOST_GID" .
110+
}
111+
trap cleanup EXIT
112+
if [ ! -e /usr/share/snapcraft/extensions/desktop ]; then
113+
extensions_desktop_dir=$(find /usr/lib -path "*/site-packages/extensions/desktop" -type d | head -n 1)
114+
if [ -n "$extensions_desktop_dir" ]; then
115+
mkdir -p /usr/share/snapcraft/extensions
116+
ln -s "$extensions_desktop_dir" /usr/share/snapcraft/extensions/desktop
117+
fi
118+
fi
119+
if [ "${SNAPCRAFT_APT_UPDATE:-1}" = "1" ]; then
120+
apt-get update
121+
fi
122+
snapcraft pack --destructive-mode "$@"'
123+
sh
124+
)
125+
126+
docker "${docker_args[@]}" "$@"
127+
128+
mapfile -t snap_files < <(find "$build_context" -maxdepth 1 -type f -name "*.snap" -print)
129+
if [[ "${#snap_files[@]}" -eq 0 ]]; then
130+
echo "No snap artifact was produced." >&2
131+
exit 1
132+
fi
133+
134+
for snap_file in "${snap_files[@]}"; do
135+
mv "$snap_file" "$output_dir/"
136+
done
137+
138+
printf 'Snap artifact(s):\n'
139+
for snap_file in "${snap_files[@]}"; do
140+
printf ' %s\n' "$output_dir/$(basename "$snap_file")"
141+
done

snap/meta/polkit/po/de.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
msgid "Authentication required"
2+
msgstr "Authentifizierung erforderlich"
3+
4+
msgid "Authenticate to access the app."
5+
msgstr "Authentifizieren Sie sich, um auf die App zuzugreifen."
6+
7+
msgid "Authenticate to continue."
8+
msgstr "Authentifizieren Sie sich, um fortzufahren."
9+
10+
msgid "Authenticate to enable local authentication."
11+
msgstr "Authentifizieren Sie sich, um die lokale Authentifizierung zu aktivieren."
12+
13+
msgid "Authenticate to disable local authentication."
14+
msgstr "Authentifizieren Sie sich, um die lokale Authentifizierung zu deaktivieren."

snap/meta/polkit/po/fr.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
msgid "Authentication required"
2+
msgstr "Authentification requise"
3+
4+
msgid "Authenticate to access the app."
5+
msgstr "Authentifiez-vous pour accéder à l'application."
6+
7+
msgid "Authenticate to continue."
8+
msgstr "Authentifiez-vous pour continuer."
9+
10+
msgid "Authenticate to enable local authentication."
11+
msgstr "Authentifiez-vous pour activer l'authentification locale."
12+
13+
msgid "Authenticate to disable local authentication."
14+
msgstr "Authentifiez-vous pour désactiver l'authentification locale."

snap/meta/polkit/po/it.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
msgid "Authentication required"
2+
msgstr "Autenticazione richiesta"
3+
4+
msgid "Authenticate to access the app."
5+
msgstr "Autenticati per accedere all'app."
6+
7+
msgid "Authenticate to continue."
8+
msgstr "Autenticati per continuare."
9+
10+
msgid "Authenticate to enable local authentication."
11+
msgstr "Autenticati per abilitare l'autenticazione locale."
12+
13+
msgid "Authenticate to disable local authentication."
14+
msgstr "Autenticati per disabilitare l'autenticazione locale."

snap/meta/polkit/po/pt.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
msgid "Authentication required"
2+
msgstr "Autenticação necessária"
3+
4+
msgid "Authenticate to access the app."
5+
msgstr "Autentique-se para acessar o app."
6+
7+
msgid "Authenticate to continue."
8+
msgstr "Autentique-se para continuar."
9+
10+
msgid "Authenticate to enable local authentication."
11+
msgstr "Autentique-se para ativar a autenticação local."
12+
13+
msgid "Authenticate to disable local authentication."
14+
msgstr "Autentique-se para desativar a autenticação local."
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<policyconfig>
3+
<action id="app.openauthenticator.openApp">
4+
<description gettext-domain="polkit.app.openauthenticator">Authentication required</description>
5+
<message gettext-domain="polkit.app.openauthenticator">Authenticate to access the app.</message>
6+
<defaults>
7+
<allow_any>auth_self</allow_any>
8+
<allow_inactive>auth_self</allow_inactive>
9+
<allow_active>auth_self</allow_active>
10+
</defaults>
11+
</action>
12+
<action id="app.openauthenticator.sensibleAction">
13+
<description gettext-domain="polkit.app.openauthenticator">Authentication required</description>
14+
<message gettext-domain="polkit.app.openauthenticator">Authenticate to continue.</message>
15+
<defaults>
16+
<allow_any>auth_self</allow_any>
17+
<allow_inactive>auth_self</allow_inactive>
18+
<allow_active>auth_self</allow_active>
19+
</defaults>
20+
</action>
21+
<action id="app.openauthenticator.enable">
22+
<description gettext-domain="polkit.app.openauthenticator">Authentication required</description>
23+
<message gettext-domain="polkit.app.openauthenticator">Authenticate to enable local authentication.</message>
24+
<defaults>
25+
<allow_any>auth_self</allow_any>
26+
<allow_inactive>auth_self</allow_inactive>
27+
<allow_active>auth_self</allow_active>
28+
</defaults>
29+
</action>
30+
<action id="app.openauthenticator.disable">
31+
<description gettext-domain="polkit.app.openauthenticator">Authentication required</description>
32+
<message gettext-domain="polkit.app.openauthenticator">Authenticate to disable local authentication.</message>
33+
<defaults>
34+
<allow_any>auth_self</allow_any>
35+
<allow_inactive>auth_self</allow_inactive>
36+
<allow_active>auth_self</allow_active>
37+
</defaults>
38+
</action>
39+
</policyconfig>

snap/snapcraft.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ apps:
3737
slots:
3838
- open-authenticator-dbus
3939
environment:
40+
LD_LIBRARY_PATH: $SNAP/usr/lib/jvm/default-java/lib/server:$LD_LIBRARY_PATH
4041
XDG_DATA_DIRS: $SNAP/usr/share:$XDG_DATA_DIRS
4142

4243
parts:
@@ -45,7 +46,15 @@ parts:
4546
plugin: flutter
4647
flutter-target: lib/main.dart
4748
build-packages:
49+
- default-jdk-headless
50+
- libcurl4-openssl-dev
51+
- libgtk-3-dev
4852
- libpolkit-gobject-1-dev
53+
- libsecret-1-dev
54+
- lld-18
55+
- llvm-18
56+
stage-packages:
57+
- default-jre-headless
4958
polkit-locale:
5059
plugin: nil
5160
source: snap/meta/polkit/po

0 commit comments

Comments
 (0)