gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/images/gpu/stable-diffusion-xl/generate_image (about)

     1  #!/bin/bash
     2  
     3  set -euo pipefail
     4  
     5  quiet_stderr=false
     6  for arg; do
     7    if [[ "$arg" == '--out' ]] || echo "$arg" | grep -qE '^--out='; then
     8      echo 'Cannot specify --out parameter; the image file will be written to stdout.' >&2
     9      exit 1
    10    fi
    11    if [[ "$arg" == '--quiet_stderr' ]]; then
    12      quiet_stderr=true
    13    fi
    14  done
    15  
    16  # Try to find out pixel size of the shell.
    17  terminal_pixel_width=0
    18  terminal_pixel_height=0
    19  if [[ -t 1 ]]; then
    20    echo -e -n '\e[14t'; IFS=';' read -rs -t 0.5 -d 't' rest height width <$(tty)
    21    terminal_pixel_width="$width"
    22    terminal_pixel_height="$height"
    23  fi
    24  
    25  out_dir="$(mktemp -d)"
    26  
    27  set +e
    28    /generate_image.py \
    29      --out="$out_dir/out_image" \
    30      --terminal_pixel_width="$terminal_pixel_width" \
    31      --terminal_pixel_height="$terminal_pixel_height" \
    32      "$@" \
    33      1>/dev/null \
    34      2>"$out_dir/stderr"
    35    return_code="$?"
    36  set -e
    37  
    38  if [[ "$return_code" == 0 ]]; then
    39    cat "$out_dir/out_image"
    40  fi
    41  if [[ "$return_code" != 0 ]] || [[ "$quiet_stderr" == false ]]; then
    42    cat "$out_dir/stderr" >&2
    43  fi
    44  rm -rf "$out_dir"
    45  exit "$return_code"