Skip to content

Commit 472df6e

Browse files
committed
chore(linux): Updated Flatpak build scripts.
1 parent 09b99ee commit 472df6e

6 files changed

Lines changed: 214 additions & 58 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ flatpak/repo
6666
flatpak/OpenAuthenticatorFlatpak
6767
flatpak/*.flatpak
6868
flatpak/*.tar.gz
69-
flatpak-build-publish.sh
69+
flatpak/public-key.asc
7070

7171
# Firebase files
7272
firebase

flatpak-build-publish.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
set -x
4+
5+
script_dir=$(cd "$(dirname "$0")" && pwd)
6+
flatpak_dir="$script_dir/flatpak"
7+
8+
app_id="app.openauthenticator.OpenAuthenticator"
9+
repo_clone_dir="${FLATPAK_PUBLISH_CLONE_DIR:-$flatpak_dir/OpenAuthenticatorFlatpak}"
10+
publish_remote="${FLATPAK_PUBLISH_REMOTE:-git@github.com:Skyost/OpenAuthenticatorFlatpak.git}"
11+
publish_branch="${FLATPAK_PUBLISH_BRANCH:-main}"
12+
repo_url="${FLATPAK_REPO_URL:-https://skyost.github.io/OpenAuthenticatorFlatpak/repo}"
13+
repo_title="${FLATPAK_REPO_TITLE:-OpenAuthenticator Flatpak}"
14+
repo_name="${FLATPAK_REPO_NAME:-app.openauthenticator.OpenAuthenticator}"
15+
default_branch="${FLATPAK_REPO_DEFAULT_BRANCH:-master}"
16+
flatpakrepo_output_name="${FLATPAK_PUBLISH_REPO_FILE:-openauthenticator.flatpakrepo}"
17+
flatpakref_output_name="${FLATPAK_PUBLISH_REF_FILE:-openauthenticator.flatpakref}"
18+
19+
write_flatpakref_file() {
20+
local destination_file="$1"
21+
local gpg_key_base64=""
22+
23+
if [[ -n "${FLATPAK_GPG_IMPORT:-}" ]]; then
24+
gpg_key_base64=$(base64 --wrap=0 < "$FLATPAK_GPG_IMPORT")
25+
fi
26+
27+
cat > "$destination_file" <<EOF
28+
[Flatpak Ref]
29+
Name=$app_id
30+
Branch=$default_branch
31+
Title=$repo_title
32+
IsRuntime=false
33+
Url=$repo_url
34+
EOF
35+
36+
if [[ -n "$gpg_key_base64" ]]; then
37+
printf 'GPGKey=%s\n' "$gpg_key_base64" >> "$destination_file"
38+
fi
39+
40+
if [[ -n "${FLATPAK_RUNTIME_REPO:-}" ]]; then
41+
printf 'RuntimeRepo=%s\n' "$FLATPAK_RUNTIME_REPO" >> "$destination_file"
42+
fi
43+
}
44+
45+
if [[ -z "${FLATPAK_GPG_KEY_ID:-}" ]]; then
46+
echo "FLATPAK_GPG_KEY_ID is required." >&2
47+
exit 1
48+
fi
49+
50+
if [[ -z "${FLATPAK_GPG_HOMEDIR:-}" ]]; then
51+
echo "FLATPAK_GPG_HOMEDIR is required." >&2
52+
exit 1
53+
fi
54+
55+
if [[ -z "$repo_url" ]]; then
56+
echo "FLATPAK_REPO_URL is required." >&2
57+
exit 1
58+
fi
59+
60+
mkdir -p "$flatpak_dir"
61+
62+
if [[ ! -d "$repo_clone_dir/.git" ]]; then
63+
git clone "$publish_remote" "$repo_clone_dir"
64+
fi
65+
66+
git -C "$repo_clone_dir" fetch origin
67+
git -C "$repo_clone_dir" checkout "$publish_branch"
68+
git -C "$repo_clone_dir" pull --ff-only origin "$publish_branch"
69+
70+
(
71+
cd "$flatpak_dir"
72+
FLATPAK_REPO_URL="$repo_url" \
73+
FLATPAK_REPO_TITLE="$repo_title" \
74+
FLATPAK_REPO_NAME="$repo_name" \
75+
FLATPAK_REPO_DEFAULT_BRANCH="$default_branch" \
76+
FLATPAK_GPG_KEY_ID="$FLATPAK_GPG_KEY_ID" \
77+
FLATPAK_GPG_HOMEDIR="$FLATPAK_GPG_HOMEDIR" \
78+
FLATPAK_GPG_IMPORT="${FLATPAK_GPG_IMPORT:-}" \
79+
FLATPAK_REPO_COMMENT="${FLATPAK_REPO_COMMENT:-}" \
80+
FLATPAK_REPO_DESCRIPTION="${FLATPAK_REPO_DESCRIPTION:-}" \
81+
FLATPAK_REPO_HOMEPAGE="${FLATPAK_REPO_HOMEPAGE:-}" \
82+
FLATPAK_REPO_ICON="${FLATPAK_REPO_ICON:-}" \
83+
./build-flutter-app.sh
84+
)
85+
86+
rsync -av --delete \
87+
--exclude '.git' \
88+
"$flatpak_dir/repo/" \
89+
"$repo_clone_dir/repo/"
90+
91+
cp "$flatpak_dir/$app_id.flatpakrepo" "$repo_clone_dir/$flatpakrepo_output_name"
92+
write_flatpakref_file "$repo_clone_dir/$flatpakref_output_name"
93+
94+
git -C "$repo_clone_dir" add repo "$flatpakrepo_output_name" "$flatpakref_output_name"
95+
96+
if git -C "$repo_clone_dir" diff --cached --quiet; then
97+
echo "No publication changes detected."
98+
exit 0
99+
fi
100+
101+
git -C "$repo_clone_dir" commit -m "${FLATPAK_PUBLISH_COMMIT_MESSAGE:-chore: update Flatpak repo}"
102+
git -C "$repo_clone_dir" push origin "$publish_branch"

flatpak/Dockerfile

Lines changed: 0 additions & 39 deletions
This file was deleted.

flatpak/app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ modules:
2525
only-arches:
2626
- x86_64
2727
build-commands:
28-
- "./build-flatpak.sh"
28+
- "./flatpak-build-subcommand.sh"
2929
sources:
3030
- type: file
31-
path: ./build-flatpak.sh
31+
path: ./flatpak-build-subcommand.sh
3232
- type: file
3333
path: ./OpenAuthenticator-Linux-Portable.tar.gz
3434
- type: file

flatpak/build-flutter-app.sh

Lines changed: 109 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,123 @@
11
#!/bin/bash
2-
set -e
2+
set -euo pipefail
33
set -x
44

5-
projectName=OpenAuthenticator
6-
archiveName=$projectName-Linux-Portable.tar.gz
7-
baseDir=$(pwd)
5+
project_name=OpenAuthenticator
6+
app_id=app.openauthenticator.OpenAuthenticator
7+
archive_name="$project_name-Linux-Portable.tar.gz"
8+
base_dir=$(pwd)
9+
repo_dir="$base_dir/repo"
810
bundle_dir="build/linux/x64/release/bundle"
11+
flatpak_bundle="$base_dir/$app_id.flatpak"
12+
flatpak_repo_file="$base_dir/$app_id.flatpakrepo"
913

10-
pushd .
14+
copy_host_library() {
15+
local pattern="$1"
16+
local destination_dir="$2"
17+
local matches=()
18+
local lib_dir
1119

20+
for lib_dir in /usr/lib64 /usr/lib/x86_64-linux-gnu; do
21+
if compgen -G "$lib_dir/$pattern" > /dev/null; then
22+
matches=("$lib_dir"/$pattern)
23+
cp -av "${matches[@]}" "$destination_dir/"
24+
return 0
25+
fi
26+
done
27+
28+
echo "Missing required host library pattern: $pattern" >&2
29+
return 1
30+
}
31+
32+
write_flatpakrepo_file() {
33+
local repo_url="$1"
34+
local repo_title="${FLATPAK_REPO_TITLE:-$project_name}"
35+
local repo_name="${FLATPAK_REPO_NAME:-$app_id}"
36+
local default_branch="${FLATPAK_REPO_DEFAULT_BRANCH:-master}"
37+
local gpg_key_base64=""
38+
39+
if [[ -n "${FLATPAK_GPG_IMPORT:-}" ]]; then
40+
gpg_key_base64=$(base64 --wrap=0 < "$FLATPAK_GPG_IMPORT")
41+
fi
42+
43+
cat > "$flatpak_repo_file" <<EOF
44+
[Flatpak Repo]
45+
Title=$repo_title
46+
Name=$repo_name
47+
Url=$repo_url
48+
DefaultBranch=$default_branch
49+
EOF
50+
51+
if [[ -n "${FLATPAK_REPO_COMMENT:-}" ]]; then
52+
printf 'Comment=%s\n' "$FLATPAK_REPO_COMMENT" >> "$flatpak_repo_file"
53+
fi
54+
55+
if [[ -n "${FLATPAK_REPO_DESCRIPTION:-}" ]]; then
56+
printf 'Description=%s\n' "$FLATPAK_REPO_DESCRIPTION" >> "$flatpak_repo_file"
57+
fi
58+
59+
if [[ -n "${FLATPAK_REPO_HOMEPAGE:-}" ]]; then
60+
printf 'Homepage=%s\n' "$FLATPAK_REPO_HOMEPAGE" >> "$flatpak_repo_file"
61+
fi
62+
63+
if [[ -n "${FLATPAK_REPO_ICON:-}" ]]; then
64+
printf 'Icon=%s\n' "$FLATPAK_REPO_ICON" >> "$flatpak_repo_file"
65+
fi
66+
67+
if [[ -n "$gpg_key_base64" ]]; then
68+
printf 'GPGKey=%s\n' "$gpg_key_base64" >> "$flatpak_repo_file"
69+
fi
70+
}
71+
72+
pushd . > /dev/null
1273
cd ..
1374

14-
# Build Flutter app
75+
# Build Flutter app.
1576
flutter clean
16-
# flutter gen-l10n
17-
export APPLICATION_ID=app.openauthenticator.OpenAuthenticator
77+
export APPLICATION_ID="$app_id"
1878
flutter build linux --release
1979

2080
mkdir -p "$bundle_dir/lib"
21-
cp -av /usr/lib/x86_64-linux-gnu/libpolkit-gobject-1.so* "$bundle_dir/lib/"
22-
cp -av /usr/lib/x86_64-linux-gnu/libsecret-1.so* "$bundle_dir/lib/"
81+
copy_host_library "libpolkit-gobject-1.so*" "$bundle_dir/lib"
82+
copy_host_library "libsecret-1.so*" "$bundle_dir/lib"
83+
84+
cd "$bundle_dir"
85+
tar -czaf "$archive_name" ./*
86+
mv "$archive_name" "$base_dir/"
87+
popd > /dev/null
88+
89+
rm -rf "$repo_dir" "$base_dir/appdir"
90+
91+
flatpak-builder --force-clean "$base_dir/appdir" "$base_dir/app.yaml" --repo="$repo_dir"
92+
93+
update_repo_args=(
94+
--generate-static-deltas
95+
--prune
96+
)
97+
98+
if [[ -n "${FLATPAK_REPO_TITLE:-}" ]]; then
99+
update_repo_args+=(--title="$FLATPAK_REPO_TITLE")
100+
fi
101+
102+
if [[ -n "${FLATPAK_REPO_DEFAULT_BRANCH:-}" ]]; then
103+
update_repo_args+=(--default-branch="$FLATPAK_REPO_DEFAULT_BRANCH")
104+
fi
105+
106+
if [[ -n "${FLATPAK_GPG_KEY_ID:-}" ]]; then
107+
update_repo_args+=(--gpg-sign="$FLATPAK_GPG_KEY_ID")
108+
109+
if [[ -n "${FLATPAK_GPG_HOMEDIR:-}" ]]; then
110+
update_repo_args+=(--gpg-homedir="$FLATPAK_GPG_HOMEDIR")
111+
fi
112+
113+
if [[ -n "${FLATPAK_GPG_IMPORT:-}" ]]; then
114+
update_repo_args+=(--gpg-import="$FLATPAK_GPG_IMPORT")
115+
fi
116+
fi
23117

24-
cd $bundle_dir || exit 1
25-
tar -czaf $archiveName ./*
26-
mv $archiveName "$baseDir"/
27-
popd
118+
flatpak build-update-repo "$repo_dir" "${update_repo_args[@]}"
119+
flatpak build-bundle "$repo_dir" "$flatpak_bundle" "$app_id"
28120

29-
flatpak-builder --force-clean appdir app.yaml --repo=repo
30-
flatpak build-bundle repo app.openauthenticator.OpenAuthenticator.flatpak app.openauthenticator.OpenAuthenticator
121+
if [[ -n "${FLATPAK_REPO_URL:-}" ]]; then
122+
write_flatpakrepo_file "$FLATPAK_REPO_URL"
123+
fi

0 commit comments

Comments
 (0)