Hello!
The goal is to remove unnecessary files after creating a VM.
E.g. /etc/one-contex.d/*
with all files in this directory and /tmp/one-context-tmp
I’ve tried using self-deleting scripts & directories with bash scripting.
For example:
(script file via context)
#!/bin/bash
one_dir=/etc/one-context.d
currentscript=$0
currentdir=$PWD
rpm -e one-context-4.10.0-1.noarch
rm -rf $one_dir
export currentdir
function finish {
echo "shredding ${currentscript}"
shred -u ${currentscript};
if [ "$(ls -A ${currentdir})" ]; then
echo "${currentdir} is not empty!"
else
echo "${currentdir} is empty, removing!"
rmdir ${currentdir};
fi
}
trap finish EXIT
echo "exiting script"
Also i try to remove with $0 each script, but there are problem with stat, because such of them run later then another, and
How i can safetly delete this files after instantiate VM?