create-usb: Add a create-usb command to complement OstreeRepoFinderMount
This can be used to put OSTree repositories on USB sticks in a format recognised by OstreeRepoFinderMount. Signed-off-by: Philip Withnall <withnall@endlessm.com> Closes: #1182 Approved by: cgwalters
This commit is contained in:
1 parent
f923c2e1ea
commit
9546e6795e
9 files changed
+532
-1
No files matched your search
@@ -3,6 +3,7 @@
|
||||
*.test
|
||||
*.trs
|
||||
ostree-http-server
|
||||
repo-finder-mount
|
||||
run-apache
|
||||
tmpdir-lifecycle
|
||||
test-rollsum
|
||||
|
||||
@@ -603,6 +603,12 @@ skip_without_fuse () {
|
||||
[ -e /etc/mtab ] || skip "no /etc/mtab"
|
||||
}
|
||||
|
||||
skip_without_experimental () {
|
||||
if ! ostree --version | grep -q -e '- experimental'; then
|
||||
skip "No experimental API is compiled in"
|
||||
fi
|
||||
}
|
||||
|
||||
has_gpgme () {
|
||||
${CMD_PREFIX} ostree --version > version.txt
|
||||
assert_file_has_content version.txt '- gpgme'
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright © 2017 Endless Mobile, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* - Philip Withnall <withnall@endlessm.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-remote-private.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-finder-mount.h"
|
||||
#include "ostree-types.h"
|
||||
#include "test-mock-gio.h"
|
||||
|
||||
static void
|
||||
result_cb (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GAsyncResult **result_out = user_data;
|
||||
*result_out = g_object_ref (result);
|
||||
}
|
||||
|
||||
static void
|
||||
collection_ref_free0 (OstreeCollectionRef *ref)
|
||||
{
|
||||
g_clear_pointer (&ref, (GDestroyNotify) ostree_collection_ref_free);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
if (argc < 5 || (argc % 2) != 1)
|
||||
{
|
||||
g_printerr ("Usage: %s REPO MOUNT-ROOT COLLECTION-ID REF-NAME [COLLECTION-ID REF-NAME …]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_autoptr(GMainContext) context = g_main_context_new ();
|
||||
g_main_context_push_thread_default (context);
|
||||
|
||||
g_autoptr(OstreeRepo) parent_repo = ostree_repo_open_at (AT_FDCWD, argv[1], NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
/* Set up a mock volume. */
|
||||
g_autoptr(GFile) mount_root = g_file_new_for_commandline_arg (argv[2]);
|
||||
g_autoptr(GMount) mount = G_MOUNT (ostree_mock_mount_new ("mount", mount_root));
|
||||
|
||||
g_autoptr(GList) mounts = g_list_prepend (NULL, mount);
|
||||
|
||||
g_autoptr(GVolumeMonitor) monitor = ostree_mock_volume_monitor_new (mounts, NULL);
|
||||
g_autoptr(OstreeRepoFinderMount) finder = ostree_repo_finder_mount_new (monitor);
|
||||
|
||||
/* Resolve the refs. */
|
||||
g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func ((GDestroyNotify) collection_ref_free0);
|
||||
|
||||
for (gsize i = 3; i < argc; i += 2)
|
||||
{
|
||||
const char *collection_id = argv[i];
|
||||
const char *ref_name = argv[i + 1];
|
||||
|
||||
g_ptr_array_add (refs, ostree_collection_ref_new (collection_id, ref_name));
|
||||
}
|
||||
|
||||
g_ptr_array_add (refs, NULL); /* NULL terminator */
|
||||
|
||||
g_autoptr(GAsyncResult) result = NULL;
|
||||
ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder),
|
||||
(const OstreeCollectionRef * const *) refs->pdata,
|
||||
parent_repo, NULL, result_cb, &result);
|
||||
|
||||
while (result == NULL)
|
||||
g_main_context_iteration (context, TRUE);
|
||||
|
||||
g_autoptr(GPtrArray) results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder),
|
||||
result, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
/* Check that the results are correct: the invalid refs should have been
|
||||
* ignored, and the valid results canonicalised and deduplicated. */
|
||||
for (gsize i = 0; i < results->len; i++)
|
||||
{
|
||||
const OstreeRepoFinderResult *result = g_ptr_array_index (results, i);
|
||||
GHashTableIter iter;
|
||||
OstreeCollectionRef *ref;
|
||||
const gchar *checksum;
|
||||
|
||||
g_hash_table_iter_init (&iter, result->ref_to_checksum);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum))
|
||||
g_print ("%" G_GSIZE_FORMAT " %s %s %s %s\n",
|
||||
i, ostree_remote_get_name (result->remote),
|
||||
ref->collection_id, ref->ref_name,
|
||||
checksum);
|
||||
}
|
||||
|
||||
g_main_context_pop_thread_default (context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright © 2017 Endless Mobile, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Authors:
|
||||
# - Philip Withnall <withnall@endlessm.com>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
. $(dirname $0)/libtest.sh
|
||||
|
||||
echo "1..5"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir repo
|
||||
ostree_repo_init repo --collection-id org.example.Collection1
|
||||
|
||||
mkdir -p tree/root
|
||||
touch tree/root/a
|
||||
|
||||
# Add a few commits
|
||||
seq 5 | while read i; do
|
||||
echo a >> tree/root/a
|
||||
${CMD_PREFIX} ostree --repo=repo commit --branch=test-$i -m test -s test --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}" tree
|
||||
done
|
||||
|
||||
${CMD_PREFIX} ostree --repo=repo summary --update --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}"
|
||||
|
||||
# Pull into a ‘local’ repository, to more accurately represent the situation of
|
||||
# creating a USB stick from your local machine.
|
||||
mkdir local-repo
|
||||
${CMD_PREFIX} ostree --repo=local-repo init
|
||||
${CMD_PREFIX} ostree --repo=local-repo remote add remote1 file://$(pwd)/repo --collection-id org.example.Collection1 --gpg-import="${test_tmpdir}/gpghome/key1.asc"
|
||||
${CMD_PREFIX} ostree --repo=local-repo pull remote1 test-1 test-2 test-3 test-4 test-5
|
||||
|
||||
# Simple test to put two refs onto a USB stick.
|
||||
mkdir dest-mount1
|
||||
${CMD_PREFIX} ostree --repo=local-repo create-usb dest-mount1 org.example.Collection1 test-1 org.example.Collection1 test-2
|
||||
|
||||
assert_has_dir dest-mount1/.ostree/repo
|
||||
${CMD_PREFIX} ostree --repo=dest-mount1/.ostree/repo refs --collections > dest-refs
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-1)$"
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-2)$"
|
||||
assert_not_file_has_content dest-refs "^(org.example.Collection1, test-3)$"
|
||||
assert_has_file dest-mount1/.ostree/repo/summary
|
||||
|
||||
echo "ok 1 simple usb"
|
||||
|
||||
# Test that the repository can be placed in another standard location on the USB stick.
|
||||
for dest in ostree/repo .ostree/repo; do
|
||||
rm -rf dest-mount2
|
||||
mkdir dest-mount2
|
||||
${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo "$dest" dest-mount2 org.example.Collection1 test-1
|
||||
assert_has_dir "dest-mount2/$dest"
|
||||
if [ -d dest-mount2/.ostree/repos.d ]; then
|
||||
ls dest-mount2/.ostree/repos.d | wc -l > repo-links
|
||||
assert_file_has_content repo-links "^0$"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "ok 2 usb in standard location"
|
||||
|
||||
# Test that the repository can be placed in a non-standard location and gets a symlink to it.
|
||||
mkdir dest-mount3
|
||||
${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo some-dest dest-mount3 org.example.Collection1 test-1
|
||||
assert_has_dir "dest-mount3/some-dest"
|
||||
assert_symlink_has_content "dest-mount3/.ostree/repos.d/00-generated" "/some-dest$"
|
||||
${CMD_PREFIX} ostree --repo=dest-mount3/.ostree/repos.d/00-generated refs --collections > dest-refs
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-1)$"
|
||||
assert_has_file dest-mount3/.ostree/repos.d/00-generated/summary
|
||||
|
||||
echo "ok 3 usb in non-standard location"
|
||||
|
||||
# Test that adding an additional ref to an existing USB repository works.
|
||||
${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo some-dest dest-mount3 org.example.Collection1 test-2 org.example.Collection1 test-3
|
||||
assert_has_dir "dest-mount3/some-dest"
|
||||
assert_symlink_has_content "dest-mount3/.ostree/repos.d/00-generated" "/some-dest$"
|
||||
${CMD_PREFIX} ostree --repo=dest-mount3/.ostree/repos.d/00-generated refs --collections > dest-refs
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-1)$"
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-1)$"
|
||||
assert_file_has_content dest-refs "^(org.example.Collection1, test-3)$"
|
||||
assert_has_file dest-mount3/.ostree/repos.d/00-generated/summary
|
||||
|
||||
echo "ok 4 adding ref to an existing usb"
|
||||
|
||||
# Check that #OstreeRepoFinderMount works from a volume initialised uing create-usb.
|
||||
mkdir finder-repo
|
||||
ostree_repo_init finder-repo
|
||||
${CMD_PREFIX} ostree --repo=finder-repo remote add remote1 file://$(pwd)/just-needed-for-the-keyring --collection-id org.example.Collection1 --gpg-import="${test_tmpdir}/gpghome/key1.asc"
|
||||
|
||||
${test_builddir}/repo-finder-mount finder-repo dest-mount1 org.example.Collection1 test-1 org.example.Collection1 test-2 &> out
|
||||
assert_file_has_content out "^0 .*_2Fdest-mount1_2F.ostree_2Frepo_remote1.trustedkeys.gpg org.example.Collection1 test-1 $(ostree --repo=repo show test-1)$"
|
||||
assert_file_has_content out "^0 .*_2Fdest-mount1_2F.ostree_2Frepo_remote1.trustedkeys.gpg org.example.Collection1 test-2 $(ostree --repo=repo show test-2)$"
|
||||
|
||||
echo "ok 5 find from usb repo"
|
||||
Reference in new issue
Block a user