msg() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    GREEN="${BOLD}\e[1;32m"
    local mesg=$1; shift
    printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

post_install() {
  # Grab the steam bootstrap for first boot

  URL="https://steamdeck-packages.steamos.cloud/archlinux-mirror/jupiter-main/os/x86_64/steam-jupiter-stable-1.0.0.81-2.5-x86_64.pkg.tar.zst"
  TMP_PKG="/tmp/package.pkg.tar.zst"
  OUTPUT_FILE="/tmp/bootstraplinux_ubuntu12_32.tar.xz"
  TARGET_FILE="/usr/lib/steam/bootstraplinux_ubuntu12_32.tar.xz"

  msg "Downloading $URL"
  curl -o "$TMP_PKG" "$URL"
  ZST_CHECKSUM=f1799216cdb894772a27be14ebcde17d3604a6f48de9b2ade543193a516fcc99123e80ddc3da16f92d024e4b82397d320e0153611d899bf7d26e18e3a96b5ded
  TMP_PKG_CHECKSUM=$(sha512sum ${TMP_PKG} | cut -d " " -f1)
  if [[ "$ZST_CHECKSUM" == "$TMP_PKG_CHECKSUM" ]]; then
     msg "Extracting $OUTPUT_FILE"
     tar -I zstd -xvf "$TMP_PKG" usr/lib/steam/bootstraplinux_ubuntu12_32.tar.xz -O > "$OUTPUT_FILE"
  else
     msg "Download failed!"
     exit 1
  fi
   XZ_CHECKSUM=bb009569b1a7faf04a129e18eeecbafa5a5f81a5e7fb83f7a780ec14a9e814083d1c5c7b07c35e0a1c5d00349218efdbbcb39be7820d2af39562ce983ef0370d
  BS_CHECKSUM=$(sha512sum ${OUTPUT_FILE} | cut -d " " -f1)
  if [[ "$XZ_CHECKSUM" == "$BS_CHECKSUM" ]]; then
     msg "moving $OUTPUT_FILE to $TARGET_FILE"
     mv "$OUTPUT_FILE" "$TARGET_FILE"
  else
     msg "Extraction failed!"
     exit 1
  fi
  [[ -e "$TMP_PKG" ]] && rm "$TMP_PKG"
  [[ -e "$OUTPUT_FILE" ]] && rm "$OUTPUT_FILE"
}
