1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# vim: filetype=sh
# this must be called by bash once, first
# (sh has no 'declare' command)
has_function() {
func_name="$1"
# check if we have the answer already
precomputed=$(eval "echo \$${func_name}_exists")
if [ -z "$precomputed" ]
then
if declare -f $func_name >/dev/null
then
echo true
else
echo false
fi
else
echo $precomputed
fi
}
setup_optional_function() {
func_name="$1"
if $(has_function $func_name)
then
eval "${func_name}_exists=true"
eval "optional_$func_name() { $func_name \$@; }"
else
eval "${func_name}_exists=false"
eval "optional_$func_name() { true; }"
fi
export "${func_name}_exists"
}
TARGET_OPTIONAL_FUNCTIONS="$(cat << EOF
target_preliminary_steps
target_final_customization_steps
target_prepare_rootfs
target_cleanup_rootfs
target_custom_packages
target_get_bootloader_install_command
target_get_vg_rename_command
EOF
)"
probe_target_optional_functions() {
for func in $TARGET_OPTIONAL_FUNCTIONS
do
setup_optional_function $func
done
}
|