From 406f585ca5b74ce15d7373f94874dfb2cf315975 Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Fri, 6 Dec 2024 15:02:27 -0300 Subject: [PATCH] Adds copy-dbmanager-files-to-dbmanager-installation.sh --- ...manager-files-to-dbmanager-installation.sh | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100755 scripts/shell/job/gp/copy-dbmanager-files-to-dbmanager-installation.sh diff --git a/scripts/shell/job/gp/copy-dbmanager-files-to-dbmanager-installation.sh b/scripts/shell/job/gp/copy-dbmanager-files-to-dbmanager-installation.sh new file mode 100755 index 0000000..5e821ac --- /dev/null +++ b/scripts/shell/job/gp/copy-dbmanager-files-to-dbmanager-installation.sh @@ -0,0 +1,220 @@ +#!/bin/env bash + +printf "\n" + +show_help() { + echo "Usage: $(basename $0) [--commit-hashes|-c commit hashes] [--deployments-path|-d deployments path]" + echo "Options:" + echo " --help | -h (Optional) Display help information on how to use this script" + # TODO, implementar + echo " --repo-dir | -r (Required) Specify the git repository path that contains the commits" + echo " --install-dir | -d (Required) Specify the dbmanager's installation directory" + # echo " --use-git-status | -g (Optional) Will add the files with differences from the \"git status\" command" + # echo " --commit-hashes | -c (Optional) Specify the commit hashes, separation by comma (,)" + # echo " --commits-between | -cb (Optional) Specify two commit hashes, separation by comma (,), so all commits between them will be considered" + echo " --file-paths | -f (Required) Specify file paths to consider in the update, separation by comma (,)" + # echo " Specifying this will make the \"--commit-hashes\" parameter optional" + echo "" +} + +# commit_hashes_arg='' +# commits_between_arg='' +repo_dir='' +install_dir='' +# use_git_status=false +file_paths_arg='' + +while [ "$#" -gt 0 ]; do + case "$1" in + --help | -h) + show_help + exit + ;; + --repo-dir | -r) + repo_dir="$2" + shift 2 + ;; + --install-dir | -d) + install_dir="$2" + shift 2 + ;; + # --commit-hashes | -c) + # commit_hashes_arg="$2" + # shift 2 + # ;; + # --commits-between | -cb) + # commits_between_arg="$2" + # shift 2 + # ;; + --file-paths | -f) + file_paths_arg="$2" + shift 2 + ;; + --use-git-status | -g) + use_git_status=true + shift + ;; + *) shift ;; + esac +done + +print_newline() { + echo -e "" +} + +convert_csv_to_array() { + csv_arg=$1 + res_arr=$(echo $csv_arg | tr ',' "\n") + echo $res_arr +} + +commit_exists() { + commit_hash=$1 + + git cat-file -t $commit_hash 1>/dev/null 2>/dev/null + + if [ $? -eq 0 ]; then + return 0 + else + return 1 + fi +} + +get_target_paths_from_commit_hash() { + commit_hash=$1 + + # TODO, fazer tratativa exclusiva para diff filter com A (added) + # TODO, fazer tratativa exclusiva para diff filter com D (deleted) + # TODO, adicionar tratativa para arquivos .jdpl + + echo $(git show --oneline --name-only --diff-filter=MA $c | tail -n +2) +} + +function join_by { + local d=${1-} f=${2-} + + if shift 2; then + printf %s "$f" "${@/#/$d}" + fi +} + +function confirm() { + while true; do + read -p '' yn + case $yn in + [Yy]*) return 0 ;; + [Nn]*) return 1 ;; + [Cc]*) exit ;; + *) echo "Please answer YES, NO, or CANCEL." ;; + esac + done +} + +if [ -z "$file_paths_arg" ] && + [ -z "$commit_hashes_arg" ] && + [ -z "$commits_between_arg" ] && + ! $use_git_status; then + echo "Error: Either one of these arguments should be provided:" + # echo " Commit hashes (--commit-hashes or -c) or;" + # echo " Commits between (--commits-between or -cb) or;" + echo " File paths (--file-paths or -f) or;" + # echo " Use Git Status (--use-git-status or -g)." + exit 1 +fi + +if [ ! -z "$repo_dir" ]; then + if [ -z "$commit_hashes_arg" ] && [ -z "$commits_between_arg" ] && [ ! $use_git_status ] && [ -z "$file_paths_arg" ]; then + echo "Error: If you specify the Commit hashes (--commit-hashes or -c) and/or Commits between (--commits-between or -cb), the repository directory (--repo-dir or -r) is also required." + exit 1 + fi +fi + +if [ -z "$install_dir" ]; then + echo "Please specify a dbmanager installation directory with --install-dir or -d" + exit 1 +fi + +if [ ! -d "$install_dir" ]; then + echo "The specified dbmanager installation directory does not exists" + exit 1 +fi + +scripts_folder=$HOME/documents/repos-personal/personal-devboot/scripts/shell/job/gp + +if [ ! -d "$scripts_folder" ]; then + echo "The git repository \"CloudAlb/personal-devboot\" must be in the \"~/repos\" folder!" + exit 1 +fi + +cur=$(pwd) + +# cd $repo_dir +# +# if [ ! -z "$commit_hashes_arg" ]; then +# commit_hashes=$(convert_csv_to_array "$commit_hashes_arg") +# +# for c in ${commit_hashes[@]}; do +# if ! commit_exists $c; then +# continue +# fi +# +# target_paths+=($(get_target_paths_from_commit_hash "$c")) +# done +# fi +# +# if [ ! -z "$commits_between_arg" ]; then +# commit_hashes=$(git rev-list --ancestry-path "${commits_between_arg/","/".."}") +# target_paths_arg=() +# +# for c in ${commit_hashes[@]}; do +# if ! commit_exists $c; then +# continue +# fi +# +# target_paths_arg+=($(get_target_paths_from_commit_hash "$c")) +# done +# +# for i in ${target_paths_arg[@]}; do +# target_paths+=($i) +# done +# fi +# +if [ ! -z "$file_paths_arg" ]; then + file_paths=$(convert_csv_to_array "$file_paths_arg") + + for f in ${file_paths[@]}; do + if [ ! -f "$repo_dir/$f" ]; then + echo "[WARN] O arquivo informado \"$f\" não existe no repositório." + continue + fi + + target_paths+=($f) + done +fi + +# +# if $use_git_status; then +# target_paths+=($(git ls-files --modified --others --exclude-standard)) +# +# if [ ${#target_paths[@]} -eq 0 ]; then +# echo "Error: You specified \"--use-git-status\" but there wasn't any modified files to use." +# exit 1 +# fi +# fi +# + +target_paths_uniq=$(for i in "${target_paths[@]}"; do echo $i; done | sort -u) + +for p in ${target_paths_uniq[@]}; do + origin_filepath="${repo_dir}/$p" + + target_path_in_dbmanager_path=$(echo "$p" | sed 's/^.*\/main\///') + + target_path="${install_dir}/db/$(dirname $target_path_in_dbmanager_path)" + + # gambiarra para esse caso aqui + # cp /l/disk0/mbrunhara/documents/repos-job/lb-indicator-ETICS-243054/gp/dbmanager/fontes/components/etics/dbmanager/core/src/main/db/xml/domain/create/schema/data/metamodelo_fk.xml /l/disk0/mbrunhara/documents/repos-job/lb-indicator-ETICS-243054/ambients/dbmanager/dbmanager/db/xml/domain/create/schema/data + target_path=$(echo $target_path | sed 's/\/db\/db\//\/db\//') + + cp $origin_filepath $target_path +done