Files
shadow/tests/common/config.sh
Alejandro Colomar 093fb605f9 lib: Merge libmisc into libshadow
The separation was unnecessary, and caused build problems.  Let's go
wild and obliterate the library.  The files are moved to libshadow.

Scripted change:

$ find libmisc/ -type f \
| grep '\.[chy]$' \
| xargs mv -t lib;

Plus updating the Makefile and other references.  While at it, I've
sorted the sources lists.

Link: <https://github.com/shadow-maint/shadow/pull/792>
Reported-by: David Seifert <soap@gentoo.org>
Cc: Sam James <sam@gentoo.org>
Cc: Christian Bricart <christian@bricart.de>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Robert Förster <Dessa@gmake.de>
[ soap tested the Gentoo package ]
Tested-by: David Seifert <soap@gentoo.org>
Acked-by: David Seifert <soap@gentoo.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-08-31 08:55:26 +02:00

133 lines
2.9 KiB
Bash

# Generic functions to save, change, and restore configuration files
set -e
build_path=$(pwd)
while [ "${build_path}" != "/" -a ! -e "${build_path}/.git" ]; do
build_path=$(dirname ${build_path})
done
if [ ! -e "${build_path}/.git" ]; then
echo "Not inside git directory" 1>&2
exit 1
fi
# Save the configuration files in tmp.
save_config ()
{
[ ! -d tmp ] && mkdir tmp
find config -depth -type f -print | sed -e 's/config\///' |
while read file
do
mkdir -p "tmp/$(dirname "$file")"
[ -f "/$file" ] && cp -dp "/$file" "tmp/$file" || true
done
# remove some things which can mess up PATH for some of our tests
# on github runners
mkdir -p "tmp/root"
cp -dp /root/.bashrc tmp/root/.bashrc
cp -dp /root/.profile tmp/root/.profile
sed -i '/pipx/d' /root/.bashrc /root/.profile
sed -i '/etc\/skel\/.cargo\/env/d' /root/.bashrc /root/.profile
}
# Copy the config files from config to the system
change_config ()
{
find config -depth -type f -print | sed -e 's/config\///' |
while read file
do
cp -f "config/$file" "/$file"
done
}
# Restored the config files in the system.
# The config files must be saved before with save_config ().
restore_config ()
{
find config -depth -type f -print | sed -e 's/config\///' |
while read file
do
if [ -f "tmp/$file" ]; then
cp -dp "tmp/$file" "/$file"
rm "tmp/$file"
else
rm -f "/$file"
fi
d="$(dirname "tmp/$file")"
while [ -n "$d" ] && [ "$d" != "." ]
do
rmdir "$d" 2>/dev/null || true
d="$(dirname "$d")"
done
done
rmdir tmp 2>/dev/null || true
}
prepare_chroot ()
{
mkdir tmp/root
cp -rfdp config_chroot/* tmp/root/
lists=/root/tests/common/config_chroot.list
[ -f config_chroot.list ] && lists="$lists config_chroot.list"
cat $lists | grep -v "#" | while read f
do
# Create parent directory if needed
d=$(dirname tmp/root/$f)
[ -d $d ] || mkdir -p $d
# Create hard link
ln $f tmp/root/$f
done
# Copy existing gcda
mkdir -p tmp/root$build_path/lib
mkdir -p tmp/root$build_path/src
find "$build_path" -name "*.gcda" | while read f
do
ln $f tmp/root/$f
done
}
clean_chroot ()
{
# Remove copied files
lists=/root/tests/common/config_chroot.list
[ -f config_chroot.list ] && lists="$lists config_chroot.list"
cat $lists | grep -v "#" | while read f
do
rm -f tmp/root/$f
# Remove parent directory if empty
d=$(dirname tmp/root/$f)
rmdir -p --ignore-fail-on-non-empty $d
done
find "$build_path" -name "*.gcda" | while read f
do
rm -f tmp/root/$f
done
find tmp/root -name "*.gcda" | while read f
do
g=${f#tmp/root}
mv "$f" "$g"
done
rmdir tmp/root$build_path/lib
rmdir tmp/root$build_path/src
rmdir tmp/root$build_path
rmdir tmp/root/root/build
rmdir tmp/root/root
find config_chroot -type f | while read f
do
f=${f#config_chroot/}
rm -f tmp/root/$f
done
find config_chroot -depth -type d | while read d
do
d=${d#config_chroot}
[ -d "tmp/root$d" ] && rmdir tmp/root$d
done
}