#!/bin/sh
# SPDX-License-Identifier: MIT

# To run from curl with arguments : curl ... | sh -s arg1 arg2 ...

set -e

BASE_DIR=/tmp/disp-info

echo "Downloading Python runtime"

mkdir -p "${BASE_DIR}"
curl -L https://cdn.asahilinux.org/installer/installer-v0.3.28.tar.gz | \
	tar -C "${BASE_DIR}" -xz

echo "Downloading display-info.py"
curl -o "${BASE_DIR}/display-info.py" \
	-L https://vincent.duvert.net/dropbox/display-info.py

echo "Starting display-info.py"

export DYLD_LIBRARY_PATH="${BASE_DIR}/Frameworks/Python.framework/Versions/Current/lib"
export DYLD_FRAMEWORK_PATH="${BASE_DIR}/Frameworks"
export SSL_CERT_FILE="${BASE_DIR}/Frameworks/Python.framework/Versions/Current/etc/openssl/cert.pem"

exec </dev/tty "${BASE_DIR}/Frameworks/Python.framework/Versions/3.9/bin/python3.9" \
	"${BASE_DIR}/display-info.py" "$@"
