Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/erc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ extract_archive()
exit
fi

if [ "$type" = "flatpak" ] ; then
_flatpak_prepare_repo "$rarc" "extract"

TMP_EXTRACT_DIR="tmp_extract_$$"
docmd ostree checkout --repo="$FLATPAK_REPO_DIR" --user-mode "$FLATPAK_REF" "$TMP_EXTRACT_DIR"

EXTRACT_DIR="$(basename "$arc" .flatpak)"
if [ -d "$TMP_EXTRACT_DIR/files" ]; then
mkdir -p "$EXTRACT_DIR"
docmd cp -r "$TMP_EXTRACT_DIR/files/." "$EXTRACT_DIR/"
else
docmd mv "$TMP_EXTRACT_DIR" "$EXTRACT_DIR"
fi

rm -rf "$TMP_EXTRACT_DIR" "$FLATPAK_REPO_DIR"
exit
fi

if have_patool ; then
docmd patool $verbose extract "$arc" "$@"
return
Expand Down Expand Up @@ -174,6 +192,13 @@ list_archive()
return
fi

if [ "$(get_archive_type "$arc" 2>/dev/null)" = "flatpak" ] ; then
_flatpak_prepare_repo "$(realpath -s "$arc")" "list"
docmd ostree ls --repo="$FLATPAK_REPO_DIR" -R "$FLATPAK_REF"
rm -rf "$FLATPAK_REPO_DIR"
return
fi

if have_patool ; then
docmd patool $verbose list "$arc" "$@"
return
Expand All @@ -200,6 +225,13 @@ test_archive()
return
fi

if [ "$(get_archive_type "$arc" 2>/dev/null)" = "flatpak" ] ; then
_flatpak_prepare_repo "$(realpath -s "$arc")" "test"
echo "Flatpak file is valid"
rm -rf "$FLATPAK_REPO_DIR"
return
fi

if have_patool ; then
docmd patool $verbose test "$arc" "$@"
return
Expand Down
1 change: 1 addition & 0 deletions bin/erc-sh-archive
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dll
AppImage
appimage
squashfs
flatpak
EOF
}

Expand Down
24 changes: 24 additions & 0 deletions bin/erc-sh-functions
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,27 @@ subst()
sed -i -e "$@"
}
fi

# init OSTree repo and import flatpak (sets FLATPAK_REPO_DIR, FLATPAK_REF)
_flatpak_prepare_repo()
{
local flatpak_file="$1"
local operation="$2"

if ! is_command ostree || ! is_command flatpak; then
fatal "ostree and flatpak are required to $operation flatpak files"
fi

FLATPAK_REPO_DIR="repo_$$_$(date +%s)"

docmd ostree init --repo="$FLATPAK_REPO_DIR" --mode=archive

flatpak build-import-bundle "$FLATPAK_REPO_DIR" "$flatpak_file" >/dev/null 2>&1 || fatal "failed to import flatpak bundle"

FLATPAK_REF=$(ostree refs --repo="$FLATPAK_REPO_DIR" | head -n 1)
if [ -z "$FLATPAK_REF" ]; then
rm -rf "$FLATPAK_REPO_DIR"
fatal "could not get ref from repository"
fi
}