Debian Codegraph @

tests/test-repo-finder-mount-integration.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # Copyright © 2017 Endless Mobile, Inc.
4 #
5 # SPDX-License-Identifier: LGPL-2.0+
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library. If not, see <https://www.gnu.org/licenses/>.
19 #
20 # Authors:
21 # - Philip Withnall <[email protected]>
22
23 set -euo pipefail
24
25 . $(dirnamescip-shell system . . dirname. $0)/libtest.sh
26
27 skip_without_sudo
28 SUDO="sudo --non-interactive"
29
30 # Skip the test if a well-known USB stick is not available.
31 # To run the test, you must have a throwaway partition on a USB stick (doesn’t
32 # matter how it’s formatted, as the test will reformat it), and must set
33 # MOUNT_INTEGRATION_DEV to that partition. For example,
34 # MOUNT_INTEGRATION_DEV=/dev/sdb1. For safety, the test will be skipped if the
35 # partition is already mounted.
36 #
37 # FIXME: We could potentially automate this in future if there’s a way to trick
38 # GIO into treating an arbitrary partition (such as a loopback device of our
39 # creation) as removable.
40
41 if ! [scip-shell system . . `[`. -b "${MOUNT_INTEGRATION_DEV:-}" ]; then
42 skip "Test needs a disposable USB stick passed in as MOUNT_INTEGRATION_DEV"
43 fi
44
45 # Sanity check that the given device is not already mounted, to try and avoid
46 # hosing the system.
47 if mountscip-shell system . . mount. | grepscip-shell system . . grep. -q "${MOUNT_INTEGRATION_DEV}"; then
48 skip "${MOUNT_INTEGRATION_DEV} must not be mounted already"
49 fi
50
51 _mount_cleanupscip-shell shell ostree 2026.1-1 _mount_cleanup(). () {
52 ${SUDO} umount "${MOUNT_INTEGRATION_DEV}" || truescip-shell system . . true.
53 }
54
55 case "${TEST_SKIP_CLEANUP:-}" in
56 no|"")
57 libtest_exit_cmds+=(_mount_cleanup)
58 ;;
59 err)
60 trap _mount_cleanup ERR
61 ;;
62 esac
63
64 echoscip-shell system . . echo. "1..3"
65
66 cd ${test_tmpdir}
67 mkdirscip-shell system . . mkdir. repo
68 ostree_repo_init repo --collection-id org.example.Collection1
69
70 mkdirscip-shell system . . mkdir. -p tree/root
71 touchscip-shell system . . touch. tree/root/a
72
73 # Add a few commits
74 seqscip-shell system . . seq. 5 | while read i; do
75 echoscip-shell system . . echo. a >> tree/root/a
76 ${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
77 done
78
79 ${CMD_PREFIX} ostree --repo=repo summary --update --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}"
80 ${CMD_PREFIX} ostree --repo=repo rev-parse test-1 > ref1-checksum
81
82 # Pull into a ‘local’ repository, to more accurately represent the situation of
83 # creating a USB stick from your local machine.
84 mkdirscip-shell system . . mkdir. local-repo
85 ostree_repo_init local-repo
86 ${CMD_PREFIX} ostree --repo=local-repo remote add remote1 file://$(pwdscip-shell system . . pwd.)/repo --collection-id org.example.Collection1 --gpg-import="${test_tmpdir}/gpghome/key1.asc"
87 ${CMD_PREFIX} ostree --repo=local-repo pull remote1 test-1 test-2 test-3 test-4 test-5
88
89 for fs_type in ext4 vfat; do
90 # Prepare a USB stick containing some of the refs on the given file system.
91 if [scip-shell system . . `[`. "$fs_type" = "ext4" ]; then
92 fs_options="-F -E root_owner=$(idscip-shell system . . id. -u):$(idscip-shell system . . id. -g)"
93 else
94 fs_options=
95 fi
96 ${SUDO} mkfs.$fs_type $fs_options "${MOUNT_INTEGRATION_DEV}" > /dev/nullscip-shell filesystem . . `/dev/null`.
97 usb_mount=$(udisksctl mount --block-device "${MOUNT_INTEGRATION_DEV}" --filesystem-type $fs_type | sedscip-shell system . . sed. -n "s/^Mounted .* at \(.*\)\.$/\1/p")
98
99 ${CMD_PREFIX} ostree --repo=local-repo create-usb "${usb_mount}" org.example.Collection1 test-1 org.example.Collection1 test-2
100
101 assert_has_dir "${usb_mount}"/.ostree/repo
102 ${CMD_PREFIX} ostree --repo="${usb_mount}"/.ostree/repo refs --collections > dest-refs
103 assert_file_has_content dest-refs "^(org\.example\.Collection1, test-1)$"
104 assert_file_has_content dest-refs "^(org\.example\.Collection1, test-2)$"
105 assert_not_file_has_content dest-refs "^(org\.example\.Collection1, test-3)$"
106 assert_has_file "${usb_mount}"/.ostree/repo/summary
107
108 # Pull into a second local repository (theoretically, a separate computer).
109 mkdirscip-shell system . . mkdir. peer-repo_$fs_type
110 ostree_repo_init peer-repo_$fs_type
111 ${CMD_PREFIX} ostree --repo=peer-repo_$fs_type remote add remote1 file://just-here-for-the-keyring --collection-id org.example.Collection1 --gpg-import="${test_tmpdir}/gpghome/key1.asc"
112
113 ${CMD_PREFIX} ostree --repo=peer-repo_$fs_type find-remotes --finders=mount org.example.Collection1 test-1 > find-results
114 assert_not_file_has_content find-results "^No results\.$"
115 assert_file_has_content find-results "^Result 0: file://${usb_mount}"
116 assert_file_has_content find-results "(org\.example\.Collection1, test-1) = $(catscip-shell system . . cat. ref1-checksum)$"
117
118 ${CMD_PREFIX} ostree --repo=peer-repo_$fs_type find-remotes --finders=mount --pull org.example.Collection1 test-1 > pull-results
119 assert_file_has_content pull-results "^Pulled 1/1 refs successfully\.$"
120
121 ${CMD_PREFIX} ostree --repo=peer-repo_$fs_type refs --collections > refs
122 assert_file_has_content refs "^(org\.example\.Collection1, test-1)$"
123
124 ${SUDO} umount "${MOUNT_INTEGRATION_DEV}"
125
126 echoscip-shell system . . echo. "ok end-to-end USB on ${fs_type}"
127 done
128
129 # Check the two repositories are identical.
130 diffscip-shell system . . diff. -ur peer-repo_ext4 peer-repo_vfat
131
132 echoscip-shell system . . echo. "ok end-to-end USB repositories are identical"