#!/bin/sh ## ## Creates cbz archive from supplied folder. ## FILENAME=$(basename $0) show_help() { echo $FILENAME grep "\#\#" $0 | cut -d\# -f3- echo } PREFIX=""; DELETE_AFTER=false SUFFIX=cbz while getopts "hp:s:d" opt; do case $opt in ## ## -p Prefix resulting filenames with supplied prefix. ## ## All resulting files will start with supplied ## prefix e.g. -p foo- bar baz will result in ## creation of archives foo-bar.cbz and foo-baz.cbz: ## p) PREFIX="$OPTARG"; ;; ## ## -d Delete supplied folders after creating archives. d) DELETE_AFTER=true; ;; ## ## -s Change file type suffix from default cbz to specified. ## ## All resulting files will end with supplied suffix instead ## of cbz. E.g. -s zip will trigger creation of normal zip files. s) SUFFIX="$OPTARG"; ;; h) show_help;exit 1;; \?) show_help;exit 1;; :) echo "Option -$OPTARG requires an argument." >&2 ; exit 1;; esac done shift $(($OPTIND-1)) echo Prefix: $PREFIX Suffix: Delete folders: $DELETE_AFTER echo $@ for DIR in "$@"; do if [ -d "$DIR" ]; then NAME=$(basename "$DIR") echo "Going to create $NAME" zip -r "${PREFIX}${NAME}.${SUFFIX}" "$DIR" fi done