Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (77 sloc) 1.87 KB
find_dir_up() {
local name=$1;
local default="$2";
local required="$3";
if [ -d "./${name}" ]; then
echo "./${name}"; return 0;
else
local path="../${name}"
local loop=0;
local realpath;
while [ $loop -eq 0 ]; do
realpath="`readlink -f $path`";
if [ "${realpath}" == "/${name}" ]; then
loop=1;
fi;
if [ -d $path ]; then
if [[ -z $required || "$realpath" == */$required/* ]]; then
loop=1;
echo "${path}"; return;
fi;
fi;
path="../${path}"
done;
fi;
if [ -n $default ]; then
echo "$default";
fi;
}
detect_module_dir() {
find_dir_up 'modules' '/etc/puppet/modules'
}
detect_manifests_dir() {
find_dir_up 'manifests' "`pwd`" "modules"
}
detect_class_name() {
local name="$1"
local manifests="`find_dir_up 'manifests' '_FAILTRAIN_' 'modules'`";
if [[ "$manifests"x == '_FAILTRAIN_x' ]]; then
echo $name; return 0;
fi;
local manifests_path="`readlink -f $manifests`";
local modulename="`pwd | sed 's@.*/modules/\([^/]\+\)/manifests.*@\1@'`";
if [[ "${modulename}"x == `pwd`x ]]; then
echo "You are in the wrong folder! cd $manifests_path" 1>&2
return 13;
fi;
if `pwd | grep -q "${modulename}/manifests/.*"`; then
modulename=`pwd | sed -e "s@.*/modules/\([^/]\+\)/manifests/\(.*\)@\1::\2@" -e "s@/@::@g"`
fi;
if [ "$name"x == 'initx' ]; then
echo "${modulename}"
else
echo "${modulename}::${name}"
fi;
}
reformat_pp_file() {
if [ -f "$1" ]; then
pp_fix_tabs $1;
pp_strip_trailing_whitespaces $1;
pp_reformat_quotes $1;
else
echo "File '$1' not found.";
return 1;
fi
}
pp_fix_tabs() {
sed -i "s@\t@ @g" $1
}
pp_strip_trailing_whitespaces() {
sed -i "s@\s*\$@@g" $1
}
pp_reformat_quotes() {
local f=$1;
if [ -f $f ]; then
sed -i "s@^\([^']*\)\"\([^\"$]\+\)\"\([^']*\)\$@\1'\2'\3@g" $f;
fi;
}