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:
#!/bin/bash
dirprev=$PWD
extracted_dir=$1
fs_config=$2
partition=${extracted_dir##*/}
IFS=
eg:
folders product_a system_a system_ext_a
file context:
myfolder - root folder product_a_file_context system_a_file_context system_ext_a_file context
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 context: /product_a/app/com.\google.\metadata
and saved in the corresponding text file of each folder\n’
echo “Checking fs config…”
echo “”
cd $extracted_dir
for i in $(find .); do
j=${i:2}
if [[ ! $(grep -rF “$partition/$j” $fs_config) ]]; then
test -f $extracted_dir/$j
if [[ $? == 0 ]]; then
if [[ $(echo /$j | grep “/bin/”) ]]; then
echo $partition/$j 0 2000 0755 >> $fs_config
else
echo $partition/$j 0 0 0644 >> $fs_config
fi
else
echo $partition/$j 0 0 0755 >> $fs_config
fi
fi
done
cd $dirprev
eg:
folders product_a system_a system_ext_a
file context:
myfolder - root folder product_a_file_context system_a_file_context system_ext_a_file context
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 context: /product_a/app/com.\google.\metadata
and saved in the corresponding text file of each folder