2013-11-19 04:47:46 +04:00
#!/bin/bash
#
# Copyright (C) 2013 Colin Walters <walters@verbum.org>
#
2018-01-30 22:26:26 +03:00
# SPDX-License-Identifier: LGPL-2.0+
#
2013-11-19 04:47:46 +04:00
# 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.
2016-01-27 19:44:10 +03:00
set -euo pipefail
2013-11-19 04:47:46 +04:00
. $( dirname $0 ) /libtest.sh
2015-07-14 20:30:05 +03:00
# Exports OSTREE_SYSROOT so --sysroot not needed.
2017-09-01 23:15:33 +03:00
setup_os_repository "archive" "syslinux"
2013-11-19 04:47:46 +04:00
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo pull-local --remote= testos testos-repo testos/buildmain/x86_64-runtime
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2013-11-19 04:47:46 +04:00
export rev
echo " rev= ${ rev } "
# This initial deployment gets kicked off with some kernel arguments
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree admin deploy --karg= root = LABEL = MOO --karg= quiet --os= testos testos:testos/buildmain/x86_64-runtime
2013-11-19 04:47:46 +04:00
assert_has_dir sysroot/boot/ostree/testos-${ bootcsum }
etc = sysroot/ostree/deploy/testos/deploy/${ rev } .0/etc
2014-09-15 17:29:26 +04:00
# modified config file
echo "a modified config file" > ${ etc } /NetworkManager/nm.conf
# Ok, let's create a long directory chain with custom permissions
2013-11-19 04:47:46 +04:00
mkdir -p ${ etc } /a/long/dir/chain
mkdir -p ${ etc } /a/long/dir/forking
chmod 700 ${ etc } /a
chmod 770 ${ etc } /a/long
chmod 777 ${ etc } /a/long/dir
chmod 707 ${ etc } /a/long/dir/chain
chmod 700 ${ etc } /a/long/dir/forking
2014-09-15 17:29:26 +04:00
# Symlink to nonexistent path, to ensure we aren't walking symlinks
ln -s no-such-file ${ etc } /a/link-to-no-such-file
2021-09-30 22:53:18 +03:00
# fifo which should be ignored
mkfifo " ${ etc } /fifo-to-ignore "
2014-09-15 17:29:26 +04:00
# Remove a directory
rm ${ etc } /testdirectory -rf
2013-11-19 04:47:46 +04:00
# Now deploy a new commit
os_repository_new_commit
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo remote add --set= gpg-verify= false testos file://$( pwd ) /testos-repo testos/buildmain/x86_64-runtime
2015-07-14 20:30:05 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2021-05-07 17:42:37 +03:00
newrev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2013-11-19 04:47:46 +04:00
echo " newrev= ${ newrev } "
2014-09-15 17:29:26 +04:00
newroot = sysroot/ostree/deploy/testos/deploy/${ newrev } .0
newetc = ${ newroot } /etc
assert_file_has_content ${ newroot } /usr/etc/NetworkManager/nm.conf "a default daemon file"
assert_file_has_content ${ newetc } /NetworkManager/nm.conf "a modified config file"
2013-11-19 04:47:46 +04:00
2021-09-30 22:53:18 +03:00
if test -e " ${ newetc } " /fifo-to-ignore; then
fatal "Should not have copied fifo!"
fi
2013-11-19 04:47:46 +04:00
assert_file_has_mode( ) {
stat -c '%a' $1 > mode.txt
if ! grep -q -e " $2 " mode.txt; then
echo 1>& 2 " file $1 has mode $( cat mode.txt) ; expected $2 " ;
exit 1
fi
rm -f mode.txt
}
2014-09-15 17:29:26 +04:00
2013-11-19 04:47:46 +04:00
assert_file_has_mode ${ newetc } /a 700
assert_file_has_mode ${ newetc } /a/long 770
assert_file_has_mode ${ newetc } /a/long/dir 777
assert_file_has_mode ${ newetc } /a/long/dir/chain 707
assert_file_has_mode ${ newetc } /a/long/dir/forking 700
assert_file_has_mode ${ newetc } /a/long/dir 777
2014-09-15 17:29:26 +04:00
test -L ${ newetc } /a/link-to-no-such-file || assert_not_reached "should have symlink"
assert_has_dir ${ newroot } /usr/etc/testdirectory
assert_not_has_dir ${ newetc } /testdirectory
2021-09-11 00:07:42 +03:00
tap_ok first
2014-06-19 23:53:20 +04:00
# Add /etc/initially-empty
cd " ${ test_tmpdir } /osdata "
mkdir -p usr/etc/initially-empty
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= ${ test_tmpdir } /testos-repo commit -b testos/buildmain/x86_64-runtime -s "Add empty directory"
2014-06-19 23:53:20 +04:00
cd ${ test_tmpdir }
# Upgrade, check that we have it
2015-07-14 20:30:05 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2021-05-07 17:42:37 +03:00
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2014-06-19 23:53:20 +04:00
assert_has_dir sysroot/ostree/deploy/testos/deploy/$rev .0/etc/initially-empty
# Now add a two files in initially-empty
cd " ${ test_tmpdir } /osdata "
touch usr/etc/initially-empty/{ afile,bfile}
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= ${ test_tmpdir } /testos-repo commit -b testos/buildmain/x86_64-runtime -s "Add empty directory"
2014-06-19 23:53:20 +04:00
# Upgrade, check that we have the two new files
cd ${ test_tmpdir }
2015-07-14 20:30:05 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2021-05-07 17:42:37 +03:00
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2014-06-19 23:53:20 +04:00
assert_has_file sysroot/ostree/deploy/testos/deploy/$rev .0/etc/initially-empty/afile
assert_has_file sysroot/ostree/deploy/testos/deploy/$rev .0/etc/initially-empty/bfile
2014-09-13 18:36:59 +04:00
# Replace config file with default directory
cd " ${ test_tmpdir } /osdata "
mkdir usr/etc/somenewdir
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= ${ test_tmpdir } /testos-repo commit -b testos/buildmain/x86_64-runtime -s "Add default dir"
2014-09-13 18:36:59 +04:00
cd ${ test_tmpdir }
2021-05-07 17:42:37 +03:00
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2014-09-13 18:36:59 +04:00
newconfpath = sysroot/ostree/deploy/testos/deploy/${ rev } .0/etc/somenewdir
echo "some content blah" > ${ newconfpath }
2015-07-14 20:30:05 +03:00
if ${ CMD_PREFIX } ostree admin upgrade --os= testos 2>err.txt; then
2014-09-13 18:36:59 +04:00
assert_not_reached "upgrade should have failed"
fi
assert_file_has_content err.txt "Modified config file newly defaults to directory"
rm ${ newconfpath }
# Remove parent directory of modified config file
cd " ${ test_tmpdir } /osdata "
rm -rf usr/etc/initially-empty
2021-05-07 17:42:37 +03:00
${ CMD_PREFIX } ostree --repo= ${ test_tmpdir } /testos-repo commit -b testos/buildmain/x86_64-runtime -s "Remove default dir"
2014-09-13 18:36:59 +04:00
cd ${ test_tmpdir }
newconfpath = sysroot/ostree/deploy/testos/deploy/${ rev } .0/etc/initially-empty/mynewfile
touch ${ newconfpath }
2015-07-14 20:30:05 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2021-05-07 17:42:37 +03:00
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime)
2014-09-15 17:29:26 +04:00
assert_not_has_file sysroot/ostree/deploy/testos/deploy/${ rev } .0/usr/etc/initially-empty
assert_has_file sysroot/ostree/deploy/testos/deploy/${ rev } .0/etc/initially-empty/mynewfile
2014-09-13 18:36:59 +04:00
rm ${ newconfpath }
2021-09-11 00:07:42 +03:00
tap_ok second
tap_end