Skip to content

Instantly share code, notes, and snippets.

@canhnt
Last active August 29, 2015 14:04
Show Gist options
  • Save canhnt/c990b9ba59b8cf4b2da5 to your computer and use it in GitHub Desktop.
Save canhnt/c990b9ba59b8cf4b2da5 to your computer and use it in GitHub Desktop.
Bash script to compile, run Hippo CMS project
#!/bin/bash
PROFILE_FILENAME=".hippo"
backup() {
echo "Move repository from $1 to $2"
mv $1 $2
exit 0
}
get_profiles(){
# remove commented lines
profiles=$(sed '/^#/d' "$PROFILE_FILENAME" | tr '\n' ' ')
echo $profiles
}
get_projectname(){
NAME=`basename $(pwd)`
if [[ $NAME == "trunk" ]]; then
NAME=$(pwd | awk -F"/" '{print $(NF-1)}')
fi
echo $NAME
}
exec_cmd(){
CMD=$1
MSG=$2
HIPPO_PROFILES=$3
if [[ $CMD ]]; then
echo $MSG
set -x
$CMD $HIPPO_PROFILES
set +x
fi
}
usage(){
cat <<EOF
Hippo projects supporting tools
Usage: $0 options
OPTIONS:
-c, --compile Compile project
-r, --run Run the project
-s, --bootstrap Bootstrap the repository
-b, --backup Backup repository
-h, --help Show help
EOF
}
#Only run in folder with pom.xml file
if [[ ! -e $(pwd)/pom.xml ]]; then
echo "Cannot run Hippo tools in the non-maven folder"
exit 1
fi
if [[ ! -e $(pwd)/$PROFILE_FILENAME ]]; then
echo "Profile setting file '$PROFILE_FILENAME' is not found. Create a default profile"
touch $PROFILE_FILENAME
echo "-Djrebel" > $PROFILE_FILENAME
echo "-Drepo.bootstrap=true" >> $PROFILE_FILENAME
echo "-Dcargo.jvm.args='-Dwicket.configuration=development'" >> $PROFILE_FILENAME
fi
# Parse the path to find project name
PROJECTNAME=$(get_projectname)
# Get Hippo profile setting
HIPPO_PROFILES=$(get_profiles)
echo "Working on the '$PROJECTNAME' project at $(pwd)"
REPO_BASEDIR="$HOME/tmp/$PROJECTNAME"
if [[ ! -d "$REPO_BASEDIR" ]]; then
mkdir -p "$REPO_BASEDIR"
fi
REPO_PATH="$REPO_BASEDIR/repo"
REPO_BACKUP_PATH="$REPO_BASEDIR/repo-`date +%Y.%m.%d-%H.%M.%S`"
echo "Repository path: $REPO_PATH"
[[ "$#" -eq 0 ]] && usage
#OPT_JREBEL="-Djrebel"
#INIT_LOCAL="-Plocal"
CMD=""
MSG=""
while (( "$#" )); do
case "$1" in
"-c" | "--compile" )
MSG="Compiling $PROJECTNAME project"
CMD="mvn clean verify"
;;
"-i" | "--install" )
MSG="Installing $PROJECTNAME project"
CMD="mvn clean install"
;;
'-r' | '--run')
if [[ -n "$CMD" ]]; then
exec_cmd "$CMD" "$MSG" "$HIPPO_PROFILES"
fi
MSG="Running $PROJECTNAME project"
CMD="mvn -Pcargo.run -Drepo.path=$REPO_PATH"
;;
'-s' | '--bootstrap')
HIPPO_PROFILES="$HIPPO_PROFILES -Drepo.bootstrap=true"
;;
"-b" | '--backup')
backup $REPO_PATH $REPO_BACKUP_PATH
exit;;
'-h' | '--help')
usage
exit;;
esac
shift
done
if [[ -n "$CMD" ]]; then
exec_cmd "$CMD" "$MSG" "$HIPPO_PROFILES"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment