优化判断使用 [[
Please enter the commit message for your changes. Lines starting with '' will be ignored, and an empty message aborts the commit. On branch master Changes to be committed: modified: auto-add-bt-trackerlist.sh modified: auto-reload-web-station-docker-reverse-proxy.sh modified: enable-web-station-websocket.sh
This commit is contained in:
@@ -20,7 +20,7 @@ LIGHT_CYAN="\e[96m"
|
||||
WHITE="\e[97m"
|
||||
END="\e[0m"
|
||||
|
||||
if [ $DISABLE_COLOR == true ]; then
|
||||
if [[ $DISABLE_COLOR == true ]]; then
|
||||
BLACK=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
@@ -113,7 +113,7 @@ pakcageList=$(synowebapi --exec api=SYNO.Core.Package method=list version=2 addi
|
||||
|
||||
isRunning=$(jq -r 'map(select(.id == "DownloadStation") | .additional.status) | .[]' <<<$pakcageList)
|
||||
|
||||
if [ $isRunning != "running" ]; then
|
||||
if [[ $isRunning != "running" ]]; then
|
||||
echo -e "Download Station$RED not running$END exit"
|
||||
exit
|
||||
fi
|
||||
|
||||
@@ -19,7 +19,7 @@ LIGHT_CYAN="\e[96m"
|
||||
WHITE="\e[97m"
|
||||
END="\e[0m"
|
||||
|
||||
if [ $DISABLE_COLOR == true ]; then
|
||||
if [[ $DISABLE_COLOR == true ]]; then
|
||||
BLACK=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
@@ -42,13 +42,13 @@ fi
|
||||
restartDockerContainer() {
|
||||
stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
|
||||
status=$(jq '.success' <<<$stop)
|
||||
if [ $status == false ]; then
|
||||
if [[ $status == false ]]; then
|
||||
echo -e $RED"stop container: $1 error: $stop"$END
|
||||
fi
|
||||
|
||||
start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
|
||||
status=$(jq '.success' <<<$start)
|
||||
if [ $status == false ]; then
|
||||
if [[ $status == false ]]; then
|
||||
echo -e $RED"start container: $1 error: $stop"$END
|
||||
fi
|
||||
|
||||
@@ -58,7 +58,7 @@ restartDockerContainer() {
|
||||
checkServiceIsOffline() {
|
||||
echo -e "checking container: $GREEN$1$END url: $GREEN$2$END"
|
||||
result=$(curl -I $2 2>/dev/null | grep 200)
|
||||
if [ ${#result} -eq 0 ]; then
|
||||
if [[ ${#result} -eq 0 ]]; then
|
||||
echo -e "conatiner need restarted: $RED$1$END"
|
||||
return 1
|
||||
else
|
||||
@@ -71,7 +71,7 @@ pakcageList=$(synowebapi --exec api=SYNO.Core.Package method=list version=2 addi
|
||||
|
||||
isRunning=$(jq -r 'map(select(.id == "WebStation") | .additional.status) | .[]' <<<$pakcageList)
|
||||
|
||||
if [ $isRunning != "running" ]; then
|
||||
if [[ $isRunning != "running" ]]; then
|
||||
echo -e "Web Station$RED not running$END exit"
|
||||
exit 0
|
||||
fi
|
||||
@@ -79,7 +79,7 @@ echo "Web Station is running go next step"
|
||||
|
||||
isRunning=$(jq -r 'map(select(.id == "ContainerManager") | .additional.status) | .[]' <<<$pakcageList)
|
||||
|
||||
if [ $isRunning != "running" ]; then
|
||||
if [[ $isRunning != "running" ]]; then
|
||||
echo -e "Container Manager$RED not running$END exit"
|
||||
exit 0
|
||||
fi
|
||||
@@ -88,7 +88,7 @@ echo "Container Manager is running go next step"
|
||||
webStationPortal=$(synowebapi --exec api=SYNO.WebStation.WebService.Portal method=list version=1 2>/dev/null | jq -c '.data.portals | map({host: .fqdn, http: .http_port[0], https: .https_port[0], service: .service, display_name: .shortcut.display_name})')
|
||||
webStationPortalCount=$(jq 'length' <<<$webStationPortal)
|
||||
|
||||
if [ $webStationPortalCount -eq 0 ]; then
|
||||
if [[ $webStationPortalCount -eq 0 ]]; then
|
||||
echo -e $RED"not found Web Station portal"$END
|
||||
exit 0
|
||||
fi
|
||||
@@ -98,7 +98,7 @@ echo -e "found Web Station portal count: $RED$webStationPortalCount"$END
|
||||
webStationService=$(synowebapi --exec api=SYNO.WebStation.WebService.Service method=list version=1 2>/dev/null | jq -c '.data.services | map(select(.category == "Docker"))')
|
||||
webStationServiceCount=$(jq 'length' <<<$webStationService)
|
||||
|
||||
if [ $webStationServiceCount -eq 0 ]; then
|
||||
if [[ $webStationServiceCount -eq 0 ]]; then
|
||||
echo -e $RED"not found Web Station services exit"$END
|
||||
exit 0
|
||||
fi
|
||||
@@ -121,15 +121,15 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
|
||||
|
||||
echo -e "service: $GREEN$serviceName$END enable: $BLUE$serviceEnable$END"
|
||||
|
||||
if [ $serviceEnable == true ]; then
|
||||
if [[ $serviceEnable == true ]]; then
|
||||
echo -e "reverse proxy: $GREEN$portalHost$END ➡️ $GREEN$serviceName$END is$BLUE running$END skip"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ ${#portal} -ne 0 ]; then
|
||||
if [[ ${#portal} -ne 0 ]]; then
|
||||
container=$(jq -c "map(select(.service.service == $serviceId)) | .[]" <<<$dockerContainer)
|
||||
|
||||
if [ ${#container} -eq 0 ]; then
|
||||
if [[ ${#container} -eq 0 ]]; then
|
||||
echo "service: $GREEN$serviceName$END container$RED is not found skip$END"
|
||||
continue
|
||||
fi
|
||||
@@ -139,7 +139,7 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
|
||||
|
||||
echo -e "service container: $GREEN$containerName$END status: $GREEN$containerStatus$END"
|
||||
|
||||
if [ $containerStatus != 'running' ]; then
|
||||
if [[ $containerStatus != 'running' ]]; then
|
||||
echo -e "contianer$GREEN $containerName$END is$RED not running$END skip"
|
||||
continue
|
||||
fi
|
||||
@@ -150,13 +150,13 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
|
||||
httpOffline=0
|
||||
httpsOffline=0
|
||||
|
||||
if [ ${#httpPort} -ne 0 ]; then
|
||||
if [[ ${#httpPort} -ne 0 ]]; then
|
||||
echo -e "reverse proxy found$GREEN http://$portalHost:$httpsPort $END➡️ $GREEN $proxyTarget $END"
|
||||
checkServiceIsOffline $containerName "http://$portalHost:$httpPort"
|
||||
httpOffline=$?
|
||||
fi
|
||||
|
||||
if [ ${#httpsPort} -ne 0 ]; then
|
||||
if [[ ${#httpsPort} -ne 0 ]]; then
|
||||
echo -e "reverse proxy found$GREEN https://$portalHost:$httpsPort $END➡️ $GREEN $proxyTarget $END"
|
||||
checkServiceIsOffline $containerName "https://$portalHost:$httpsPort"
|
||||
httpsOffline=$?
|
||||
|
||||
@@ -20,7 +20,7 @@ LIGHT_CYAN="\e[96m"
|
||||
WHITE="\e[97m"
|
||||
END="\e[0m"
|
||||
|
||||
if [ $DISABLE_COLOR == true ]; then
|
||||
if [[ $DISABLE_COLOR == true ]]; then
|
||||
BLACK=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
@@ -46,7 +46,7 @@ pakcageList=$(synowebapi --exec api=SYNO.Core.Package method=list version=2 addi
|
||||
|
||||
isRunning=$(jq -r 'map(select(.id == "WebStation") | .additional.status) | .[]' <<<$pakcageList)
|
||||
|
||||
if [ $isRunning != "running" ]; then
|
||||
if [[ $isRunning != "running" ]]; then
|
||||
echo -e "Web Station$RED not running$END exit"
|
||||
exit 0
|
||||
fi
|
||||
@@ -54,7 +54,7 @@ echo "Web Station is running go next step"
|
||||
|
||||
isRunning=$(jq -r 'map(select(.id == "ContainerManager") | .additional.status) | .[]' <<<$pakcageList)
|
||||
|
||||
if [ $isRunning != "running" ]; then
|
||||
if [[ $isRunning != "running" ]]; then
|
||||
echo -e "Container Manager$RED not running$END exit"
|
||||
exit 0
|
||||
fi
|
||||
@@ -63,7 +63,7 @@ echo "Container Manager is running go next step"
|
||||
webStationService=$(synowebapi --exec api=SYNO.WebStation.WebService.Service method=list version=1 2>/dev/null | jq -c '.data.services | map(select(.category == "Docker"))')
|
||||
webStationServiceCount=$(jq 'length' <<<$webStationService)
|
||||
|
||||
if [ $webStationServiceCount -eq 0 ]; then
|
||||
if [[ $webStationServiceCount -eq 0 ]]; then
|
||||
echo -e $RED"not found Web Station services exit"$END
|
||||
exit 0
|
||||
fi
|
||||
@@ -173,13 +173,13 @@ EOF
|
||||
restartDockerContainer() {
|
||||
stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
|
||||
status=$(jq '.success' <<<$stop)
|
||||
if [ $status == false ]; then
|
||||
if [[ $status == false ]]; then
|
||||
echo -e $RED"stop container: $1 error: $stop"$END
|
||||
fi
|
||||
|
||||
start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
|
||||
status=$(jq '.success' <<<$start)
|
||||
if [ $status == false ]; then
|
||||
if [[ $status == false ]]; then
|
||||
echo -e $RED"start container: $1 error: $stop"$END
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user