#!/bin/bash

if [ "$(uname -m)" == "armv6l" ]; then
	zenoty --error --no-wrap --text="Firefox is not supported on $(sed 's/ Rev .*//' /proc/device-tree/model)"
	exit 0
fi

display_qstn() {
  if [ -z "$DISPLAY" ]; then
    echo "$1"
  else
    zenoty --title=Firefox --text="$1" --question --ok-label="$2" \
      --cancel-label=Cancel --icon-name=dialog-warning
  fi
}

lowmemlimit=524288
lowmem="\
It is not recommended to run Firefox on devices with less than 1GB of RAM."
lowmemok="Launch anyway"

# Set env variable FF_SKIP_MEMCHECK=1 to skip this check
if [ ${FF_SKIP_MEMCHECK:=0} -ne 1 ]; then
  memkb=$(awk '/^MemTotal/{print $2; exit}' /proc/meminfo)
  if [ $memkb -le $lowmemlimit ]; then
    if ! display_qstn "$lowmem" "$lowmemok"; then
        exit 1
    fi
  fi
fi

MOZ_APP_LAUNCHER=/usr/bin/firefox exec /usr/lib/firefox/firefox "$@"
