Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/ex_rtl_fileop.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_build_fileop() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _op="${1}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	if [ "${_op}" = cd ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg varn "Changing working directory to \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		[ \( -n "${1}" \) -a \( -L "${1}" -o -e "${1}" \) ] && cd -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	elif [ "${_op}" = cp ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg varn "Copying \`${1}' to \`${2}' w/ -pPR.";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		[ ${#} -ge 2 ] && cp -pPR -- "${@}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	elif [ "${_op}" = ln_symbolic ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg varn "Linking \`${1}' to \`${2}' w/ -fs";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		[ \( -n "${1}" \) -a \( -n "${2}" \) ] && ln -fs -- "${1}" "${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	elif [ "${_op}" = mv ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg varn "Moving \`${1}' to \`${2}' w/ -fs";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		[ \( -n "${1}" \) -a \( -n "${2}" \) ] && mv -f -- "${1}" "${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	elif [ "${_op}" = mkdir ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	||   [ "${_op}" = rm ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			if [ -z "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			elif [ "${_op}" = mkdir ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			&&   [ ! -e "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				ex_log_msg varn "Making directory \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				mkdir -p -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			elif [ "${_op}" = rm ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			&&   [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				ex_log_msg varn "Removing directory or file \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				rm -rf -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg failexit "Error: ex_build_fileop() called w/ invalid parameter(s) \`${@}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# vim:filetype=sh