Files
dotfiles/scripts/shell/job/gp/explode-java-files.sh
2024-04-16 09:50:36 -03:00

72 lines
1.7 KiB
Bash
Executable File

#!/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
rm --recursive --force $file_without_old_suffix
mv $f $file_without_old_suffix
rm --force "$file_without_old_suffix.dodeploy"
rm --force cpqd-ds.xml.failed
# for removal of files after else
f=$file_without_old_suffix
else
mv $f $f.old
unzip -qq -d $f $f.old
touch $f.dodeploy
fi
rm --force "$f.isdeploying"
rm --force "$f.deployed"
rm --force "$f.failed"
done