#!/bin/bash echo "\ =================================================== MiaozhenProbe Installation =================================================== " # 脚本所在目录 绝对路径 ROOT_PATH="/home/smart/SmartOrganizer" . ${ROOT_PATH}/lib.conf PACKAGE_PATH="/home/Miaozhen" PACKAGE_NAME="MiaozhenProbe" SERVICE_NAME="MiaozhenProbeService" CURRENT_VERSION="" TARGET_VERSION="${1}" if [[ -z ${TARGET_VERSION} ]]; then echo "Argument: TARGET_VERSION is needed!" exit 2 fi #version_compare() #{ # source=(${1//./ }) # target=(${2//./ }) # for ((i=0; i<${#source[@]}; i++)); do # if [[ ${source[i]} == ${target[i]} ]]; then # continue # fi # # if [[ ${source[i]} -lt ${target[i]} ]]; then # echo -1 # return # elif [[ ${source[i]} -gt ${target[i]} ]]; then # echo 1 # return # fi # done # echo 0 #} #PACKAGE_URL="http://axis-config.oss-cn-beijing.aliyuncs.com/MiaozhenProbe/MiaozhenProbe.jar" # Create working path #echo "Create working path ${PACKAGE_PATH}" #mkdir -p ${PACKAGE_PATH} pushd ${PACKAGE_PATH} > /dev/null if [[ -f ".version" ]]; then CURRENT_VERSION="$(cat .version)" fi if [[ -n ${CURRENT_VERSION} ]]; then echo "current_version:"${CURRENT_VERSION}" target_version:"${TARGET_VERSION} if [[ $(version_compare ${CURRENT_VERSION} ${TARGET_VERSION}) != -1 ]]; then echo "No upgrade required" popd > /dev/null exit 2 fi fi echo "Upgrade start >>>" # Download #echo "Downloading [ MiaozhenProbe.jar ] from [ ${PACKAGE_URL} ] ..." #wget -q ${PACKAGE_URL} -O ./${PACKAGE_NAME}.jar #echo "Download ... successed!" \cp -r ${PACKAGE_PATH}/repo/last/. ${PACKAGE_PATH} chmod og+x ${PACKAGE_NAME}.jar echo "USE_START_STOP_DAEMON=false" > ${PACKAGE_NAME}.conf if [[ $(getSystemVersion ) -eq 6 ]]; then # Add to system service and auto startup chkconfig ${SERVICE_NAME} off chkconfig --del ${SERVICE_NAME} rm -f /etc/init.d/${SERVICE_NAME} echo "Register to system service ... successed!" ln -s /home/Miaozhen/${PACKAGE_NAME}.jar /etc/init.d/${SERVICE_NAME} chkconfig --add ${SERVICE_NAME} chkconfig ${SERVICE_NAME} on echo "Register to auto start ... successed!" # startup echo "Start service ... successed!" # service ${SERVICE_NAME} restart # set self-starting netstat -anp | grep ${SERVICE_NAME} &> /dev/null if [[ $? -ne 0 ]]; then cat > ${PACKAGE_PATH}/startup.sh < /dev/null 2>&1 & chmod 777 /home/Miaozhen/logs/*.log EOF chmod og+x ${PACKAGE_PATH}/startup.sh echo "sh /home/Miaozhen/startup.sh" >> /etc/rc.local fi else # Add to system service and auto startup systemctl stop ${SERVICE_NAME} systemctl disable ${SERVICE_NAME} cat > "/usr/lib/systemd/system/${SERVICE_NAME}.service" < ${PACKAGE_PATH}/${SERVICE_NAME}-start.sh < /dev/null 2>&1 & echo $! > /var/run/"${SERVICE_NAME}".pid EOF cat > ${PACKAGE_PATH}/${SERVICE_NAME}-stop.sh < .version echo "Done!" popd > /dev/null