Skip to content

Commit

Permalink
Bugifx Interopability
Browse files Browse the repository at this point in the history
  • Loading branch information
mepux committed Jul 31, 2020
1 parent 5a91e89 commit 78227cd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
48 changes: 31 additions & 17 deletions bin/cb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ export CB_OS CB_MACHINE
export CB_LINE CB_LINEHEADER


#########################################################################
# Check if the binary exists
#########################################################################
existBinary() {
if [ "$CB_OS" = "linux" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$2}'"
elif [ "$CB_OS" = "cygwin" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$2}'"
elif [ "$CB_OS" = "mac" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$1}'"
fi
}


#########################################################################
# Get the file size (gnu linux: stat -c %s, max: stat -f %z)
#########################################################################
Expand Down Expand Up @@ -136,7 +150,7 @@ executeCustomSettings() {
checkInternetConnection() {
CB_OFFLINE=false
CMD=""
[ -z "$(whereis -b ping 2>/dev/null | awk '{print $2}')" ] && return
[ -z "$(existBinary ping)" ] && return

[ -z "$CB_ONLINE_ADDRESS" ] && CB_ONLINE_ADDRESS="8.8.8.8"
if [ "$CB_OS" = "linux" ]; then
Expand Down Expand Up @@ -250,17 +264,17 @@ projectWizard() {
#########################################################################
exploreProject()
{
[ "$CB_OS" = "windows" ] && fileExplorer=$(whereis -b explorer.exe 2>/dev/null | awk '{print $2}')
[ "$CB_OS" = "cygwin" ] && fileExplorer=$(whereis -b explorer.exe 2>/dev/null | awk '{print $2}')
[ "$CB_OS" = "mac" ] && fileExplorer=$(whereis -b open 2>/dev/null | awk '{print $2}')
[ "$CB_OS" = "windows" ] && fileExplorer=$(existBinary explorer.exe)
[ "$CB_OS" = "cygwin" ] && fileExplorer=$(existBinary explorer.exe)
[ "$CB_OS" = "mac" ] && fileExplorer=$(existBinary open)

if [ "$CB_OS" = "linux" ]; then
fileExplorer=$(whereis -b xdg-open 2>/dev/null | awk '{print $2}')
fileExplorer=$(existBinary xdg-open)
# kde
[ -z "$fileExplorer" ] && fileExplorer=$(whereis -b dolphin 2>/dev/null | awk '{print $2}')
[ -z "$fileExplorer" ] && fileExplorer=$(existBinary dolphin)
# gnome
[ -z "$fileExplorer" ] && fileExplorer=$(whereis -b gnome-open 2>/dev/null | awk '{print $2}')
[ -z "$fileExplorer" ] && fileExplorer=$(whereis -b nautilus 2>/dev/null | awk '{print $2}')
[ -z "$fileExplorer" ] && fileExplorer=$(existBinary gnome-open)
[ -z "$fileExplorer" ] && fileExplorer=$(existBinary nautilus)
fi

if [ -n "$fileExplorer" ]; then
Expand Down Expand Up @@ -375,7 +389,7 @@ commonBuildGradle() {
! [ "$CB_GRADLE_HOME" = "$GRADLE_HOME" ] && GRADLE_HOME="$CB_GRADLE_HOME" && export GRADLE_HOME
[ "$(echo ${PATH#*$CB_GRADLE_HOME/bin*})" = "$(echo $PATH)" ] && PATH="$CB_GRADLE_HOME/bin:$PATH" && export PATH

if [ -z "$(whereis -b $GRADLE_EXEC 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary $GRADLE_EXEC)" ]; then
echo "${CB_LINEHEADER}Could not find gradle version in path."
endWithError
fi
Expand Down Expand Up @@ -418,7 +432,7 @@ commonBuildMaven() {
! [ "$CB_MAVEN_HOME" = "$MAVEN_HOME" ] && MAVEN_HOME="$CB_MAVEN_HOME" && export MAVEN_HOME
[ "$(echo ${PATH#*$CB_MAVEN_HOME/bin*})" = "$(echo $PATH)" ] && PATH="$CB_MAVEN_HOME/bin:$PATH" && export PATH

if [ -z "$(whereis -b $MAVEN_EXEC 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary $MAVEN_EXEC)" ]; then
echo "${CB_LINEHEADER}Could not find maven version in path."
endWithError
fi
Expand Down Expand Up @@ -457,7 +471,7 @@ commonBuildAnt() {
! [ "$CB_ANT_HOME" = "$ANT_HOME" ] && ANT_HOME="$CB_ANT_HOME" && export ANT_HOME
[ "$(echo ${PATH#*$CB_ANT_HOME/bin*})" = "$(echo $PATH)" ] && PATH="$CB_ANT_HOME/bin:$PATH" && export PATH

if [ -z "$(whereis -b $ANT_EXEC 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary $ANT_EXEC)" ]; then
echo "${CB_LINEHEADER}Could not find ant version in path."
endWithError
fi
Expand Down Expand Up @@ -495,7 +509,7 @@ commonBuildNode() {
! [ "$CB_NODE_HOME" = "$NODE_HOME" ] && NODE_HOME="$CB_NODE_HOME" && export NODE_HOME
[ "$(echo ${PATH#*$CB_NODE_HOME*})" = "$(echo $PATH)" ] && PATH="$CB_NODE_HOME:$PATH" && export PATH

if [ -z "$(whereis -b $NODE_EXEC 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary $NODE_EXEC)" ]; then
echo "${CB_LINEHEADER}Could not find node version in path."
endWithError
fi
Expand Down Expand Up @@ -580,7 +594,7 @@ commonBuild() {
[ "$(echo ${PATH#*$CB_JAVA_HOME/bin*})" = "$(echo $PATH)" ] && PATH="$CB_JAVA_HOME_RUNTIME/bin:$PATH" && export PATH
#&& echo ${CB_LINEHEADER}Set $CB_JAVA_HOME to path!

if [ -z "$(whereis -b $JAVAC_EXEC 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary $JAVAC_EXEC)" ]; then
echo "${CB_LINEHEADER}Could not find java version in path."
endWithError
fi
Expand Down Expand Up @@ -611,8 +625,8 @@ commonBuild() {
# checkHttpRequestCLI
#########################################################################
checkHttpRequestCLI() {
[ -n "$(whereis -b curl 2>/dev/null | awk '{print $2}')" ] && echo "curl" && return
[ -n "$(whereis -b wget 2>/dev/null | awk '{print $2}')" ] && echo "wget" && return
[ -n "$(existBinary curl)" ] && echo "curl" && return
[ -n "$(existBinary wget)" ] && echo "wget" && return
echo ""
}

Expand All @@ -623,7 +637,7 @@ checkHttpRequestCLI() {
downloadFiles() {
errorCode=1
if [ -z "$2" ]; then
[ -z "$(whereis -b wget 2>/dev/null | awk '{print $2}')" ] && echo "${CB_LINEHEADER}Can not download wildcard by curl, please install wget." | tee -a "$CB_LOGFILE" && return
[ -z "$(existBinary wget)" ] && echo "${CB_LINEHEADER}Can not download wildcard by curl, please install wget." | tee -a "$CB_LOGFILE" && return
fi

if [ "$HTTP_REQUEST_CLI" = "curl" ]; then
Expand Down Expand Up @@ -936,7 +950,7 @@ installCb() {

if [ -z "${i%%*.zip}" ]; then

if [ -z "$(whereis -b unzip 2>/dev/null | awk '{print $2}')" ]; then
if [ -z "$(existBinary unzip)" ]; then
echo "${CB_LINEHEADER}Could not find unzip, please install unzip."
CMD=""
else
Expand Down
41 changes: 27 additions & 14 deletions bin/cb-install
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ case $CB_OS in
'aix') CB_OS="aix";;
*) ;;
esac
CB_SHELL_INITIALISATION_CMD="export CB_HOME=$CB_HOME && export PATH=\"\$CB_HOME/bin:\$PATH\""


#########################################################################
# Check if the binary exists
#########################################################################
existBinary() {
if [ "$CB_OS" = "linux" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$2}'"
elif [ "$CB_OS" = "cygwin" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$2}'"
elif [ "$CB_OS" = "mac" ]; then
eval "whereis -b $1 2>/dev/null | awk '{print \$1}'"
fi
}


#########################################################################
Expand All @@ -71,9 +84,9 @@ getCurrentShell() {

currentShell=$(eval $CMD | awk '{print $1}')
if [ -z $currentShell ]; then
[ "$(echo ${SHELL##*/})" = "bash" ] && currentShell=".bashrc"
[ "$(echo ${SHELL##*/})" = "zsh" ] && currentShell=".zshrc"
[ "$(echo ${SHELL##*/})" = "zsh" ] && currentShell=".ashrc"
[ "$(echo ${SHELL##*/})" = "ash" ] && currentShell=".ashrc"
[ "$(echo ${SHELL##*/})" = "bash" ] && currentShell=".bashrc"
fi

echo $currentShell
Expand Down Expand Up @@ -144,7 +157,7 @@ installationFailed() {
# checkInternetConnection
#########################################################################
checkInternetConnection() {
[ -z "$(whereis -b ping 2>/dev/null | awk '{print $2}')" ] && return
[ -z "$(existBinary ping)" ] && return

[ -z "$CB_ONLINE_ADDRESS" ] && CB_ONLINE_ADDRESS="8.8.8.8"
if [ "$CB_OS" = "linux" ]; then
Expand All @@ -170,8 +183,8 @@ checkInternetConnection() {
# checkHttpRequestCLI
#########################################################################
checkHttpRequestCLI() {
[ -n "$(whereis -b curl 2>/dev/null | awk '{print $2}')" ] && echo "curl" && return
[ -n "$(whereis -b wget 2>/dev/null | awk '{print $2}')" ] && echo "wget" && return
[ -n "$(existBinary curl)" ] && echo "curl" && return
[ -n "$(existBinary wget)" ] && echo "wget" && return
echo ""
}

Expand Down Expand Up @@ -270,10 +283,10 @@ exithandler() {
#########################################################################
updateShellInitialisation() {
[ -z "$1" ] && return
shellProfile=$1
shellProfile="$1"

# in case it does not exist, just create empty file
! [ -f "$shellProfile" ] && touch $shellProfile && chmod 750 $shellProfile
! [ -f "$shellProfile" ] && touch "$shellProfile" && chmod 750 "$shellProfile"

if [ -w "$shellProfile" ]; then
backupFileName="${shellProfile}_cb-$(eval $FULLTIMESTAMP)"
Expand All @@ -291,7 +304,7 @@ updateShellInitialisation() {
#TEST: CB_HOME="$CB_HOME/aa"
CB_HOME_ESCAPED=$(echo "$CB_HOME" | sed 's/\//\\\//g')
[ "$CB_INSTALLER_SILENT" = "false" ] && echo "${CB_LINEHEADER}Update file $shellProfile"
cat "$shellProfile" | sed "s/CB_HOME\=.*\&/CB_HOME\=$CB_HOME_ESCAPED\ \&\&/g" > "$newFileName"
cat "$shellProfile" | sed "s/CB_HOME\=.*\&/CB_HOME\=\"$CB_HOME_ESCAPED\"\ \&\&/g" > "$newFileName"
chmod --reference="$shellProfile $newFileName" >/dev/null 2>&1
chmod +r+w "$newFileName" >/dev/null 2>&1
mv -f "$newFileName" "$shellProfile" >/dev/null 2>&1
Expand Down Expand Up @@ -409,13 +422,13 @@ if ! [ "$CB_HOME" = "$CB_DEVTOOLS/$CB_VERSION_NAME" ]; then
[ "$CB_INSTALLER_SILENT" = "false" ] && echo "${CB_LINEHEADER}Set CB_HOME to $CB_DEVTOOLS/$CB_VERSION_NAME"
CB_HOME="$CB_DEVTOOLS/$CB_VERSION_NAME"
export CB_HOME="$CB_HOME" && export PATH="$CB_HOME/bin:$PATH"
CB_SHELL_INITIALISATION_CMD="export CB_HOME=\"$CB_HOME\" && export PATH=\"\$CB_HOME/bin:\$PATH\""


[ -n "$(whereis -b bash 2>/dev/null | awk '{print $2}')" ] && updateShellInitialisation "$HOME/.bashrc"
[ -n "$(whereis -b ash 2>/dev/null | awk '{print $2}')" ] && updateShellInitialisation "$HOME/.ashrc"
[ -n "$(whereis -b zsh 2>/dev/null | awk '{print $2}')" ] && updateShellInitialisation "$HOME/.zshrc"
[ -n "$(existBinary bash)" ] && updateShellInitialisation "$HOME/.bashrc"
[ -n "$(existBinary ash)" ] && updateShellInitialisation "$HOME/.ashrc"
[ -n "$(existBinary zsh)" ] && updateShellInitialisation "$HOME/.zshrc"

#if [ -n "$(whereis -b fish 2>/dev/null | awk '{print $2}')" ]; then
#if [ -n "$(existBinary fish)" ]; then
# CB_SHELL_INITIALISATION_CMD="set -x CB_HOME $CB_HOME && set -x PATH \$PATH \$CB_HOME/bin"
# updateShellInitialisation "$HOME/.config/fish/config.fish"
#fi
Expand Down

0 comments on commit 78227cd

Please sign in to comment.