I have the following method and I need it to read a directory containing 3 or more subdirectories and generate a selinux context txt file separated by the name of each folder:
[bash]
#!/bin/bash
dirprev=$PWD
extracted_dir=$1
file_context=$2
partition=${extracted_dir##*/}
IFS=$'n'
echo "Checking fs config..."
echo ""
cd $extracted_dir
for i in $(find .); do
j=${i:2}
if [[ ! $(grep -rF "$partition/$j" $file_context) ]]; then
test -f $extracted_dir/$j
if [[ $? == 0 ]]; then
if [[ $(echo /$j | grep "/bin/") ]]; then
echo $partition/$j 0 2000 0755 >> $file_context
else
echo $partition/$j 0 0 0644 >> $file_context
fi
else
echo $partition/$j 0 0 0755 >> $file_context
fi
fi
done
cd $dirprev
eg:
folders
myfolder
....product_a -> product_a_file_context with all files builtin
....system_a -> system_a_file_context with all files builtin
....system_ext_a system_ext_a_file_context with all files builtin
each context file must only contain files from its directory
For files or folders that have a dot in the name, it needs to be generated as follows
files structure:
**original path: ./product_a/app/com.google.medatada
product_a_file_context: /product_a/app/com.google.metadata**
and saved in the corresponding text file of each folder
2