From f8dc5c82d12a7be59f447198a4e9527b6e9f77bc Mon Sep 17 00:00:00 2001 From: Waldo Jaquith Date: Thu, 20 Jun 2019 20:26:22 -0400 Subject: [PATCH] Conditionally shut down Only shut down if any video was found. If not, that means that we're starting up the server manually, in which case we *want* it to stay on. Closes #64. --- bin/handler.sh | 32 +++++++++++++------------------- deploy/test.sh | 12 ++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 deploy/test.sh diff --git a/bin/handler.sh b/bin/handler.sh index 35b3793..8d629ad 100755 --- a/bin/handler.sh +++ b/bin/handler.sh @@ -8,11 +8,10 @@ function finish { cd .. rm -Rf video/ - if [[ -v "SHUTDOWN" ]]; then - echo "[WOULD SHUT DOWN SERVER NOW]" - #sudo shutdown -h now + if [[ -v "SHUTDOWN" ]] && [[ "$ANY_VIDEO_FOUND" == true ]]; then + sudo shutdown -h now else - cd bin/ + cd bin/ || exit ./handler.sh || exit fi @@ -21,6 +20,9 @@ function finish { # Run the finish() function every time this script exits for any reason. trap finish EXIT +# Establish a flag that indicates whether any video has been found +ANY_VIDEO_FOUND=false + # Change to the directory containing this script. cd "$(dirname "$0")" || exit 1 @@ -34,6 +36,7 @@ cd "$VIDEO_DIR" || exit 1 php ../bin/get_video.php GOT_VIDEO=$? if [ $GOT_VIDEO -eq 1 ]; then + ANY_VIDEO_FOUND=true exit 1 elif [ $GOT_VIDEO -eq 2 ]; then export SHUTDOWN=1 @@ -42,12 +45,12 @@ fi # Turn the JSON into key/value pairs, and make them into environment variables. eval "$(jq -r '. | to_entries | .[] | .key + "=\"" + .value + "\""' < metadata.json)" -set $filename -set $date -set $date_hyphens -set $s3_url -set $chamber -set $type +set "$filename" +set "$date" +set "$date_hyphens" +set "$s3_url" +set "$chamber" +set "$type" # Define the name of the directory that will store the extracted chyrons. export output_dir="${filename/.mp4/}" @@ -94,12 +97,3 @@ if [ "$type" = "floor" ]; then php ../bin/process_captions.php "$CAPTIONS_FILE" "$VIDEO_ID" || exit $? fi - -#/home/ubuntu/youtube-upload-master/bin/youtube-upload ' -# . '--tags="virginia, legislature, general assembly" ' -# . '--default-language="en" ' -# . '--default-audio-language="en" ' -# . '--title="Virginia ' . ucfirst($video['chamber']) . ', ' . date('F j, Y', strtotime($video['date'])) . '" ' -# . '--recording-date="' . $DATE . 'T00:00:00.0Z" ' -# . $DATE -## diff --git a/deploy/test.sh b/deploy/test.sh new file mode 100644 index 0000000..feb2621 --- /dev/null +++ b/deploy/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Get the test video. +echo "Downloading test House video from S3" +curl -s -o test-house-video.mp4 https://s3.amazonaws.com/deploy.richmondsunlight.com/test-house-video.mp4 + +# OCR the video. +set output_dir=test-house-video +ocr.sh test-house-video.mp4 house + +# Verify that the chyrons match what we expect them to be. +cat *.txt