printf -- "${fmt}\n" "$@"
}
+print_indent() {
+ local i=${1}
+ shift
+
+ while (( i-- )); do
+ printf "\t"
+ done
+
+ print "%s" "$@"
+}
+
# The args() function takes a number of arguments like
# var1="abc d" var2="abc" var3="abcd e"
# and splits them into several arguments, devided by newline
assert isset file
shift
- if [ ! -w "${file}" ]; then
+ if [ -e "${file}" ] && [ ! -w "${file}" ]; then
log ERROR "${file}: No such file"
return ${EXIT_ERROR}
fi
print "%s" "$@" >> ${file} 2>/dev/null
}
+file_exists() {
+ local file=${1}
+
+ [ -e "${file}" ] && return ${EXIT_TRUE} || return ${EXIT_FALSE}
+}
+
+file_is_newer_than() {
+ local file1="${1}"
+ local file2="${2}"
+
+ local age1=$(file_get_age "${file1}")
+ local age2=$(file_get_age "${file2}")
+
+ if [ ${age1} -gt ${age2} ]; then
+ return ${EXIT_TRUE}
+ else
+ return ${EXIT_FALSE}
+ fi
+}
+
+file_get_age() {
+ local file="${1}"
+
+ if [ -e "${file}" ]; then
+ stat --format="%Y" "${file}"
+ return $?
+ fi
+
+ return ${EXIT_ERROR}
+}
+
make_parent_dir() {
local path="${1}"
log DEBUG "Running command: ${cmd}"
- ${cmd}
- local ret=$?
+ if ! ${cmd}; then
+ local ret=$?
- log DEBUG "Returned with code '${ret}'"
+ log DEBUG "Returned with code '${ret}'"
+ return ${ret}
+ fi
- return ${ret}
+ return ${EXIT_OK}
}
cmd_quiet() {
return ${EXIT_FALSE}
}
+string_match() {
+ local match=${1}
+ local string=${2}
+
+ [[ ${string} =~ ${match} ]] && return ${EXIT_TRUE} || return ${EXIT_FALSE}
+}
+
string_split() {
local string="$@"
printf "%02x\n" "${1}"
}
+# This function just copy config files
copy() {
- # This function just copy config files
assert [ $# -eq 2 ]
local src=${1}
local dst=${2}
+ # Check if we can read from the source
+ if [ ! -r "${src}" ]; then
+ log ERROR "Cannot read ${src}"
+ return ${EXIT_ERROR}
+ fi
+
# Check if ${dst} is a directory
if [ -d "${dst}" ]; then
- log ERROR "${dst} is a directory."
+ log ERROR "${dst} is a directory"
return ${EXIT_ERROR}
fi