Blame tests/test-admin-gpg.sh

rpm-build 0fba15
#!/bin/bash
rpm-build 0fba15
#
rpm-build 0fba15
# Copyright (C) 2019 Rafael Fonseca <r4f4rfs@gmail.com>
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
set -euo pipefail
rpm-build 0fba15
rpm-build 0fba15
. $(dirname $0)/libtest.sh
rpm-build 0fba15
rpm-build 0fba15
setup_os_repository_signed () {
rpm-build 0fba15
    mode=$1
rpm-build 0fba15
    shift
rpm-build 0fba15
    bootmode=$1
rpm-build 0fba15
    shift
rpm-build 0fba15
    bootdir=${1:-usr/lib/modules/3.6.0}
rpm-build 0fba15
rpm-build 0fba15
    oldpwd=`pwd`
rpm-build 0fba15
    keyid="472CDAFA"
rpm-build 0fba15
rpm-build 0fba15
    cd ${test_tmpdir}
rpm-build 0fba15
    mkdir testos-repo
rpm-build 0fba15
    if test -n "$mode"; then
rpm-build 0fba15
	      ostree_repo_init testos-repo --mode=${mode}
rpm-build 0fba15
    else
rpm-build 0fba15
	      ostree_repo_init testos-repo
rpm-build 0fba15
    fi
rpm-build 0fba15
rpm-build 0fba15
    cd ${test_tmpdir}
rpm-build 0fba15
    mkdir osdata
rpm-build 0fba15
    cd osdata
rpm-build 0fba15
    kver=3.6.0
rpm-build 0fba15
    mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc
rpm-build 0fba15
    kernel_path=${bootdir}/vmlinuz
rpm-build 0fba15
    initramfs_path=${bootdir}/initramfs.img
rpm-build 0fba15
    # /usr/lib/modules just uses "vmlinuz", since the version is in the module
rpm-build 0fba15
    # directory name.
rpm-build 0fba15
    if [[ $bootdir != usr/lib/modules/* ]]; then
rpm-build 0fba15
        kernel_path=${kernel_path}-${kver}
rpm-build 0fba15
        initramfs_path=${bootdir}/initramfs-${kver}.img
rpm-build 0fba15
    fi
rpm-build 0fba15
    echo "a kernel" > ${kernel_path}
rpm-build 0fba15
    echo "an initramfs" > ${initramfs_path}
rpm-build 0fba15
    bootcsum=$(cat ${kernel_path} ${initramfs_path} | sha256sum | cut -f 1 -d ' ')
rpm-build 0fba15
    export bootcsum
rpm-build 0fba15
    # Add the checksum for legacy dirs (/boot, /usr/lib/ostree-boot), but not
rpm-build 0fba15
    # /usr/lib/modules.
rpm-build 0fba15
    if [[ $bootdir != usr/lib/modules/* ]]; then
rpm-build 0fba15
        mv ${kernel_path}{,-${bootcsum}}
rpm-build 0fba15
        mv ${initramfs_path}{,-${bootcsum}}
rpm-build 0fba15
    fi
rpm-build 0fba15
rpm-build 0fba15
    echo "an executable" > usr/bin/sh
rpm-build 0fba15
    echo "some shared data" > usr/share/langs.txt
rpm-build 0fba15
    echo "a library" > usr/lib/libfoo.so.0
rpm-build 0fba15
    ln -s usr/bin bin
rpm-build 0fba15
cat > usr/etc/os-release <
rpm-build 0fba15
NAME=TestOS
rpm-build 0fba15
VERSION=42
rpm-build 0fba15
ID=testos
rpm-build 0fba15
VERSION_ID=42
rpm-build 0fba15
PRETTY_NAME="TestOS 42"
rpm-build 0fba15
EOF
rpm-build 0fba15
    echo "a config file" > usr/etc/aconfigfile
rpm-build 0fba15
    mkdir -p usr/etc/NetworkManager
rpm-build 0fba15
    echo "a default daemon file" > usr/etc/NetworkManager/nm.conf
rpm-build 0fba15
    mkdir -p usr/etc/testdirectory
rpm-build 0fba15
    echo "a default daemon file" > usr/etc/testdirectory/test
rpm-build 0fba15
rpm-build 0fba15
    ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.9 -b testos/buildmaster/x86_64-runtime -s "Build" --gpg-sign=$keyid --gpg-homedir=${test_tmpdir}/gpghome
rpm-build 0fba15
rpm-build 0fba15
    # Ensure these commits have distinct second timestamps
rpm-build 0fba15
    sleep 2
rpm-build 0fba15
    echo "a new executable" > usr/bin/sh
rpm-build 0fba15
    ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.10 -b testos/buildmaster/x86_64-runtime -s "Build" --gpg-sign=$keyid --gpg-homedir=${test_tmpdir}/gpghome
rpm-build 0fba15
rpm-build 0fba15
    cd ${test_tmpdir}
rpm-build 0fba15
    rm -rf osdata-devel
rpm-build 0fba15
    mkdir osdata-devel
rpm-build 0fba15
    tar -C osdata -cf - . | tar -C osdata-devel -xf -
rpm-build 0fba15
    cd osdata-devel
rpm-build 0fba15
    mkdir -p usr/include
rpm-build 0fba15
    echo "a development header" > usr/include/foo.h
rpm-build 0fba15
    ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.9 -b testos/buildmaster/x86_64-devel -s "Build" --gpg-sign=$keyid --gpg-homedir=${test_tmpdir}/gpghome
rpm-build 0fba15
rpm-build 0fba15
    ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo fsck -q
rpm-build 0fba15
rpm-build 0fba15
    cd ${test_tmpdir}
rpm-build 0fba15
    mkdir sysroot
rpm-build 0fba15
    export OSTREE_SYSROOT=sysroot
rpm-build 0fba15
    ${CMD_PREFIX} ostree admin init-fs sysroot
rpm-build 0fba15
    if test -n "${OSTREE_NO_XATTRS:-}"; then
rpm-build 0fba15
        echo -e 'disable-xattrs=true\n' >> sysroot/ostree/repo/config
rpm-build 0fba15
    fi
rpm-build 0fba15
    ${CMD_PREFIX} ostree admin os-init testos
rpm-build 0fba15
rpm-build 0fba15
    case $bootmode in
rpm-build 0fba15
        "syslinux")
rpm-build 0fba15
	    setup_os_boot_syslinux
rpm-build 0fba15
            ;;
rpm-build 0fba15
        "uboot")
rpm-build 0fba15
	    setup_os_boot_uboot
rpm-build 0fba15
            ;;
rpm-build 0fba15
        *grub2*)
rpm-build 0fba15
        setup_os_boot_grub2 "${bootmode}"
rpm-build 0fba15
            ;;
rpm-build 0fba15
    esac
rpm-build 0fba15
rpm-build 0fba15
    cd ${test_tmpdir}
rpm-build 0fba15
    mkdir ${test_tmpdir}/httpd
rpm-build 0fba15
    cd httpd
rpm-build 0fba15
    ln -s ${test_tmpdir} ostree
rpm-build 0fba15
    ${OSTREE_HTTPD} --autoexit --daemonize -p ${test_tmpdir}/httpd-port
rpm-build 0fba15
    port=$(cat ${test_tmpdir}/httpd-port)
rpm-build 0fba15
    echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
rpm-build 0fba15
    cd ${oldpwd}
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
# Exports OSTREE_SYSROOT so --sysroot not needed.
rpm-build 0fba15
setup_os_repository_signed "archive" "syslinux"
rpm-build 0fba15
rpm-build 0fba15
echo "1..2"
rpm-build 0fba15
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo remote add testos $(cat httpd-address)/ostree/testos-repo
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --gpg-verify=true --remote=testos testos-repo testos/buildmaster/x86_64-runtime
rpm-build 0fba15
# This initial deployment gets kicked off with some kernel arguments
rpm-build 0fba15
${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmaster/x86_64-runtime
rpm-build 0fba15
assert_has_dir sysroot/boot/ostree/testos-${bootcsum}
rpm-build 0fba15
rpm-build 0fba15
echo "ok deploy command"
rpm-build 0fba15
rpm-build 0fba15
${CMD_PREFIX} ostree admin status > status.txt
rpm-build 0fba15
test -f status.txt
rpm-build 0fba15
assert_file_has_content status.txt "GPG: Signature made"
rpm-build 0fba15
assert_not_file_has_content status.txt "GPG: Can't check signature: public key not found"
rpm-build 0fba15
echo 'ok gpg signature'