优化判断使用 [[
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:
		
							parent
							
								
									5d7f33ce66
								
							
						
					
					
						commit
						189129bd10
					
				@ -20,7 +20,7 @@ LIGHT_CYAN="\e[96m"
 | 
				
			|||||||
WHITE="\e[97m"
 | 
					WHITE="\e[97m"
 | 
				
			||||||
END="\e[0m"
 | 
					END="\e[0m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $DISABLE_COLOR == true ]; then
 | 
					if [[ $DISABLE_COLOR == true ]]; then
 | 
				
			||||||
  BLACK=""
 | 
					  BLACK=""
 | 
				
			||||||
  RED=""
 | 
					  RED=""
 | 
				
			||||||
  GREEN=""
 | 
					  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)
 | 
					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"
 | 
					  echo -e "Download Station$RED not running$END exit"
 | 
				
			||||||
  exit
 | 
					  exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ LIGHT_CYAN="\e[96m"
 | 
				
			|||||||
WHITE="\e[97m"
 | 
					WHITE="\e[97m"
 | 
				
			||||||
END="\e[0m"
 | 
					END="\e[0m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $DISABLE_COLOR == true ]; then
 | 
					if [[ $DISABLE_COLOR == true ]]; then
 | 
				
			||||||
  BLACK=""
 | 
					  BLACK=""
 | 
				
			||||||
  RED=""
 | 
					  RED=""
 | 
				
			||||||
  GREEN=""
 | 
					  GREEN=""
 | 
				
			||||||
@ -42,13 +42,13 @@ fi
 | 
				
			|||||||
restartDockerContainer() {
 | 
					restartDockerContainer() {
 | 
				
			||||||
  stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
 | 
					  stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
 | 
				
			||||||
  status=$(jq '.success' <<<$stop)
 | 
					  status=$(jq '.success' <<<$stop)
 | 
				
			||||||
  if [ $status == false ]; then
 | 
					  if [[ $status == false ]]; then
 | 
				
			||||||
    echo -e $RED"stop container: $1 error: $stop"$END
 | 
					    echo -e $RED"stop container: $1 error: $stop"$END
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
 | 
					  start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
 | 
				
			||||||
  status=$(jq '.success' <<<$start)
 | 
					  status=$(jq '.success' <<<$start)
 | 
				
			||||||
  if [ $status == false ]; then
 | 
					  if [[ $status == false ]]; then
 | 
				
			||||||
    echo -e $RED"start container: $1 error: $stop"$END
 | 
					    echo -e $RED"start container: $1 error: $stop"$END
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -58,7 +58,7 @@ restartDockerContainer() {
 | 
				
			|||||||
checkServiceIsOffline() {
 | 
					checkServiceIsOffline() {
 | 
				
			||||||
  echo -e "checking container: $GREEN$1$END url: $GREEN$2$END"
 | 
					  echo -e "checking container: $GREEN$1$END url: $GREEN$2$END"
 | 
				
			||||||
  result=$(curl -I $2 2>/dev/null | grep 200)
 | 
					  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"
 | 
					    echo -e "conatiner need restarted: $RED$1$END"
 | 
				
			||||||
    return 1
 | 
					    return 1
 | 
				
			||||||
  else
 | 
					  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)
 | 
					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"
 | 
					  echo -e "Web Station$RED not running$END exit"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@ -79,7 +79,7 @@ echo "Web Station is running go next step"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
isRunning=$(jq -r 'map(select(.id == "ContainerManager") | .additional.status) | .[]' <<<$pakcageList)
 | 
					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"
 | 
					  echo -e "Container Manager$RED not running$END exit"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					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})')
 | 
					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)
 | 
					webStationPortalCount=$(jq 'length' <<<$webStationPortal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $webStationPortalCount -eq 0 ]; then
 | 
					if [[ $webStationPortalCount -eq 0 ]]; then
 | 
				
			||||||
  echo -e $RED"not found Web Station portal"$END
 | 
					  echo -e $RED"not found Web Station portal"$END
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					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"))')
 | 
					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)
 | 
					webStationServiceCount=$(jq 'length' <<<$webStationService)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $webStationServiceCount -eq 0 ]; then
 | 
					if [[ $webStationServiceCount -eq 0 ]]; then
 | 
				
			||||||
  echo -e $RED"not found Web Station services exit"$END
 | 
					  echo -e $RED"not found Web Station services exit"$END
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@ -121,15 +121,15 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  echo -e "service: $GREEN$serviceName$END enable: $BLUE$serviceEnable$END"
 | 
					  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"
 | 
					    echo -e "reverse proxy: $GREEN$portalHost$END ➡️  $GREEN$serviceName$END is$BLUE running$END skip"
 | 
				
			||||||
    continue
 | 
					    continue
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ ${#portal} -ne 0 ]; then
 | 
					  if [[ ${#portal} -ne 0 ]]; then
 | 
				
			||||||
    container=$(jq -c "map(select(.service.service == $serviceId)) | .[]" <<<$dockerContainer)
 | 
					    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"
 | 
					      echo "service: $GREEN$serviceName$END container$RED is not found skip$END"
 | 
				
			||||||
      continue
 | 
					      continue
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
@ -139,7 +139,7 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    echo -e "service container: $GREEN$containerName$END status: $GREEN$containerStatus$END"
 | 
					    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"
 | 
					      echo -e "contianer$GREEN $containerName$END is$RED not running$END skip"
 | 
				
			||||||
      continue
 | 
					      continue
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
@ -150,13 +150,13 @@ for idx in $(seq 0 $(($webStationServiceCount - 1))); do
 | 
				
			|||||||
    httpOffline=0
 | 
					    httpOffline=0
 | 
				
			||||||
    httpsOffline=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"
 | 
					      echo -e "reverse proxy found$GREEN http://$portalHost:$httpsPort $END➡️ $GREEN $proxyTarget $END"
 | 
				
			||||||
      checkServiceIsOffline $containerName "http://$portalHost:$httpPort"
 | 
					      checkServiceIsOffline $containerName "http://$portalHost:$httpPort"
 | 
				
			||||||
      httpOffline=$?
 | 
					      httpOffline=$?
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [ ${#httpsPort} -ne 0 ]; then
 | 
					    if [[ ${#httpsPort} -ne 0 ]]; then
 | 
				
			||||||
      echo -e "reverse proxy found$GREEN https://$portalHost:$httpsPort $END➡️ $GREEN $proxyTarget $END"
 | 
					      echo -e "reverse proxy found$GREEN https://$portalHost:$httpsPort $END➡️ $GREEN $proxyTarget $END"
 | 
				
			||||||
      checkServiceIsOffline $containerName "https://$portalHost:$httpsPort"
 | 
					      checkServiceIsOffline $containerName "https://$portalHost:$httpsPort"
 | 
				
			||||||
      httpsOffline=$?
 | 
					      httpsOffline=$?
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ LIGHT_CYAN="\e[96m"
 | 
				
			|||||||
WHITE="\e[97m"
 | 
					WHITE="\e[97m"
 | 
				
			||||||
END="\e[0m"
 | 
					END="\e[0m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $DISABLE_COLOR == true ]; then
 | 
					if [[ $DISABLE_COLOR == true ]]; then
 | 
				
			||||||
  BLACK=""
 | 
					  BLACK=""
 | 
				
			||||||
  RED=""
 | 
					  RED=""
 | 
				
			||||||
  GREEN=""
 | 
					  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)
 | 
					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"
 | 
					  echo -e "Web Station$RED not running$END exit"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@ -54,7 +54,7 @@ echo "Web Station is running go next step"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
isRunning=$(jq -r 'map(select(.id == "ContainerManager") | .additional.status) | .[]' <<<$pakcageList)
 | 
					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"
 | 
					  echo -e "Container Manager$RED not running$END exit"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					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"))')
 | 
					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)
 | 
					webStationServiceCount=$(jq 'length' <<<$webStationService)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ $webStationServiceCount -eq 0 ]; then
 | 
					if [[ $webStationServiceCount -eq 0 ]]; then
 | 
				
			||||||
  echo -e $RED"not found Web Station services exit"$END
 | 
					  echo -e $RED"not found Web Station services exit"$END
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@ -173,13 +173,13 @@ EOF
 | 
				
			|||||||
restartDockerContainer() {
 | 
					restartDockerContainer() {
 | 
				
			||||||
  stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
 | 
					  stop=$(synowebapi --exec api=SYNO.Docker.Container method=stop version=1 name=$1 2>/dev/null)
 | 
				
			||||||
  status=$(jq '.success' <<<$stop)
 | 
					  status=$(jq '.success' <<<$stop)
 | 
				
			||||||
  if [ $status == false ]; then
 | 
					  if [[ $status == false ]]; then
 | 
				
			||||||
    echo -e $RED"stop container: $1 error: $stop"$END
 | 
					    echo -e $RED"stop container: $1 error: $stop"$END
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
 | 
					  start=$(synowebapi --exec api=SYNO.Docker.Container method=start version=1 name=$1 2>/dev/null)
 | 
				
			||||||
  status=$(jq '.success' <<<$start)
 | 
					  status=$(jq '.success' <<<$start)
 | 
				
			||||||
  if [ $status == false ]; then
 | 
					  if [[ $status == false ]]; then
 | 
				
			||||||
    echo -e $RED"start container: $1 error: $stop"$END
 | 
					    echo -e $RED"start container: $1 error: $stop"$END
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user