practize_1course/automation/build_bundle.zsh

36 lines
896 B
Bash
Executable file

#!/bin/zsh
BOLD='\033[1m'
REGULAR='\033[0m'
target_dir="Pu240_798-811_TitovAA"
target_path=$(find ../ -type d -name "$target_dir" -print -quit)
read -r "USER_AGREE?%B$target_path%b will be used as bundle source [Y/n]: "
USER_AGREE="${USER_AGREE:l}"
if [[ "$USER_AGREE" == "q" ]]; then
print "Bundle\'s making canceled"
exit
fi
if ! [[ -z "$USER_AGREE" || "$USER_AGREE" == "y" || "$USER_AGREE" == "yes" ]]; then
read -r "target_path?Enter path to bundle source: "
fi
dirname="${target_path:A:t}"
tmp_dir=$(mktemp -d /tmp/XXXXX)
#tmp_dir="/tmp/bundle"
cp -r "$target_path" "$tmp_dir"
for dir in "$tmp_dir/$dirname"/*(/); do
find "$dir" -type f -iname "rename*" -exec rm -f {} \;
/usr/bin/env python ./clean_wolfram_notebook.py "$dir"/* --in-place
done
find "$tmp_dir" -type f -iname "*.bak" -exec rm -f {} \;
tar -cvzf bundle.tar.gz -C "$tmp_dir" "$dirname"
rm -rf "$tmp_dir"