#!/bin/bash

chsmack=/usr/sbin/chsmack
load=/usr/sbin/spcackload
tos_label="tos"-$(cat /etc/spcack/label)
data="data"-$(cat /etc/spcack/label)

chsmack -e "root" /usr/bin/find
echo "$tos_label $data rwxlta" | $load
directories=$(find "/" -maxdepth 1 -mindepth 1 -type d -name "Volume*")

protect_data() {
    for dir in $directories; do
        $chsmack -a "$data" -t $dir > /dev/null 2>&1
        $chsmack -a "$data" -t $dir/@apps > /dev/null 2>&1
        sub_dir=$(find $dir -maxdepth 1 | grep -v '/@apps$' | grep -v '/Volume.$')
        echo $sub_dir

        for d in $sub_dir; do
                $chsmack -A $d
                $chsmack -a "$data" -t -r $d > /dev/null 2>&1
        done
    done
}

protect_data
chsmack -e $tos_label /usr/bin/find
