Last active
August 29, 2015 14:02
-
-
Save cristobal/4329adc5f48d56e17d0b to your computer and use it in GitHub Desktop.
Bash - set JBoss Home Runtime from Brew install name or /Path/to/JBoss/installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
########################## | |
# Export new jboss path # | |
######################### | |
function export_path { | |
# already same as exported variables(s) no changes needed | |
if [ ! -z "$JBOSS_HOME" ] && \ | |
[ "$JBOSS_HOME" = "$jboss_dir" ] && \ | |
[ "$(echo $PATH | grep -E "${JBOSS_HOME}/bin" | wc -l | awk '{print $1}')" -eq 1 ]; then | |
echo "\$JBOSS_HOME & \$PATH already set" | |
return | |
fi | |
# old $JBOSS_HOME already exists in PATH remove it | |
path=$PATH | |
if [ ! -z "$JBOSS_HOME" ] && \ | |
[ "$(echo $PATH | grep -E "${JBOSS_HOME}/bin" | wc -l | awk '{print $1}')" -eq 1 ]; then | |
path=$(echo $PATH | tr ":" "\n" | grep -v "${JBOSS_HOME}/bin" | tr "\n" ":") | |
fi | |
# remove trailing ":" | |
if [ "${path:(${#path}-1):1}" = ":" ]; then | |
path=${path%?} | |
fi | |
export JBOSS_HOME=$jboss_dir | |
export PATH=${path}:${JBOSS_HOME}/bin | |
cat <<EOF | |
Updated \$JBOSS_HOME and \$PATH to following values: | |
JBOSS_HOME=$JBOSS_HOME | |
PATH=$PATH" | |
EOF | |
} | |
################ | |
# Print usage # | |
############## | |
function print_usage { | |
cat <<EOF | |
Usage: $0 <jboss-brew-name> or <path-to-jboss-dir> | |
EOF | |
} | |
################### | |
### Main logic ### | |
################ | |
# If no argument is given exit | |
arg=$1 | |
if [ -z "$arg" ]; then | |
print_usage | |
return | |
fi | |
# Set jboss_dir as given argument | |
# if argument matches wildfly-as or jboss-as installation update the jboss_dir to match brew location | |
jboss_dir=$arg | |
if [ "$(echo $arg | grep -E "^(wildfly|jboss)\-as$" | wc -l | awk '{print $1}')" -eq 1 ]; then | |
jboss_dir="/usr/local/opt/${arg}/libexec" | |
fi | |
if [ ! -d ${jboss_dir} ]; then | |
echo "The jboss directory: \`${jboss_dir}\ does not exist!" | |
return | |
fi | |
export_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the script
You will need to run this script as:
or
To be able to export the values from the script to the current user environment.
These changes are not permanent but only available for the current user environment.
Expected requirements
Install jboss-as and wildfly-as using brew.
It will still work with non brew installation but the script was made with brew in mind
Tips
Make the script executable
$ chmod +x /path/to/set-jboss-home.s
Add an alias in your
.bashrc
or.bash_aliases
alias set-jboss-home=". /path/to/jboss-home.
I.e. running wildfly-as as the default JBOSS environment add the line following to your
.bashrc
file or other init file`set-jboss-home wildly-as > /dev/null 2>&1'