#!/bin/bash show_help() { echo "Usage: $0 [--files|-f files]" echo "Options:" echo " --help | -h (Optional) Display help information on how to use this script" echo " --files | -f (Optional) Specify the files to explode, separation by comma (,)" echo " If not specified, the script will apply the changes to all [jew]ar files in current directory" echo " --revert true | -r true (Optional) Undo the exploding of java files" } files_arg='' revert=false while [ "$#" -gt 0 ]; do case "$1" in --help|-h) show_help; exit ;; --files|-f) files_arg="$2"; shift 2;; --revert|-r) revert=true; shift 2;; *) shift ;; esac done convert_csv_to_array() { csv_arg=$1 res_arr=`echo $csv_arg | tr ',' "\n"` echo $res_arr } files=() if [ ! -z "$files_arg" ]; then files=`convert_csv_to_array "$files_arg"` else regex_search=".*[jew]ar" if $revert; then regex_search+=".old" fi files=(`find * -maxdepth 0 -type f -regextype sed -regex $regex_search`) fi for f in ${files[@]}; do if [ ! -f "$f" ]; then continue fi if $revert; then file_without_old_suffix=${f%".old"} # "f" will have ".old" suffix mv $f $file_without_old_suffix zip $file_without_old_suffix $f rm -f "$file_without_old_suffix.dodeploy" else mv $f $f.old unzip -d $f $f.old touch $f.dodeploy fi rm -f "$f.isdeploying" rm -f "$f.deployed" rm -f "$f.failed" done