#!/bin/bash

modules_path="/software/modules"
output_file="/tmp/meta_modules.ls"

which timeout &>/dev/null
[ $? -gt 0 ] && exit 0

role=$([ -f /etc/facter/facts.d/puppet.yaml ] && echo $(grep "role" /etc/facter/facts.d/puppet.yaml | awk '{print $2}'))

[ -d $modules_path ] || [ "${role}x" == "computex" ] || exit 0

echo '<<<meta_modules>>>'

if [[ $(find "$output_file" -mmin +240 -print 2>&1) ]]; then
	timeout 60s ls -l $modules_path &>$output_file
fi

cat $output_file
