Blame tests/test-create-usb.sh

rpm-build 0fba15
#!/bin/bash
rpm-build 0fba15
#
rpm-build 0fba15
# Copyright © 2017 Endless Mobile, Inc.
rpm-build 0fba15
#
rpm-build 0fba15
# SPDX-License-Identifier: LGPL-2.0+
rpm-build 0fba15
#
rpm-build 0fba15
# This library is free software; you can redistribute it and/or
rpm-build 0fba15
# modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
# License as published by the Free Software Foundation; either
rpm-build 0fba15
# version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
#
rpm-build 0fba15
# This library is distributed in the hope that it will be useful,
rpm-build 0fba15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
# Lesser General Public License for more details.
rpm-build 0fba15
#
rpm-build 0fba15
# You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
# License along with this library; if not, write to the
rpm-build 0fba15
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
# Boston, MA 02111-1307, USA.
rpm-build 0fba15
#
rpm-build 0fba15
# Authors:
rpm-build 0fba15
#  - Philip Withnall <withnall@endlessm.com>
rpm-build 0fba15
rpm-build 0fba15
set -euo pipefail
rpm-build 0fba15
rpm-build 0fba15
. $(dirname $0)/libtest.sh
rpm-build 0fba15
rpm-build 0fba15
skip_without_gpgme
rpm-build 0fba15
rpm-build 0fba15
echo "1..5"
rpm-build 0fba15
rpm-build 0fba15
cd ${test_tmpdir}
rpm-build 0fba15
mkdir repo
rpm-build 0fba15
ostree_repo_init repo --collection-id org.example.Collection1
rpm-build 0fba15
rpm-build 0fba15
mkdir -p tree/root
rpm-build 0fba15
touch tree/root/a
rpm-build 0fba15
rpm-build 0fba15
# Add a few commits
rpm-build 0fba15
seq 5 | while read i; do
rpm-build 0fba15
    echo a >> tree/root/a
rpm-build 0fba15
    ${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
rpm-build 0fba15
done
rpm-build 0fba15
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=repo summary --update --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}"
rpm-build 0fba15
rpm-build 0fba15
# Pull into a ‘local’ repository, to more accurately represent the situation of
rpm-build 0fba15
# creating a USB stick from your local machine.
rpm-build 0fba15
mkdir local-repo
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo init
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo remote add remote1 file://$(pwd)/repo --collection-id org.example.Collection1 --gpg-import="${test_tmpdir}/gpghome/key1.asc"
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo pull remote1 test-1 test-2 test-3 test-4 test-5
rpm-build 0fba15
rpm-build 0fba15
# Simple test to put two refs onto a USB stick.
rpm-build 0fba15
mkdir dest-mount1
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo create-usb dest-mount1 org.example.Collection1 test-1 org.example.Collection1 test-2
rpm-build 0fba15
rpm-build 0fba15
assert_has_dir dest-mount1/.ostree/repo
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=dest-mount1/.ostree/repo refs --collections > dest-refs
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-1)$"
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-2)$"
rpm-build 0fba15
assert_not_file_has_content dest-refs "^(org\.example\.Collection1, test-3)$"
rpm-build 0fba15
assert_has_file dest-mount1/.ostree/repo/summary
rpm-build 0fba15
rpm-build 0fba15
echo "ok 1 simple usb"
rpm-build 0fba15
rpm-build 0fba15
# Test that the repository can be placed in another standard location on the USB stick.
rpm-build 0fba15
for dest in ostree/repo .ostree/repo; do
rpm-build 0fba15
    rm -rf dest-mount2
rpm-build 0fba15
    mkdir dest-mount2
rpm-build 0fba15
    ${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo "$dest" dest-mount2 org.example.Collection1 test-1
rpm-build 0fba15
    assert_has_dir "dest-mount2/$dest"
rpm-build 0fba15
    if [ -d dest-mount2/.ostree/repos.d ]; then
rpm-build 0fba15
        ls dest-mount2/.ostree/repos.d | wc -l > repo-links
rpm-build 0fba15
        assert_file_has_content repo-links "^0$"
rpm-build 0fba15
    fi
rpm-build 0fba15
done
rpm-build 0fba15
rpm-build 0fba15
echo "ok 2 usb in standard location"
rpm-build 0fba15
rpm-build 0fba15
# Test that the repository can be placed in a non-standard location and gets a symlink to it.
rpm-build 0fba15
mkdir dest-mount3
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo some-dest dest-mount3 org.example.Collection1 test-1
rpm-build 0fba15
assert_has_dir "dest-mount3/some-dest"
rpm-build 0fba15
assert_symlink_has_content "dest-mount3/.ostree/repos.d/00-generated" "/some-dest$"
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=dest-mount3/.ostree/repos.d/00-generated refs --collections > dest-refs
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-1)$"
rpm-build 0fba15
assert_has_file dest-mount3/.ostree/repos.d/00-generated/summary
rpm-build 0fba15
rpm-build 0fba15
echo "ok 3 usb in non-standard location"
rpm-build 0fba15
rpm-build 0fba15
# Test that adding an additional ref to an existing USB repository works.
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=local-repo create-usb --destination-repo some-dest dest-mount3 org.example.Collection1 test-2 org.example.Collection1 test-3
rpm-build 0fba15
assert_has_dir "dest-mount3/some-dest"
rpm-build 0fba15
assert_symlink_has_content "dest-mount3/.ostree/repos.d/00-generated" "/some-dest$"
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=dest-mount3/.ostree/repos.d/00-generated refs --collections > dest-refs
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-1)$"
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-2)$"
rpm-build 0fba15
assert_file_has_content dest-refs "^(org\.example\.Collection1, test-3)$"
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=dest-mount3/.ostree/repos.d/00-generated summary -v > dest-summary
rpm-build 0fba15
assert_file_has_content dest-summary "(org\.example\.Collection1, test-1)$"
rpm-build 0fba15
assert_file_has_content dest-summary "(org\.example\.Collection1, test-2)$"
rpm-build 0fba15
assert_file_has_content dest-summary "(org\.example\.Collection1, test-3)$"
rpm-build 0fba15
rpm-build 0fba15
echo "ok 4 adding ref to an existing usb"
rpm-build 0fba15
rpm-build 0fba15
# Check that #OstreeRepoFinderMount works from a volume initialised uing create-usb.
rpm-build 0fba15
mkdir finder-repo
rpm-build 0fba15
ostree_repo_init finder-repo
rpm-build 0fba15
${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"
rpm-build 0fba15
rpm-build 0fba15
${test_builddir}/repo-finder-mount finder-repo dest-mount1 org.example.Collection1 test-1 org.example.Collection1 test-2 &> out
rpm-build 0fba15
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)$"
rpm-build 0fba15
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)$"
rpm-build 0fba15
rpm-build 0fba15
echo "ok 5 find from usb repo"