You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2023/01/11 09:51:48 UTC
[incubator-hugegraph-toolchain] branch shell-fix created (now 156a5f22)
This is an automated email from the ASF dual-hosted git repository.
jin pushed a change to branch shell-fix
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
at 156a5f22 refact: enhance shell script style
This branch includes the following new commits:
new 156a5f22 refact: enhance shell script style
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-hugegraph-toolchain] 01/01: refact: enhance shell script style
Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch shell-fix
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
commit 156a5f22b076524a2a7df7adb731dca8d2253a35
Author: imbajin <ji...@apache.org>
AuthorDate: Wed Jan 11 17:48:53 2023 +0800
refact: enhance shell script style
---
hugegraph-client/build.sh | 24 ------
.../assembly/static/bin/start-hubble.sh | 3 +-
.../hubble-dist/assembly/static/bin/stop-hubble.sh | 2 +-
hugegraph-loader/assembly/static/bin/get-params.sh | 2 +-
.../static/bin/hugegraph-flinkcdc-loader.sh | 16 ++--
.../assembly/static/bin/hugegraph-loader.sh | 2 +-
.../assembly/static/bin/hugegraph-spark-loader.sh | 16 ++--
.../assembly/static/bin/mapping-convert.sh | 14 ++--
.../assembly/static/bin/utf8-bom-to-utf8.sh | 2 +-
hugegraph-loader/build.sh | 24 ------
hugegraph-tools/assembly/bin/backup.sh | 19 +++--
hugegraph-tools/assembly/bin/clear.sh | 24 +++---
hugegraph-tools/assembly/bin/deploy.sh | 48 ++++++------
hugegraph-tools/assembly/bin/hugegraph | 59 +++++++-------
hugegraph-tools/assembly/bin/release.sh | 44 +++++------
hugegraph-tools/assembly/bin/schedule-backup.sh | 33 ++++----
hugegraph-tools/assembly/bin/start-all.sh | 28 +++----
hugegraph-tools/assembly/bin/stop-all.sh | 12 +--
hugegraph-tools/assembly/bin/util.sh | 90 +++++++++++-----------
hugegraph-tools/build.sh | 22 ------
20 files changed, 211 insertions(+), 273 deletions(-)
diff --git a/hugegraph-client/build.sh b/hugegraph-client/build.sh
deleted file mode 100644
index 03d8de92..00000000
--- a/hugegraph-client/build.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-HUGEGRAPH_CLIENT_RELEASE_PATH="${PWD}/output/"
-
-export MAVEN_HOME="/home/scmtools/buildkit/maven/apache-maven-3.3.9/"
-export JAVA_HOME="/home/scmtools/buildkit/java/jdk1.8.0_25/"
-export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
-
-mvn clean test -Dtest=UnitTestSuite
diff --git a/hugegraph-hubble/hubble-dist/assembly/static/bin/start-hubble.sh b/hugegraph-hubble/hubble-dist/assembly/static/bin/start-hubble.sh
index e9c9c9d7..b15b3c49 100644
--- a/hugegraph-hubble/hubble-dist/assembly/static/bin/start-hubble.sh
+++ b/hugegraph-hubble/hubble-dist/assembly/static/bin/start-hubble.sh
@@ -78,7 +78,8 @@ args=${CONF_PATH}/hugegraph-hubble.properties
log=${LOG_PATH}/hugegraph-hubble.log
echo -n "starting HugeGraphHubble "
-nohup nice -n 0 java -server "${java_opts}" -Dhubble.home.path="${HOME_PATH}" -cp "${class_path}" ${main_class} "${args}" > "${log}" 2>&1 < /dev/null &
+nohup nice -n 0 java -server "${java_opts}" -Dhubble.home.path="${HOME_PATH}" \
+-cp "${class_path}" ${main_class} "${args}" > "${log}" 2>&1 < /dev/null &
pid=$!
echo ${pid} > "${PID_FILE}"
diff --git a/hugegraph-hubble/hubble-dist/assembly/static/bin/stop-hubble.sh b/hugegraph-hubble/hubble-dist/assembly/static/bin/stop-hubble.sh
index 8d525ff9..03f1015a 100644
--- a/hugegraph-hubble/hubble-dist/assembly/static/bin/stop-hubble.sh
+++ b/hugegraph-hubble/hubble-dist/assembly/static/bin/stop-hubble.sh
@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-HOME_PATH=$(dirname $0)
+HOME_PATH=$(dirname "$0")
HOME_PATH=$(cd "${HOME_PATH}"/.. && pwd)
BIN_PATH=${HOME_PATH}/bin
PID_FILE=${BIN_PATH}/pid
diff --git a/hugegraph-loader/assembly/static/bin/get-params.sh b/hugegraph-loader/assembly/static/bin/get-params.sh
index e0302399..b9040de1 100644
--- a/hugegraph-loader/assembly/static/bin/get-params.sh
+++ b/hugegraph-loader/assembly/static/bin/get-params.sh
@@ -47,7 +47,7 @@ function get_params() {
esac
done
- if [ $mode = 'cluster' ];then
+ if [ "$mode" = 'cluster' ];then
HUGEGRAPH_PARAMS="$HUGEGRAPH_PARAMS --file ${file##*/}"
ENGINE_PARAMS="$ENGINE_PARAMS --files ${file}"
else
diff --git a/hugegraph-loader/assembly/static/bin/hugegraph-flinkcdc-loader.sh b/hugegraph-loader/assembly/static/bin/hugegraph-flinkcdc-loader.sh
index e424dd98..2cd65d96 100755
--- a/hugegraph-loader/assembly/static/bin/hugegraph-flinkcdc-loader.sh
+++ b/hugegraph-loader/assembly/static/bin/hugegraph-flinkcdc-loader.sh
@@ -16,20 +16,20 @@
# limitations under the License.
#
BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-APP_DIR=$(dirname ${BIN_DIR})
+APP_DIR=$(dirname "${BIN_DIR}")
LIB_DIR=${APP_DIR}/lib
-ASSEMBLY_JAR_NAME=$(find ${LIB_DIR} -name hugegraph-loader*.jar)
+ASSEMBLY_JAR_NAME=$(find "${LIB_DIR}" -name 'hugegraph-loader*.jar')
# get hugegraph_params and engine_params
source "$BIN_DIR"/get-params.sh
-get_params $*
+get_params "$@"
echo "engine_params: $ENGINE_PARAMS"
echo "hugegraph_params: $HUGEGRAPH_PARAMS"
CMD=${FLINK_HOME}/bin/flink run \
- ${ENGINE_PARAMS} \
- -c org.apache.hugegraph.loader.flink.HugeGraphFlinkCDCLoader \
- ${ASSEMBLY_JAR_NAME} ${HUGEGRAPH_PARAMS}
+ "${ENGINE_PARAMS}" \
+ -c org.apache.hugegraph.loader.flink.HugeGraphFlinkCDCLoader \
+ "${ASSEMBLY_JAR_NAME}" "${HUGEGRAPH_PARAMS}"
-echo ${CMD}
-exec ${CMD}
+echo "${CMD}"
+exec "${CMD}"
diff --git a/hugegraph-loader/assembly/static/bin/hugegraph-loader.sh b/hugegraph-loader/assembly/static/bin/hugegraph-loader.sh
index 4bc89652..23615e5b 100755
--- a/hugegraph-loader/assembly/static/bin/hugegraph-loader.sh
+++ b/hugegraph-loader/assembly/static/bin/hugegraph-loader.sh
@@ -25,7 +25,7 @@ abs_path() {
echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}
-BIN=`abs_path`
+BIN=$(abs_path)
TOP="$(cd ${BIN}/../ && pwd)"
CONF="$TOP/conf"
LIB="$TOP/lib"
diff --git a/hugegraph-loader/assembly/static/bin/hugegraph-spark-loader.sh b/hugegraph-loader/assembly/static/bin/hugegraph-spark-loader.sh
index 99d7c51f..6aa38439 100755
--- a/hugegraph-loader/assembly/static/bin/hugegraph-spark-loader.sh
+++ b/hugegraph-loader/assembly/static/bin/hugegraph-spark-loader.sh
@@ -16,25 +16,23 @@
# limitations under the License.
#
BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-APP_DIR=$(dirname ${BIN_DIR})
+APP_DIR=$(dirname "${BIN_DIR}")
LIB_DIR=${APP_DIR}/lib
# get hugegraph_params and engine_params
source "$BIN_DIR"/get-params.sh
-get_params $*
+get_params "$@"
echo "engine_params: $ENGINE_PARAMS"
echo "hugegraph_params: $HUGEGRAPH_PARAMS"
-ASSEMBLY_JAR_NAME=$(find ${LIB_DIR} -name hugegraph-loader*.jar)
-
+ASSEMBLY_JAR_NAME=$(find "${LIB_DIR}" -name 'hugegraph-loader*.jar')
DEFAULT_APP_NAME="hugegraph-spark-loader"
APP_NAME=${APP_NAME:-$DEFAULT_APP_NAME}
CMD="${SPARK_HOME}/bin/spark-submit
- --class org.apache.hugegraph.loader.spark.HugeGraphSparkLoader \
- ${ENGINE_PARAMS}
- --jars $(echo ${LIB_DIR}/*.jar | tr ' ' ',') ${ASSEMBLY_JAR_NAME} ${HUGEGRAPH_PARAMS}"
+ --class org.apache.hugegraph.loader.spark.HugeGraphSparkLoader ${ENGINE_PARAMS} \
+ --jars $(echo "${LIB_DIR}"/*.jar | tr ' ' ',') ${ASSEMBLY_JAR_NAME} ${HUGEGRAPH_PARAMS}"
-echo ${CMD}
-exec ${CMD}
+echo "${CMD}"
+exec "${CMD}"
diff --git a/hugegraph-loader/assembly/static/bin/mapping-convert.sh b/hugegraph-loader/assembly/static/bin/mapping-convert.sh
index 64f55dd0..2173c1af 100755
--- a/hugegraph-loader/assembly/static/bin/mapping-convert.sh
+++ b/hugegraph-loader/assembly/static/bin/mapping-convert.sh
@@ -18,9 +18,9 @@
export LANG=zh_CN.UTF-8
set -e
-HOME_PATH=`dirname $0`
-HOME_PATH=`cd ${HOME_PATH}/.. && pwd`
-cd ${HOME_PATH}
+HOME_PATH=$(dirname "$0")
+HOME_PATH=$(cd "${HOME_PATH}"/.. && pwd)
+cd "${HOME_PATH}"
BIN_PATH=${HOME_PATH}/bin
CONF_PATH=${HOME_PATH}/conf
@@ -34,15 +34,15 @@ if [[ -z "$1" ]]; then
fi
if [[ ! -d ${LOG_PATH} ]]; then
- mkdir ${LOG_PATH}
+ mkdir "${LOG_PATH}"
fi
class_path="."
-for jar in `ls ${LIB_PATH}/*.jar`; do
+for jar in "$LIB_PATH"/*.jar; do
class_path=${class_path}:${jar}
done
args=$1
main_class="org.apache.hugegraph.loader.MappingConverter"
-exec java -Dlog4j.configurationFile=${CONF_PATH}/log4j2.xml \
--cp ${class_path} ${main_class} ${args}
+exec java -Dlog4j.configurationFile="${CONF_PATH}"/log4j2.xml \
+ -cp "${class_path}" ${main_class} "${args}"
diff --git a/hugegraph-loader/assembly/static/bin/utf8-bom-to-utf8.sh b/hugegraph-loader/assembly/static/bin/utf8-bom-to-utf8.sh
index 38b55058..76138cd2 100755
--- a/hugegraph-loader/assembly/static/bin/utf8-bom-to-utf8.sh
+++ b/hugegraph-loader/assembly/static/bin/utf8-bom-to-utf8.sh
@@ -22,5 +22,5 @@ if [[ -z "$1" ]]; then
fi
path=$1
-find ${path} -type f -name "*" -print | xargs -i sed -i '1 s/^\xef\xbb\xbf//' {}
+find "${path}" -type f -name "*" -print | xargs -i sed -i '1 s/^\xef\xbb\xbf//' {}
echo "Conversion completed"
diff --git a/hugegraph-loader/build.sh b/hugegraph-loader/build.sh
deleted file mode 100644
index 1946a0a3..00000000
--- a/hugegraph-loader/build.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-HUGEGRAPH_LOADER_RELEASE_PATH="${PWD}/output/"
-
-export MAVEN_HOME="/home/scmtools/buildkit/maven/apache-maven-3.3.9/"
-export JAVA_HOME="/home/scmtools/buildkit/java/jdk1.8.0_25/"
-export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
-
-mvn clean compile
diff --git a/hugegraph-tools/assembly/bin/backup.sh b/hugegraph-tools/assembly/bin/backup.sh
index 3e91bd6f..70ee5b1f 100755
--- a/hugegraph-tools/assembly/bin/backup.sh
+++ b/hugegraph-tools/assembly/bin/backup.sh
@@ -18,23 +18,22 @@
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
-cd $BIN
+BIN=$(abs_path)
+cd "$BIN" || exit
# do backup
-bash $BIN/hugegraph ${*:1:$(($#-2))}"/hugegraph-backup-`date +%y%m%d%H%M`/"
+bash "$BIN"/hugegraph "${*:1:$(($# - 2))}/hugegraph-backup-$(date +%y%m%d%H%M)/"
-DIR=`eval echo '${'$(($#-2))'}'`
-NUM=`eval echo '${'$#'}'`
+DIR=$(eval echo '${'$(($# - 2))'}')
+NUM=$(eval echo '${'$#'}')
# delete redundant backups if needed
-for i in `ls -lt $DIR | grep -v "total" | grep "hugegraph-backup-" | awk -v awkNum="$NUM" '{if(NR>awkNum){print $9}}'`
-do
- rm -fr "$DIR/$i"
+for i in $(ls -lt "$DIR" | grep -v "total" | grep "hugegraph-backup-" | awk -v awkNum="$NUM" '{if(NR>awkNum){print $9}}'); do
+ rm -rf "${DIR:?}/$i"
done
diff --git a/hugegraph-tools/assembly/bin/clear.sh b/hugegraph-tools/assembly/bin/clear.sh
index f9b01326..4845ec46 100755
--- a/hugegraph-tools/assembly/bin/clear.sh
+++ b/hugegraph-tools/assembly/bin/clear.sh
@@ -44,22 +44,22 @@ if [ ! -w "${INSTALL_PATH}" ]; then
exit 1
fi
-INSTALL_PATH="$(cd ${INSTALL_PATH} && pwd)"
+INSTALL_PATH="$(cd "${INSTALL_PATH}" && pwd)"
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
-. ${BIN}/util.sh
+BIN=$(abs_path)
+. "${BIN}"/util.sh
-cd ${BIN}
+cd "${BIN}" || exit
SERVER_RELEASE_PREFIX="hugegraph"
STUDIO_RELEASE_PREFIX="hugegraph-studio"
@@ -68,9 +68,9 @@ function ensure_no_process() {
local path=$1
local prefix=$2
- for file in `ls ${path}`; do
+ for file in $path; do
file=${path}/${file}
- if [[ -d "${file}" && "${file}" =~ "${prefix}" ]]; then
+ if [[ -d "${file}" && "${file}" =~ ${prefix} ]]; then
p_name=${file}
process_status "${p_name}" >/dev/null
if [ $? -eq 0 ]; then
@@ -81,13 +81,13 @@ function ensure_no_process() {
done
}
-ensure_no_process ${INSTALL_PATH} ${SERVER_RELEASE_PREFIX}
-ensure_no_process ${INSTALL_PATH} ${STUDIO_RELEASE_PREFIX}
+ensure_no_process "${INSTALL_PATH}" ${SERVER_RELEASE_PREFIX}
+ensure_no_process "${INSTALL_PATH}" ${STUDIO_RELEASE_PREFIX}
-for file in ${INSTALL_PATH}/${SERVER_RELEASE_PREFIX}*; do
+for file in "${INSTALL_PATH}/${SERVER_RELEASE_PREFIX}"*; do
remove_with_prompt "${file}"
done
-for file in ${INSTALL_PATH}/${STUDIO_RELEASE_PREFIX}*; do
+for file in "${INSTALL_PATH}/${STUDIO_RELEASE_PREFIX}"*; do
remove_with_prompt "${file}"
done
diff --git a/hugegraph-tools/assembly/bin/deploy.sh b/hugegraph-tools/assembly/bin/deploy.sh
index 579fb0c9..40368733 100755
--- a/hugegraph-tools/assembly/bin/deploy.sh
+++ b/hugegraph-tools/assembly/bin/deploy.sh
@@ -19,7 +19,7 @@ VERSION=""
INSTALL_PATH=""
DOWNLOAD_LINK_PREFIX=""
DEFAULT_DOWNLOAD_LINK_PREFIX="https://github.com/hugegraph"
-DOWNLOAD_LINK_PREFIX_CONFIG=`env | grep ^HOME= | cut -c 6-`"/hugegraph-download-url-prefix"
+DOWNLOAD_LINK_PREFIX_CONFIG=$(env | grep ^HOME= | cut -c 6-)"/hugegraph-download-url-prefix"
function print_usage() {
echo "USAGE: $0 -v {hugegraph-version} -p {install-path} [-u {download-path-prefix}]"
@@ -41,49 +41,49 @@ if [[ "$VERSION" = "" || "$INSTALL_PATH" = "" ]]; then
fi
if [[ "$DOWNLOAD_LINK_PREFIX" = "" ]]; then
- if [ -f ${DOWNLOAD_LINK_PREFIX_CONFIG} ]; then
- DOWNLOAD_LINK_PREFIX=`sed -n "1p" ${DOWNLOAD_LINK_PREFIX_CONFIG}`
+ if [ -f "${DOWNLOAD_LINK_PREFIX_CONFIG}" ]; then
+ DOWNLOAD_LINK_PREFIX=$(sed -n "1p" "${DOWNLOAD_LINK_PREFIX_CONFIG}")
else
DOWNLOAD_LINK_PREFIX=${DEFAULT_DOWNLOAD_LINK_PREFIX}
fi
else
- echo ${DOWNLOAD_LINK_PREFIX} > ${DOWNLOAD_LINK_PREFIX_CONFIG}
+ echo ${DOWNLOAD_LINK_PREFIX} >"${DOWNLOAD_LINK_PREFIX_CONFIG}"
fi
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
-. ${BIN}/util.sh
+BIN=$(abs_path)
+. "${BIN}"/util.sh
-`ensure_path_writable ${INSTALL_PATH}`
+ensure_path_writable "${INSTALL_PATH}"
# Convert to absolute path
-INSTALL_PATH="$(cd ${INSTALL_PATH} && pwd)"
+INSTALL_PATH="$(cd "${INSTALL_PATH}" && pwd)"
-cd ${BIN}
+cd "${BIN}" || exit
# Check input version can be found in version-map.yaml
-OPTIONAL_VERSIONS=`cat version-map.yaml | grep 'version' | awk -F ':' '{print $1}' | xargs`
-if [[ ! "$OPTIONAL_VERSIONS" =~ "$VERSION" ]]; then
+OPTIONAL_VERSIONS=$(cat version-map.yaml | grep 'version' | awk -F ':' '{print $1}' | xargs)
+if [[ ! "$OPTIONAL_VERSIONS" =~ $VERSION ]]; then
echo "Invalid version '${VERSION}' for hugegraph, the optional values are [$OPTIONAL_VERSIONS]"
exit 1
fi
# Parse module version from 'version-map.yaml'
-SERVER_VERSION=`parse_yaml version-map.yaml "${VERSION}" "server"`
+SERVER_VERSION=$(parse_yaml version-map.yaml "${VERSION}" "server")
if [ "$SERVER_VERSION" = "" ]; then
echo "Not found the key '$VERSION.server' in version-map.yaml"
exit 1
fi
-STUDIO_VERSION=`parse_yaml version-map.yaml "${VERSION}" "studio"`
+STUDIO_VERSION=$(parse_yaml version-map.yaml "${VERSION}" "studio")
if [ "$STUDIO_VERSION" = "" ]; then
echo "Not found the key '$VERSION.studio' in version-map.yaml"
exit 1
@@ -103,29 +103,29 @@ STUDIO_TAR=${STUDIO_DIR}${ARCHIVE_FORMAT}
SERVER_DOWNLOAD_URL="${DOWNLOAD_LINK_PREFIX}/hugegraph/releases/download/v${SERVER_VERSION}/${SERVER_TAR}"
STUDIO_DOWNLOAD_URL="${DOWNLOAD_LINK_PREFIX}/hugegraph-studio/releases/download/v${STUDIO_VERSION}/${STUDIO_TAR}"
-ensure_package_exist $INSTALL_PATH $SERVER_DIR $SERVER_TAR $SERVER_DOWNLOAD_URL
-ensure_package_exist $INSTALL_PATH $STUDIO_DIR $STUDIO_TAR $STUDIO_DOWNLOAD_URL
+ensure_package_exist "$INSTALL_PATH" "$SERVER_DIR" "$SERVER_TAR" "$SERVER_DOWNLOAD_URL"
+ensure_package_exist "$INSTALL_PATH" "$STUDIO_DIR" "$STUDIO_TAR" "$STUDIO_DOWNLOAD_URL"
-IP=`get_ip`
+IP=$(get_ip)
function config_hugegraph_server() {
local rest_server_conf="$SERVER_DIR/conf/rest-server.properties"
local server_url="http://$IP:8080"
- write_property $rest_server_conf "restserver\.url" $server_url
+ write_property "$rest_server_conf" "restserver\.url" "$server_url"
}
function config_hugegraph_studio() {
local studio_server_conf="$STUDIO_DIR/conf/hugegraph-studio.properties"
- write_property $studio_server_conf "studio\.server\.host" $IP
- write_property $studio_server_conf "graph\.server\.host" $IP
+ write_property "$studio_server_conf" "studio\.server\.host" "$IP"
+ write_property "$studio_server_conf" "graph\.server\.host" "$IP"
}
-cd ${INSTALL_PATH}
+cd "${INSTALL_PATH}" || exit
config_hugegraph_server
config_hugegraph_studio
-${SERVER_DIR}/bin/init-store.sh
+"${SERVER_DIR}"/bin/init-store.sh
-${BIN}/start-all.sh -v ${VERSION} -p ${INSTALL_PATH}
+"${BIN}"/start-all.sh -v "${VERSION}" -p "${INSTALL_PATH}"
diff --git a/hugegraph-tools/assembly/bin/hugegraph b/hugegraph-tools/assembly/bin/hugegraph
index 3a2635c2..2151a2eb 100755
--- a/hugegraph-tools/assembly/bin/hugegraph
+++ b/hugegraph-tools/assembly/bin/hugegraph
@@ -27,20 +27,20 @@
abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
+BIN=$(abs_path)
TOP="$(cd $BIN/../ && pwd)"
LIB=$TOP/lib:$JAVA_HOME/lib/ext:$JAVA_HOME/jre/lib/ext
-. $BIN/util.sh
+. "$BIN"/util.sh
-MAX_MEM=$[96*1024]
+MAX_MEM=$((96 * 1024))
MIN_MEM=512
if [ -n "$JAVA_HOME" ]; then
@@ -52,19 +52,19 @@ fi
if [ "$1" == "deploy" ]; then
shift
- bash $BIN/deploy.sh $@
+ bash $BIN/deploy.sh "$@"
exit $?
fi
if [ "$1" == "start-all" ]; then
shift
- bash $BIN/start-all.sh $@
+ bash $BIN/start-all.sh "$@"
exit $?
fi
if [ "$1" == "clear" ]; then
shift
- bash $BIN/clear.sh $@
+ bash $BIN/clear.sh "$@"
exit $?
fi
@@ -74,58 +74,57 @@ if [ "$1" == "stop-all" ]; then
fi
# Set default environment variables if not exist
-echo $* | grep "\--url" > /dev/null 2>&1
-if [ $? -ne 0 -a -n "$HUGEGRAPH_URL" ]; then
+echo "$@" | grep "\--url" >/dev/null 2>&1
+if [ $? -ne 0 ] && [ -n "$HUGEGRAPH_URL" ]; then
URL_ARG="--url $HUGEGRAPH_URL"
else
URL_ARG=""
fi
-echo $* | grep "\--graph " > /dev/null 2>&1
-if [ $? -ne 0 -a -n "$HUGEGRAPH_GRAPH" ]; then
+echo "$@" | grep "\--graph " >/dev/null 2>&1
+if [ $? -ne 0 ] && [ -n "$HUGEGRAPH_GRAPH" ]; then
GRAPH_ARG="--graph $HUGEGRAPH_GRAPH"
else
GRAPH_ARG=""
fi
-echo $* | grep "\--user" > /dev/null 2>&1
-if [ $? -ne 0 -a -n "$HUGEGRAPH_USERNAME" ]; then
+echo "$@" | grep "\--user" >/dev/null 2>&1
+if [ $? -ne 0 ] && [ -n "$HUGEGRAPH_USERNAME" ]; then
USER_ARG="--user $HUGEGRAPH_USERNAME"
else
USER_ARG=""
fi
-echo $* | grep "\--password" > /dev/null 2>&1
-if [ $? -ne 0 -a -n "$HUGEGRAPH_PASSWORD" ]; then
+echo "$@" | grep "\--password" >/dev/null 2>&1
+if [ $? -ne 0 ] && [ -n "$HUGEGRAPH_PASSWORD" ]; then
PASSWORD_ARG="--password $HUGEGRAPH_PASSWORD"
else
PASSWORD_ARG=""
fi
-echo $* | grep "\--timeout" > /dev/null 2>&1
+echo $* | grep "\--timeout" >/dev/null 2>&1
if [ $? -ne 0 -a -n "$HUGEGRAPH_TIMEOUT" ]; then
TIMEOUT_ARG="--timeout $HUGEGRAPH_TIMEOUT"
else
TIMEOUT_ARG=""
fi
-echo $* | grep "\--trust-store-file" > /dev/null 2>&1
+echo $* | grep "\--trust-store-file" >/dev/null 2>&1
if [ $? -ne 0 -a -n "$HUGEGRAPH_TRUST_STORE_FILE" ]; then
TRUST_STORE_FILE_ARG="--trust-store-file $HUGEGRAPH_TRUST_STORE_FILE"
else
TRUST_STORE_FILE_ARG=""
fi
-echo $* | grep "\--trust-store-password" > /dev/null 2>&1
+echo $* | grep "\--trust-store-password" >/dev/null 2>&1
if [ $? -ne 0 -a -n "$HUGEGRAPH_TRUST_STORE_PASSWORD" ]; then
TRUST_STORE_PASSWORD_ARG="--trust-store-password $HUGEGRAPH_TRUST_STORE_PASSWORD"
else
TRUST_STORE_PASSWORD_ARG=""
fi
-for ((i=1;i<=$#;i++));
-do
- if [ "`eval echo '$'"$i"`" == "schedule-backup" ]; then
+for ((i = 1; i <= $#; i++)); do
+ if [ "$(eval echo '$'"$i")" == "schedule-backup" ]; then
ARGS=${*//schedule-backup/}
bash $BIN/schedule-backup.sh $URL_ARG $GRAPH_ARG $USER_ARG $PASSWORD_ARG $TIMEOUT_ARG $TRUST_STORE_FILE_ARG $TRUST_STORE_PASSWORD_ARG ${ARGS//'*'/'\*'}
exit $?
@@ -133,8 +132,8 @@ do
done
# Set Java options
-if [ "$JAVA_OPTIONS" = "" ] ; then
- XMX=`calc_xmx $MIN_MEM $MAX_MEM`
+if [ "$JAVA_OPTIONS" = "" ]; then
+ XMX=$(calc_xmx $MIN_MEM $MAX_MEM)
if [ $? -ne 0 ]; then
echo "Failed to run bin/hugegraph, requires at least ${MIN_MEM}m free memory"
exit 1
@@ -142,5 +141,13 @@ if [ "$JAVA_OPTIONS" = "" ] ; then
JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m"
fi
-exec $JAVA -Dtools.home.path=${TOP} $JAVA_OPTIONS -cp $LIB/hugegraph-tools-*.jar -Djava.ext.dirs=$LIB/ \
-org.apache.hugegraph.cmd.HugeGraphCommand $URL_ARG $GRAPH_ARG $USER_ARG $PASSWORD_ARG $TIMEOUT_ARG $TRUST_STORE_FILE_ARG $TRUST_STORE_PASSWORD_ARG "$@"
+# TODO: use xx=(/path/to/*.jar) instead
+tools_ext_jar_path=$LIB/hugegraph-tools-*.jar
+for i in "$LIB"/*.jar; do
+ tools_ext_jar_path=$tools_ext_jar_path:$i
+ export tools_ext_jar_path
+done
+
+exec $JAVA -Dtools.home.path=${TOP} $JAVA_OPTIONS -cp $tools_ext_jar_path \
+ org.apache.hugegraph.cmd.HugeGraphCommand $URL_ARG $GRAPH_ARG $USER_ARG $PASSWORD_ARG \
+ $TIMEOUT_ARG $TRUST_STORE_FILE_ARG $TRUST_STORE_PASSWORD_ARG "$@"
diff --git a/hugegraph-tools/assembly/bin/release.sh b/hugegraph-tools/assembly/bin/release.sh
index 2732429a..b3869329 100755
--- a/hugegraph-tools/assembly/bin/release.sh
+++ b/hugegraph-tools/assembly/bin/release.sh
@@ -40,18 +40,18 @@ fi
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
function ensure_path_writable() {
local path=$1
# Ensure input path exist
if [ ! -d "${path}" ]; then
- mkdir -p ${path}
+ mkdir -p "${path}"
if [ $? -ne 0 ]; then
echo "Failed to mkdir $path"
exit 1
@@ -69,7 +69,7 @@ function replace() {
from=$2
to=$3
- local os=`uname`
+ local os=$(uname)
case $os in
Darwin) sed -i '' "s!$from!$to!g" "$file" >/dev/null 2>&1 ;;
*) sed -i "s!$from!$to!g" "$file" >/dev/null 2>&1 ;;
@@ -79,7 +79,7 @@ function replace() {
# Ensure the project dir is valid
ensure_path_writable $PROJECT_DIR
-cd $PROJECT_DIR
+cd $PROJECT_DIR || exit
################################################################################
# Checkout release branch
@@ -92,7 +92,7 @@ fi
git diff --quiet HEAD
if [ $? -ne 0 ]; then
- echo "There are uncommited changes in branch $BASE_BRANCH"
+ echo "There are uncommitted changes in branch $BASE_BRANCH"
exit 1
fi
@@ -113,14 +113,14 @@ fi
# Modify README.md
################################################################################
README="README.md"
-RELEASE_VERSION=`cat "pom.xml" | grep "<version>" | head -1 | awk -F '<|>' '{print $3}'`
+RELEASE_VERSION=$(cat "pom.xml" | grep "<version>" | head -1 | awk -F '<|>' '{print $3}')
function update_readme_maven_version() {
# Append version to maven repository link
# Extract the Maven Central line, then split the badge and dependency link
- MAVEN_LINK_LINE=`cat $README | grep 'Maven Central'`
- OLD_MAVEN_BADGE_LINK=`echo $MAVEN_LINK_LINE | awk -F '[\\(|\\)]' '{print $2}'`
- OLD_MAVEN_DEPEN_LINK=`echo $MAVEN_LINK_LINE | awk -F '[\\(|\\)]' '{print $4}'`
+ MAVEN_LINK_LINE=$(cat $README | grep 'Maven Central')
+ OLD_MAVEN_BADGE_LINK=$(echo $MAVEN_LINK_LINE | awk -F '[\\(|\\)]' '{print $2}')
+ OLD_MAVEN_DEPEN_LINK=$(echo $MAVEN_LINK_LINE | awk -F '[\\(|\\)]' '{print $4}')
# Replace or append the branch name in maven badge link
if [[ "$OLD_MAVEN_BADGE_LINK" =~ .*\?version=.* ]]; then
@@ -156,17 +156,17 @@ if [ ! -f "$README" ]; then
echo "Skipping modify $README"
else
echo "Checkout to branch $RELEASE_BRANCH, ready to modify $README"
- if [ `grep -c "Build Status" "$README"` -eq 1 ]; then
+ if [ $(grep -c "Build Status" "$README") -eq 1 ]; then
# Replace old branch with new
replace $README "branch=$BASE_BRANCH" "branch=$RELEASE_BRANCH"
check_update_readme_status "Build Status" $?
fi
- if [ `grep -c "codecov" "$README"` -eq 1 ]; then
+ if [ $(grep -c "codecov" "$README") -eq 1 ]; then
# Replace old branch with new
replace $README "branch/$BASE_BRANCH" "branch/$RELEASE_BRANCH"
check_update_readme_status "codecov" $?
fi
- if [ `grep -c "Maven Central" "$README"` -eq 1 ]; then
+ if [ $(grep -c "Maven Central" "$README") -eq 1 ]; then
update_readme_maven_version
check_update_readme_status "Maven Central" $?
fi
@@ -186,32 +186,32 @@ fi
################################################################################
function update_hugegraph_version() {
# Second digit plus 1
- BUMP_VERSION=`echo $RELEASE_VERSION | awk -F '.' '{prefix=$2}END{print $1"."prefix+1".0"}'`
+ BUMP_VERSION=$(echo $RELEASE_VERSION | awk -F '.' '{prefix=$2}END{print $1"."prefix+1".0"}')
CORE_POM_XML_FILE="$PROJECT_DIR/hugegraph-core/pom.xml"
CORE_VERSION_JAVA_FILE="$PROJECT_DIR/hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java"
API_VERSION_JAVA_FILE="$PROJECT_DIR/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java"
# Replace Implementation-Version in core pom.xml
replace $CORE_POM_XML_FILE "<Implementation-Version>.*</Implementation-Version>" \
- "<Implementation-Version>$BUMP_VERSION.0</Implementation-Version>" || return 1
+ "<Implementation-Version>$BUMP_VERSION.0</Implementation-Version>" || return 1
# Replace version in CoreVersion.java
replace $CORE_VERSION_JAVA_FILE "Version.of(CoreVersion.class, \".*\")" \
- "Version.of(CoreVersion.class, \"$BUMP_VERSION\")" || return 1
+ "Version.of(CoreVersion.class, \"$BUMP_VERSION\")" || return 1
# Replace version in ApiVersion.java
# Extract the first two digits of the version number
- MIN_VERSION=`echo $BUMP_VERSION | awk -F '.' '{print $1"."$2}'`
+ MIN_VERSION=$(echo $BUMP_VERSION | awk -F '.' '{print $1"."$2}')
# Second digit plus 1
- MAX_VERSION=`echo $BUMP_VERSION | awk -F '.' '{prefix=$2}END{print $1"."prefix+1}'`
+ MAX_VERSION=$(echo $BUMP_VERSION | awk -F '.' '{prefix=$2}END{print $1"."prefix+1}')
replace $API_VERSION_JAVA_FILE "VersionUtil.check(CoreVersion.VERSION, \".*\", \".*\", CoreVersion.NAME);" \
- "VersionUtil.check(CoreVersion.VERSION, \"$MIN_VERSION\", \"$MAX_VERSION\", CoreVersion.NAME);" || return 1
+ "VersionUtil.check(CoreVersion.VERSION, \"$MIN_VERSION\", \"$MAX_VERSION\", CoreVersion.NAME);" || return 1
}
function update_general_component_version() {
# Third digit plus 1
- BUMP_VERSION=`echo $RELEASE_VERSION | awk -F '.' '{prefix=$3}END{print $1"."$2"."prefix+1}'`
+ BUMP_VERSION=$(echo $RELEASE_VERSION | awk -F '.' '{prefix=$3}END{print $1"."$2"."prefix+1}')
POM_XML_FILE="$PROJECT_DIR/pom.xml"
# Replace Implementation-Version in pom.xml
replace $POM_XML_FILE "<Implementation-Version>.*</Implementation-Version>" \
- "<Implementation-Version>$BUMP_VERSION.0</Implementation-Version>" || return 1
+ "<Implementation-Version>$BUMP_VERSION.0</Implementation-Version>" || return 1
}
function check_update_version_status() {
@@ -230,7 +230,7 @@ git checkout $BASE_BRANCH >/dev/null 2>&1 || exit 1
echo "Checkout to branch $BASE_BRANCH, ready to bump pom version"
if [ -f "pom.xml" ]; then
- ARTIFACT=`cat "pom.xml" | grep "<artifactId>" | head -1 | awk -F '<|>' '{print $3}'`
+ ARTIFACT=$(cat "pom.xml" | grep "<artifactId>" | head -1 | awk -F '<|>' '{print $3}')
# Bump up maven implementation version
if [ "$ARTIFACT" = "hugegraph" ]; then
update_hugegraph_version
diff --git a/hugegraph-tools/assembly/bin/schedule-backup.sh b/hugegraph-tools/assembly/bin/schedule-backup.sh
index bd6b480a..7318dc88 100755
--- a/hugegraph-tools/assembly/bin/schedule-backup.sh
+++ b/hugegraph-tools/assembly/bin/schedule-backup.sh
@@ -25,10 +25,11 @@ function abs_path() {
echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}
-BIN=`abs_path`
-TOP=`dirname $BIN`
-cd $BIN
+BIN=$(abs_path)
+TOP=$(dirname "$BIN")
+cd "$BIN" || exit
+# TODO: $JAVA is unused now
if [ -n "$JAVA_HOME" ]; then
JAVA="$JAVA_HOME"/bin/java
else
@@ -41,43 +42,43 @@ function parse_interval() {
for((i=1;i<=$#;i+=2));
do
- current=`eval echo '${'$i'}'`
+ current=$(eval echo '${'"$i"'}')
case "$current" in
"--url")
- URL=`eval echo '${'$(($i+1))'}'`
+ URL=$(eval echo '${'$((i+1))'}')
URL_ARG="--url "$URL
;;
"--graph")
- GRAPH=`eval echo '${'$(($i+1))'}'`
+ GRAPH=$(eval echo '${'$((i+1))'}')
GRAPH_ARG="--graph "$GRAPH
;;
"--user")
- USERNAME=`eval echo '${'$(($i+1))'}'`
+ USERNAME=$(eval echo '${'$((i+1))'}')
USERNAME_ARG="--user "$USERNAME
;;
"--password")
- PASSWORD=`eval echo '${'$(($i+1))'}'`
+ PASSWORD=$(eval echo '${'$((i+1))'}')
PASSWORD_ARG="--password "$PASSWORD
;;
"--timeout")
- TIMEOUT=`eval echo '${'$(($i+1))'}'`
+ TIMEOUT=$(eval echo '${'$((i+1))'}')
TIMEOUT_ARG="--timeout "$TIMEOUT
;;
"--interval")
- position=$(($i+1))
+ position=$((i+1))
INTERVAL=${@:$position:5}
INTERVAL=${INTERVAL//\\/}
- let i+=4
+ (( i+=4 ))
;;
"--backup-num")
- NUM=`eval echo '${'$(($i+1))'}'`
+ NUM=$(eval echo '${'$((i+1))'}')
;;
"--directory"|"-d")
- DIR=`eval echo '${'$(($i+1))'}'`
+ DIR=$(eval echo '${'$((i+1))'}')
;;
*)
echo "Invalid argument: $current"
- bash $BIN/hugegraph
+ bash "$BIN"/hugegraph
exit 1
esac
done
@@ -86,12 +87,12 @@ if [ -z "$DIR" ]; then
echo "Must provide backup directory"
exit 1
else
- if [ ${DIR:0:1} != "/" ]; then
+ if [ "${DIR:0:1}" != "/" ]; then
DIR=$TOP"/"$DIR
fi
fi
-DIR=`dirname $DIR`/`basename $DIR`
+DIR=$(dirname $DIR)/$(basename $DIR)
if [ -z "$GRAPH" ]; then
GRAPH="hugegraph"
diff --git a/hugegraph-tools/assembly/bin/start-all.sh b/hugegraph-tools/assembly/bin/start-all.sh
index 48330d28..2e3c1b54 100755
--- a/hugegraph-tools/assembly/bin/start-all.sh
+++ b/hugegraph-tools/assembly/bin/start-all.sh
@@ -39,37 +39,37 @@ fi
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
-. ${BIN}/util.sh
+BIN=$(abs_path)
+. "${BIN}"/util.sh
-`ensure_path_writable ${INSTALL_PATH}`
+ensure_path_writable "${INSTALL_PATH}"
# Convert to absolute path
INSTALL_PATH="$(cd ${INSTALL_PATH} && pwd)"
-cd ${BIN}
+cd ${BIN} || exit
# Check input version can be found in version-map.yaml
-OPTIONAL_VERSIONS=`cat version-map.yaml | grep 'version' | awk -F ':' '{print $1}' | xargs`
-if [[ ! "$OPTIONAL_VERSIONS" =~ "$VERSION" ]]; then
+OPTIONAL_VERSIONS=$(cat version-map.yaml | grep 'version' | awk -F ':' '{print $1}' | xargs)
+if [[ ! "$OPTIONAL_VERSIONS" =~ $VERSION ]]; then
echo "Invalid version '${VERSION}' for hugegraph, the optional values are [$OPTIONAL_VERSIONS]"
exit 1
fi
# Parse module version from 'version-map.yaml'
-SERVER_VERSION=`parse_yaml version-map.yaml "${VERSION}" "server"`
+SERVER_VERSION=$(parse_yaml version-map.yaml "${VERSION}" "server")
if [ "$SERVER_VERSION" = "" ]; then
echo "Please check the format and content of file 'version-map.yaml' is normal"
exit 1
fi
-STUDIO_VERSION=`parse_yaml version-map.yaml "${VERSION}" "studio"`
+STUDIO_VERSION=$(parse_yaml version-map.yaml "${VERSION}" "studio")
if [ "$STUDIO_VERSION" = "" ]; then
echo "Please check the format and content of file 'version-map.yaml' is normal"
exit 1
@@ -89,7 +89,7 @@ if [ ! -d "${STUDIO_DIR}" ]; then
fi
function start_hugegraph_server() {
- $SERVER_DIR/bin/start-hugegraph.sh
+ "$SERVER_DIR"/bin/start-hugegraph.sh
if [ $? -ne 0 ]; then
echo "Failed to start HugeGraphServer, please check the logs under '$SERVER_DIR/logs' for details"
exit 1
@@ -98,10 +98,10 @@ function start_hugegraph_server() {
function start_hugegraph_studio() {
# TODO: Let hugegraph-studio.sh can execute in any directory instead of $STUDIO_DIR
- cd $STUDIO_DIR
+ cd $STUDIO_DIR || exit
- local server_host=`read_property "conf/hugegraph-studio.properties" "studio.server.host"`
- local server_port=`read_property "conf/hugegraph-studio.properties" "studio.server.port"`
+ local server_host=$(read_property "conf/hugegraph-studio.properties" "studio.server.host")
+ local server_port=$(read_property "conf/hugegraph-studio.properties" "studio.server.port")
local server_url="http://${server_host}:${server_port}"
local start_timeout_s=20
diff --git a/hugegraph-tools/assembly/bin/stop-all.sh b/hugegraph-tools/assembly/bin/stop-all.sh
index ef7328dd..ce397ec3 100755
--- a/hugegraph-tools/assembly/bin/stop-all.sh
+++ b/hugegraph-tools/assembly/bin/stop-all.sh
@@ -18,22 +18,22 @@
function abs_path() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
- echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+ echo "$(cd -P "$(dirname "$SOURCE")" && pwd)"
}
-BIN=`abs_path`
-cd $BIN
+BIN=$(abs_path)
+cd "$BIN" || exit
. util.sh
SLEEP_INTERVAL_S=2
SHUTDOWN_TIMEOUT_S=10
-kill_process 'HugeGraphServer'
+kill_process 'HugeGraphServer'
wait_for_shutdown 'HugeGraphServer' $SHUTDOWN_TIMEOUT_S
-kill_process 'HugeGraphStudio'
+kill_process 'HugeGraphStudio'
wait_for_shutdown 'HugeGraphStudio' $SHUTDOWN_TIMEOUT_S
diff --git a/hugegraph-tools/assembly/bin/util.sh b/hugegraph-tools/assembly/bin/util.sh
index a32a85d1..7d00cb83 100755
--- a/hugegraph-tools/assembly/bin/util.sh
+++ b/hugegraph-tools/assembly/bin/util.sh
@@ -28,7 +28,7 @@ function read_property() {
# file path
file_name=$1
# replace "." to "\."
- property_name=`echo $2 | sed 's/\./\\\./g'`
+ property_name=$(echo $2 | sed 's/\./\\\./g')
cat $file_name | sed -n -e "s/^[ ]*//g;/^#/d;s/^$property_name=//p" | tail -1
}
@@ -37,13 +37,13 @@ function write_property() {
local key=$2
local value=$3
- local os=`uname`
+ local os=$(uname)
case $os in
- # Note: in mac os should use sed -i '' "xxx" to replace string,
- # otherwise prompt 'command c expects \ followed by text'.
- # See http://www.cnblogs.com/greedy-day/p/5952899.html
- Darwin) sed -i '' "s!$key=.*!$key=$value!g" "$file" ;;
- *) sed -i "s!$key=.*!$key=$value!g" "$file" ;;
+ # Note: in mac os should use sed -i '' "xxx" to replace string,
+ # otherwise prompt 'command c expects \ followed by text'.
+ # See http://www.cnblogs.com/greedy-day/p/5952899.html
+ Darwin) sed -i '' "s!$key=.*!$key=$value!g" "$file" ;;
+ *) sed -i "s!$key=.*!$key=$value!g" "$file" ;;
esac
}
@@ -52,7 +52,7 @@ function parse_yaml() {
local version=$2
local module=$3
- cat $file | tr -d '\n {}'| awk -F',+|:' '''{
+ cat $file | tr -d '\n {}' | awk -F',+|:' '''{
pre="";
for(i=1; i<=NF; ) {
if(match($i, /version/)) {
@@ -63,23 +63,23 @@ function parse_yaml() {
i+=2
}
}
- } END {for(e in result) {print e": "result[e]}}''' \
- | grep "$version-$module" | awk -F':' '{print $2}' | tr -d ' ' && echo
+ } END {for(e in result) {print e": "result[e]}}''' |
+ grep "$version-$module" | awk -F':' '{print $2}' | tr -d ' ' && echo
}
function process_num() {
- num=`ps -ef | grep $1 | grep -v grep | wc -l`
+ num=$(ps -ef | grep $1 | grep -v grep | wc -l)
return $num
}
function process_id() {
- pid=`ps -ef | grep $1 | grep -v grep | awk '{print $2}'`
+ pid=$(ps -ef | grep $1 | grep -v grep | awk '{print $2}')
return $pid
}
# check the port of rest server is occupied
function check_port() {
- local port=`echo $1 | awk -F':' '{print $3}'`
+ local port=$(echo $1 | awk -F':' '{print $3}')
if ! command_available "lsof"; then
echo "Required lsof but it is unavailable"
exit 1
@@ -99,7 +99,10 @@ function crontab_append() {
if [ $? -eq 0 ]; then
return 1
fi
- (crontab -l ; echo "$job") | crontab -
+ (
+ crontab -l
+ echo "$job"
+ ) | crontab -
}
function crontab_remove() {
@@ -110,7 +113,7 @@ function crontab_remove() {
return 0
fi
- crontab -l | grep -Fv "$job" | crontab -
+ crontab -l | grep -Fv "$job" | crontab -
# Check exist after remove
crontab -l | grep -F "$job" >/dev/null 2>&1
@@ -127,21 +130,21 @@ function wait_for_startup() {
local server_url="$2"
local timeout_s="$3"
- local now_s=`date '+%s'`
- local stop_s=$(( $now_s + $timeout_s ))
+ local now_s=$(date '+%s')
+ local stop_s=$((now_s + timeout_s))
local status
echo -n "Connecting to $server_name ($server_url)"
while [ $now_s -le $stop_s ]; do
echo -n .
- status=`curl -o /dev/null -s -w %{http_code} $server_url`
+ status=$(curl -o /dev/null -s -w %{http_code} $server_url)
if [ $status -eq 200 ]; then
echo "OK"
return 0
fi
sleep 2
- now_s=`date '+%s'`
+ now_s=$(date '+%s')
done
echo "The operation timed out when attempting to connect to $server_url" >&2
@@ -150,22 +153,22 @@ function wait_for_startup() {
function free_memory() {
local free=""
- local os=`uname`
+ local os=$(uname)
if [ "$os" == "Linux" ]; then
- local mem_free=`cat /proc/meminfo | grep -w "MemFree" | awk '{print $2}'`
- local mem_buffer=`cat /proc/meminfo | grep -w "Buffers" | awk '{print $2}'`
- local mem_cached=`cat /proc/meminfo | grep -w "Cached" | awk '{print $2}'`
+ local mem_free=$(cat /proc/meminfo | grep -w "MemFree" | awk '{print $2}')
+ local mem_buffer=$(cat /proc/meminfo | grep -w "Buffers" | awk '{print $2}')
+ local mem_cached=$(cat /proc/meminfo | grep -w "Cached" | awk '{print $2}')
if [[ "$mem_free" == "" || "$mem_buffer" == "" || "$mem_cached" == "" ]]; then
echo "Failed to get free memory"
exit 1
fi
- free=`expr $mem_free + $mem_buffer + $mem_cached`
- free=`expr $free / 1024`
+ free=$(expr $mem_free + $mem_buffer + $mem_cached)
+ free=$(expr $free / 1024)
elif [ "$os" == "Darwin" ]; then
- local pages_free=`vm_stat | awk '/Pages free/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
- local pages_inactive=`vm_stat | awk '/Pages inactive/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
- local pages_available=`expr $pages_free + $pages_inactive`
- free=`expr $pages_available \* 4096 / 1024 / 1024`
+ local pages_free=$(vm_stat | awk '/Pages free/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " ")
+ local pages_inactive=$(vm_stat | awk '/Pages inactive/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " ")
+ local pages_available=$(expr $pages_free + $pages_inactive)
+ free=$(expr $pages_available \* 4096 / 1024 / 1024)
else
echo "Unsupported operating system $os"
exit 1
@@ -177,8 +180,8 @@ function calc_xmx() {
local min_mem=$1
local max_mem=$2
# Get machine available memory
- local free=`free_memory`
- local half_free=$[free/2]
+ local free=$(free_memory)
+ local half_free=$((free / 2))
local xmx=$min_mem
if [[ "$free" -lt "$min_mem" ]]; then
@@ -226,29 +229,29 @@ function ensure_path_writable() {
}
function get_ip() {
- local os=`uname`
+ local os=$(uname)
local loopback="127.0.0.1"
local ip=""
case $os in
Linux)
if command_available "ifconfig"; then
- ip=`ifconfig | grep 'inet addr:' | grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}'`
+ ip=$(ifconfig | grep 'inet addr:' | grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}')
elif command_available "ip"; then
- ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}'`
+ ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}')
else
ip=$loopback
fi
;;
FreeBSD|OpenBSD|Darwin)
if command_available "ifconfig"; then
- ip=`ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}'`
+ ip=$(ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}')
else
ip=$loopback
fi
;;
SunOS)
if command_available "ifconfig"; then
- ip=`ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} '`
+ ip=$(ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} ')
else
ip=$loopback
fi
@@ -306,8 +309,8 @@ function wait_for_shutdown() {
local p_name="$1"
local timeout_s="$2"
- local now_s=`date '+%s'`
- local stop_s=$(( $now_s + $timeout_s ))
+ local now_s=$(date '+%s')
+ local stop_s=$((now_s + timeout_s))
while [ $now_s -le $stop_s ]; do
process_status "$p_name" >/dev/null
@@ -316,7 +319,7 @@ function wait_for_shutdown() {
return 0
fi
sleep 2
- now_s=`date '+%s'`
+ now_s=$(date '+%s')
done
echo "$p_name shutdown timeout(exceeded $timeout_s seconds)" >&2
@@ -324,7 +327,7 @@ function wait_for_shutdown() {
}
function process_status() {
- local p=`ps -ef | grep "$1" | grep -v grep | awk '{print $2}'`
+ local p=$(ps -ef | grep "$1" | grep -v grep | awk '{print $2}')
if [ -n "$p" ]; then
echo "$1 is running with pid $p"
return 0
@@ -335,20 +338,19 @@ function process_status() {
}
function kill_process() {
- local pids=`ps -ef | grep "$1" | grep -v grep | awk '{print $2}' | xargs`
+ local pids=$(ps -ef | grep "$1" | grep -v grep | awk '{print $2}' | xargs)
if [ "$pids" = "" ]; then
echo "There is no $1 process"
fi
- for pid in ${pids[@]}
- do
+ for pid in "${pids[@]}"; do
if [ -z "$pid" ]; then
echo "The process $1 does not exist"
return
fi
echo "Killing $1 (pid $pid)..." >&2
- case "`uname`" in
+ case "$(uname)" in
CYGWIN*) taskkill /F /PID "$pid" ;;
*) kill "$pid" ;;
esac
diff --git a/hugegraph-tools/build.sh b/hugegraph-tools/build.sh
deleted file mode 100644
index 24e65521..00000000
--- a/hugegraph-tools/build.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-export MAVEN_HOME="/home/scmtools/buildkit/maven/apache-maven-3.3.9/"
-export JAVA_HOME="/home/scmtools/buildkit/java/jdk1.8.0_25/"
-export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
-
-mvn clean compile
\ No newline at end of file