added file_to_zip.sh
This commit is contained in:
+2
-2
@@ -26,11 +26,11 @@ TARGET="$(
|
||||
readonly TARGET
|
||||
|
||||
## test vars
|
||||
if test -f "${SOURCE}"; then
|
||||
if ! test -f "${SOURCE}"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -d "${TARGET}"; then
|
||||
if ! test -d "${TARGET}"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
## usage
|
||||
USAGE="USAGE:
|
||||
$(basename "$0") source_file dest_dir"
|
||||
readonly USAGE
|
||||
|
||||
function help_message() {
|
||||
printf "%s\n" "$USAGE"
|
||||
}
|
||||
|
||||
## check parameters
|
||||
if [ "$#" -ne 2 ]; then
|
||||
help_message
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## vars
|
||||
SOURCE=$1
|
||||
readonly SOURCE
|
||||
|
||||
TARGET="$(
|
||||
cd -- "$2" >/dev/null 2>&1 || exit
|
||||
pwd -P
|
||||
)"
|
||||
readonly TARGET
|
||||
|
||||
## test vars
|
||||
if ! test -f "${SOURCE}"; then
|
||||
printf "%s\n" "${SOURCE} file does not exist"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! test -d "${TARGET}"; then
|
||||
printf "%s\n" "${TARGET} path does not exist"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## create zip file
|
||||
NAME=$(basename "${SOURCE}")
|
||||
printf "%s\n" "7z a -tzip -mx=9 "${TARGET}"/"${NAME}".zip "${SOURCE}""
|
||||
7z a -tzip -mx=9 "${TARGET}"/"${NAME}".zip "${SOURCE}"
|
||||
Reference in New Issue
Block a user