#!/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}")
filename=$(basename -- "$SOURCE")
#extension="${filename##*.}"
filename="${filename%.*}"
7z a -tzip -mx=9 "${TARGET}"/"${filename}".zip "${SOURCE}"
