]> git.ipfire.org Git - people/ms/network.git/commitdiff
util: add new function copy
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 19 Jul 2017 08:09:44 +0000 (10:09 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Jul 2017 17:09:06 +0000 (19:09 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.util

index 381208cfd4ccd2d7f48029b865c2b39901a16edb..8c8f569179db086088273de0b6631a9a233b33d0 100644 (file)
@@ -752,3 +752,22 @@ hex2dec() {
 dec2hex() {
        printf "%02x\n" "${1}"
 }
+
+copy() {
+       # This function just copy config files
+       assert [ $# -eq 2 ]
+
+       local src=${1}
+       local dst=${2}
+
+       # Check if ${dst} is a directory
+       if [ -d ${dst} ]; then
+               log ERROR "${dst} is a directory."
+               return ${EXIT_ERROR}
+       fi
+
+       if ! fread "${src}" > "${dst}"; then
+               log ERROR "Could not copy data from ${src} to ${dst}"
+               return ${EXIT_ERROR}
+       fi
+}