|
1 | 1 | #!/bin/bash |
2 | | -set -e |
| 2 | +set -euo pipefail |
3 | 3 | set -x |
4 | 4 |
|
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" |
8 | 10 | bundle_dir="build/linux/x64/release/bundle" |
| 11 | +flatpak_bundle="$base_dir/$app_id.flatpak" |
| 12 | +flatpak_repo_file="$base_dir/$app_id.flatpakrepo" |
9 | 13 |
|
10 | | -pushd . |
| 14 | +copy_host_library() { |
| 15 | + local pattern="$1" |
| 16 | + local destination_dir="$2" |
| 17 | + local matches=() |
| 18 | + local lib_dir |
11 | 19 |
|
| 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 |
12 | 73 | cd .. |
13 | 74 |
|
14 | | -# Build Flutter app |
| 75 | +# Build Flutter app. |
15 | 76 | flutter clean |
16 | | -# flutter gen-l10n |
17 | | -export APPLICATION_ID=app.openauthenticator.OpenAuthenticator |
| 77 | +export APPLICATION_ID="$app_id" |
18 | 78 | flutter build linux --release |
19 | 79 |
|
20 | 80 | 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 |
23 | 117 |
|
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" |
28 | 120 |
|
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