184 lines
4.6 KiB
Bash
Executable File
184 lines
4.6 KiB
Bash
Executable File
#!/bin/env bash
|
|
|
|
show_help() {
|
|
echo "Usage: $(basename $0) [--preset|-p] [--executable|-e] [--dry-run|-d] [--help|h]"
|
|
echo "Options:"
|
|
echo " --help | -h (Optional) Display help information on how to use this script"
|
|
echo " --repo-dir | -r (Required) GP's cloned git repository directory"
|
|
echo " --install-dir | -d (Required) Where to install Metawizard. Must be a relative path"
|
|
echo " --no-download | -no-dl (Optional) Use this if you already have the .jar file in --install-dir (and the dir is already created)"
|
|
echo " --no-meta-setup | -no-m (Optional) Use this if you already have MetaWizard installed"
|
|
echo " --no-post-steps | -no-p (Optional) Use this if you already have done the post steps"
|
|
}
|
|
|
|
REPO_DIR=""
|
|
INSTALL_DIR=""
|
|
SHOULD_DOWNLOAD=true
|
|
SHOULD_INSTALL_META=true
|
|
SHOULD_DO_POST_STEPS=true
|
|
|
|
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
|
|
;;
|
|
--no-download | -no-dl)
|
|
SHOULD_DOWNLOAD=false
|
|
shift
|
|
;;
|
|
--no-meta-setup | -no-m)
|
|
SHOULD_INSTALL_META=false
|
|
shift
|
|
;;
|
|
--no-post-steps | -no-p)
|
|
SHOULD_DO_POST_STEPS=false
|
|
shift
|
|
;;
|
|
*) shift ;;
|
|
esac
|
|
done
|
|
|
|
commands_to_check=(wget)
|
|
|
|
commands_not_found=()
|
|
for command in ${commands_to_check[@]}; do
|
|
if ! command -v "$command" &>/dev/null; then
|
|
commands_not_found+=("$command")
|
|
fi
|
|
done
|
|
|
|
if [ ${#commands_not_found[@]} -ne 0 ]; then
|
|
echo 'The following commands are necessary in order to run the script, but were not found:'
|
|
|
|
for command in ${commands_not_found[@]}; do
|
|
echo " \"$command\""
|
|
done
|
|
|
|
exit 1
|
|
fi
|
|
|
|
ROOT_DIR=$(pwd)
|
|
|
|
if [ $(basename $ROOT_DIR) != "$INSTALL_DIR" ]; then
|
|
mkdir --parents $INSTALL_DIR
|
|
cd $INSTALL_DIR
|
|
ROOT_DIR=$(pwd)
|
|
fi
|
|
|
|
validate_dir() {
|
|
DIR="$1"
|
|
MESSAGE="$2"
|
|
|
|
if [ -z "$DIR" ]; then
|
|
echo "$MESSAGE"
|
|
exit 0
|
|
fi
|
|
|
|
if [ ! -d "$DIR" ]; then
|
|
echo "The provided directory '$DIR' does not exist"
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
get_cdk_version_from_gp_superparent_pom() {
|
|
SUPERPARENT_POM_PATH=$1
|
|
|
|
CDK_VERSION=$(xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:properties/pom:cpqd.cdk.version' $SUPERPARENT_POM_PATH)
|
|
|
|
echo "$CDK_VERSION"
|
|
}
|
|
|
|
get_version_type_from_version() {
|
|
version=$1
|
|
|
|
if [[ $version == *"-"* ]]; then
|
|
echo 'snapshot'
|
|
else
|
|
echo 'release'
|
|
fi
|
|
}
|
|
|
|
get_maven_repo_from_version() {
|
|
version=$1
|
|
|
|
case $(get_version_type_from_version $version) in
|
|
'snapshot') echo 'cpqd-snapshot' ;;
|
|
'release') echo 'cpqd-release' ;;
|
|
*) echo "[ERROR] Função \"$FUNCNAME\" recebeu um retorno inválido" ;;
|
|
esac
|
|
}
|
|
|
|
chmod_sh_files_recursively() {
|
|
DIRPATH=$1
|
|
|
|
find $DIRPATH -type f -name '*.sh' -exec chmod +x {} \;
|
|
}
|
|
|
|
validate_dir "$REPO_DIR" "Please specify a GP's cloned git repository directory with --repo-dir or -r"
|
|
|
|
METAWIZARD_JAR_FILENAME=""
|
|
|
|
if $SHOULD_DOWNLOAD; then
|
|
CDK_VERSION=$(get_cdk_version_from_gp_superparent_pom "$REPO_DIR/main/super-parent/pom.xml")
|
|
|
|
if [ -z "$CDK_VERSION" ]; then
|
|
echo "Could not retrieve GP's version from the specified cloned repository"
|
|
exit 0
|
|
fi
|
|
|
|
ARTIFACTORY_REPOSITORY=$(get_maven_repo_from_version "$CDK_VERSION")
|
|
METAWIZARD_ARTIFACTORY_PATH_WILDCARD="$ARTIFACTORY_REPOSITORY/br/com/cpqd/cdk/cpqd-cdk-meta-installer/$CDK_VERSION/cpqd-cdk-meta-installer-*.jar"
|
|
METAWIZARD_ARTIFACTORY_PATH=$(jf rt search --fail-no-op=true --sort-by=path "${METAWIZARD_ARTIFACTORY_PATH_WILDCARD}" | jq -r '.[].path')
|
|
METAWIZARD_JAR_FILENAME=$(basename ${METAWIZARD_ARTIFACTORY_PATH})
|
|
METAWIZARD_ARTIFACTORY_URL="https://artifactory.cpqd.com.br/artifactory/${METAWIZARD_ARTIFACTORY_PATH}"
|
|
|
|
wget $METAWIZARD_ARTIFACTORY_URL
|
|
fi
|
|
|
|
METAWIZARD_SH_FILE="wizard/metawizard.sh"
|
|
|
|
if $SHOULD_INSTALL_META; then
|
|
echo "Please specify '$(pwd)' in MetaWizard's installation directory"
|
|
|
|
java -jar $METAWIZARD_JAR_FILENAME
|
|
|
|
chmod_sh_files_recursively "$(pwd)"
|
|
|
|
if [ -z "$METAWIZARD_SH_FILE" ]; then
|
|
echo "Could not find MetaWizard's .sh file"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
if $SHOULD_DO_POST_STEPS; then
|
|
rm -rf wizard/modules/xml/xml-compat/
|
|
|
|
FILES_TO_COPY=(settings.properties mw-modules-config.xml mw-validation-config.xml)
|
|
|
|
ETICS_FOLDER_WITH_META_FILES=etics/fontes/components/model/src/main/config
|
|
|
|
for f in ${FILES_TO_COPY[@]}; do
|
|
cp $REPO_DIR/$ETICS_FOLDER_WITH_META_FILES/$f wizard/config/
|
|
done
|
|
|
|
MKLINK_META_FILE="mklink_META.sh"
|
|
|
|
cp $REPO_DIR/$ETICS_FOLDER_WITH_META_FILES/$MKLINK_META_FILE $ROOT_DIR
|
|
|
|
chmod +x ./$MKLINK_META_FILE
|
|
|
|
./$MKLINK_META_FILE $REPO_DIR
|
|
|
|
sed -i 's/256/2048/g' ./$METAWIZARD_SH_FILE
|
|
sed -i 's/512/4096/g' ./$METAWIZARD_SH_FILE
|
|
fi
|