<commit_before>#!/bin/sh
export LC_ALL="en_US.UTF-8"

# working directory of koreader
KOREADER_DIR="${0%/*}"

# we're always starting from our working directory
cd "${KOREADER_DIR}" || exit

# Attempt to switch to a sensible CPUFreq governor when that's not already the case...
IFS= read -r current_cpufreq_gov <"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
# NOTE: We're being fairly conservative here, because what's used and what's available varies depending on HW...
if [ "${current_cpufreq_gov}" != "ondemand" ] && [ "${current_cpufreq_gov}" != "interactive" ]; then
    # NOTE: Go with ondemand, because it's likely to be the lowest common denominator.
    #       Plus, interactive is hard to tune right, and only really interesting when it's a recent version,
    #       which I somehow doubt is the case anywhere here...
    if grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
        ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
        echo "ondemand" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
    fi
fi
# NOTE: That doesn't actually help us poor userspace plebs, but, short of switching to performance,
#       I don't really have a golden bullet here... (conservative's rubberbanding is terrible, so that's a hard pass).
#       All I can say is that userspace is a terrible idea and behaves *very* strangely (c.f., #4114).

# update to new version from OTA directory
ko_update_check() {
    NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar"
    INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar"
    if [ -f "${NEWUPDATE}" ]; then
        ./fbink -q -y -7 -pmh "Updating KOReader"<commit_msg>More robust way to detect our own path on Kobo (#6283)<commit_after>#!/bin/sh
export LC_ALL="en_US.UTF-8"

# Compute our working directory in an extremely defensive manner
KOREADER_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"

# We rely on starting from our working directory, and it needs to be set, sane and absolute.
cd "${KOREADER_DIR:-/dev/null}" || exit

# Attempt to switch to a sensible CPUFreq governor when that's not already the case...
IFS= read -r current_cpufreq_gov <"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
# NOTE: We're being fairly conservative here, because what's used and what's available varies depending on HW...
if [ "${current_cpufreq_gov}" != "ondemand" ] && [ "${current_cpufreq_gov}" != "interactive" ]; then
    # NOTE: Go with ondemand, because it's likely to be the lowest common denominator.
    #       Plus, interactive is hard to tune right, and only really interesting when it's a recent version,
    #       which I somehow doubt is the case anywhere here...
    if grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
        ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
        echo "ondemand" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
    fi
fi
# NOTE: That doesn't actually help us poor userspace plebs, but, short of switching to performance,
#       I don't really have a golden bullet here... (conservative's rubberbanding is terrible, so that's a hard pass).
#       All I can say is that userspace is a terrible idea and behaves *very* strangely (c.f., #4114).

# update to new version from OTA directory
ko_update_check() {
    NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar"
    INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar"
    if [ -f "${NEWUPDATE}" ]; then
        ./fbink -q -y -7 -pmh "Updating KOReader"
{'fraction_non_alphanumeric': 0.11537368570616652, 'fraction_numerical': 0.0068201193520886615, 'mean_word_length': 3.8219178082191783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2100954', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1080, 'n_words': 387}