From ab4222c16adac2908a4ffb163b1f6252fae86ca5 Mon Sep 17 00:00:00 2001 From: Sergio Date: Sat, 21 May 2022 19:42:00 +0200 Subject: [PATCH] added file_to_zip.sh --- file_to_link.sh | 4 ++-- file_to_zip.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 file_to_zip.sh diff --git a/file_to_link.sh b/file_to_link.sh index 319bc3f..e817df1 100755 --- a/file_to_link.sh +++ b/file_to_link.sh @@ -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 diff --git a/file_to_zip.sh b/file_to_zip.sh new file mode 100755 index 0000000..6a2f5df --- /dev/null +++ b/file_to_zip.sh @@ -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}"