summaryrefslogtreecommitdiffhomepage
path: root/subr/ex_rtl_fileop.subr
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-11-22 01:32:50 +0000
committerLucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de>2017-11-22 02:35:10 +0000
commit32ad217d197203a97dfcc0076e748731d2315c0b (patch)
tree1f4dd5799daa9ac8540cddcc45b4c1557cb0ac70 /subr/ex_rtl_fileop.subr
parent465073d1a9f8ead60dbe66a26b55c0c1927e63c6 (diff)
downloadmidipix_build-32ad217d197203a97dfcc0076e748731d2315c0b.tar.bz2
midipix_build-32ad217d197203a97dfcc0076e748731d2315c0b.tar.xz
subr/*: reorganised as {ex{,_{pkg,rtl,setup}},pkg}_*.
Diffstat (limited to 'subr/ex_rtl_fileop.subr')
-rw-r--r--subr/ex_rtl_fileop.subr39
1 files changed, 39 insertions, 0 deletions
diff --git a/subr/ex_rtl_fileop.subr b/subr/ex_rtl_fileop.subr
new file mode 100644
index 00000000..3732ab5e
--- /dev/null
+++ b/subr/ex_rtl_fileop.subr
@@ -0,0 +1,39 @@
+#
+# set -o errexit -o noglob are assumed.
+#
+
+ex_build_fileop() {
+ local _op="${1}"; shift;
+ if [ "${_op}" = cd ]; then
+ ex_log_msg varn "Changing working directory to \`${1}'.";
+ [ \( -n "${1}" \) -a \( -L "${1}" -o -e "${1}" \) ] && cd -- "${1}";
+ elif [ "${_op}" = cp ]; then
+ ex_log_msg varn "Copying \`${1}' to \`${2}' w/ -pPR.";
+ [ ${#} -ge 2 ] && cp -pPR -- "${@}";
+ elif [ "${_op}" = ln_symbolic ]; then
+ ex_log_msg varn "Linking \`${1}' to \`${2}' w/ -fs";
+ [ \( -n "${1}" \) -a \( -n "${2}" \) ] && ln -fs -- "${1}" "${2}";
+ elif [ "${_op}" = mv ]; then
+ ex_log_msg varn "Moving \`${1}' to \`${2}' w/ -fs";
+ [ \( -n "${1}" \) -a \( -n "${2}" \) ] && mv -f -- "${1}" "${2}";
+ elif [ "${_op}" = mkdir ]\
+ || [ "${_op}" = rm ]; then
+ while [ ${#} -gt 0 ]; do
+ if [ -z "${1}" ]; then
+ return 1;
+ elif [ "${_op}" = mkdir ]\
+ && [ ! -e "${1}" ]; then
+ ex_log_msg varn "Making directory \`${1}'.";
+ mkdir -p -- "${1}";
+ elif [ "${_op}" = rm ]\
+ && [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then
+ ex_log_msg varn "Removing directory or file \`${1}'.";
+ rm -rf -- "${1}";
+ fi; shift;
+ done;
+ else
+ ex_log_msg failexit "Error: ex_build_fileop() called w/ invalid parameter(s) \`${@}'.";
+ fi;
+};
+
+# vim:filetype=sh