2014-09-18 01:12:55 +05:30
|
|
|
# Generic functions to save, change, and restore configuration files
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-04-25 21:12:41 +05:30
|
|
|
build_path=$(pwd)
|
2023-02-26 20:09:15 +05:30
|
|
|
while [ "${build_path}" != "/" -a ! -e "${build_path}/.git" ]; do
|
2022-04-25 21:12:41 +05:30
|
|
|
build_path=$(dirname ${build_path})
|
|
|
|
done
|
2023-02-26 20:09:15 +05:30
|
|
|
if [ ! -e "${build_path}/.git" ]; then
|
2022-04-25 21:12:41 +05:30
|
|
|
echo "Not inside git directory" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-09-18 01:12:55 +05:30
|
|
|
|
|
|
|
# Save the configuration files in tmp.
|
|
|
|
save_config ()
|
|
|
|
{
|
|
|
|
[ ! -d tmp ] && mkdir tmp
|
2020-04-25 03:11:34 +05:30
|
|
|
find config -depth -type f -print | sed -e 's/config\///' |
|
2014-09-18 01:12:55 +05:30
|
|
|
while read file
|
|
|
|
do
|
|
|
|
mkdir -p "tmp/$(dirname "$file")"
|
|
|
|
[ -f "/$file" ] && cp -dp "/$file" "tmp/$file" || true
|
|
|
|
done
|
2023-02-25 09:55:58 +05:30
|
|
|
# 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
|
2014-09-18 01:12:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the config files from config to the system
|
|
|
|
change_config ()
|
|
|
|
{
|
2020-04-25 03:11:34 +05:30
|
|
|
find config -depth -type f -print | sed -e 's/config\///' |
|
2014-09-18 01:12:55 +05:30
|
|
|
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 ()
|
|
|
|
{
|
2020-04-25 03:11:34 +05:30
|
|
|
find config -depth -type f -print | sed -e 's/config\///' |
|
2014-09-18 01:12:55 +05:30
|
|
|
while read file
|
|
|
|
do
|
|
|
|
if [ -f "tmp/$file" ]; then
|
|
|
|
cp -dp "tmp/$file" "/$file"
|
|
|
|
rm "tmp/$file"
|
|
|
|
else
|
2014-09-20 19:10:46 +05:30
|
|
|
rm -f "/$file"
|
2014-09-18 01:12:55 +05:30
|
|
|
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/libmisc
|
|
|
|
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/libmisc
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|