diff options
author | ClusterM <cluster@ubuntu.(none)> | 2013-04-23 19:33:07 +0400 |
---|---|---|
committer | ClusterM <cluster@ubuntu.(none)> | 2013-04-23 19:33:07 +0400 |
commit | 418f6a672692a03918d1670082e4ad2dac451771 (patch) | |
tree | 7bd1de54a9d078632985c55d6eebbd68b8f4244e |
First commit
-rw-r--r-- | README.txt | 13 | ||||
-rwxr-xr-x | build/build-updates.sh | 52 | ||||
-rw-r--r-- | build/consts/patchconsts | 16 | ||||
-rw-r--r-- | build/ui/blanket | 176 | ||||
-rw-r--r-- | build/ui/progressbar | 62 | ||||
-rwxr-xr-x | src/install.sh | 42 | ||||
-rwxr-xr-x | src/uninstall.sh | 39 | ||||
-rw-r--r-- | update_lightfix_0.0.1_install.bin | bin | 0 -> 4184 bytes | |||
-rw-r--r-- | update_lightfix_0.0.1_uninstall.bin | bin | 0 -> 4065 bytes |
9 files changed, 400 insertions, 0 deletions
diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..1c700d9 --- /dev/null +++ b/README.txt @@ -0,0 +1,13 @@ + Kindle Paperwhite Lightfix +============================ +This patch allows user to turn off the frontlight completely. + +=== Install/Uninstall === +Nothing fancy, as usual, with a jailbroken Kindle, just use the appropriate update file: +copy it to the Kindle's USB drive's root, then launch it by going to [Menu] -> Settings -> [Menu] -> Update Your Kindle. + +=== Usage === +Just set brightness to lowest level and the frontlight will be turned off after one minute or less. + +Alexey Avdyukhin, from Russia with love. +mailto: clusterrr@clusterrr.com
\ No newline at end of file diff --git a/build/build-updates.sh b/build/build-updates.sh new file mode 100755 index 0000000..8f56d4a --- /dev/null +++ b/build/build-updates.sh @@ -0,0 +1,52 @@ +#! /bin/sh +# +# $Id: build-updates.sh +# + +HACKNAME="lightfix" +PKGNAME="${HACKNAME}" +PKGVER="0.0.1" + +# We need kindletool (https://github.com/NiLuJe/KindleTool) in $PATH +if (( $(kindletool version | wc -l) == 1 )) ; then + HAS_KINDLETOOL="true" +fi + +if [[ "${HAS_KINDLETOOL}" != "true" ]] ; then + echo "You need KindleTool (https://github.com/NiLuJe/KindleTool) to build this package." + exit 1 +fi + +# We also need GNU tar +TAR_BIN="tar" +if ! ${TAR_BIN} --version | grep "GNU tar" > /dev/null 2>&1 ; then + echo "You need GNU tar to build this package." + exit 1 +fi + +## Install +# Create the utils tarball +${TAR_BIN} --owner root --group root -cvzf utils.tar.gz consts ui + +# Archive custom directory +#${TAR_BIN} --owner root --group root --exclude="*.svn" -cvzf ${HACKNAME}.tar.gz ../src/${HACKNAME} + +# Copy the script to our working directory, to avoid storing crappy paths in the update package +cp ../src/install.sh ./ + +# Build the install package +kindletool create ota2 -d kindle5 utils.tar.gz install.sh update_${PKGNAME}_${PKGVER}_install.bin + +## Uninstall +# Copy the script to our working directory, to avoid storing crappy paths in the update package +cp ../src/uninstall.sh ./ + +# Build the install package +kindletool create ota2 -d kindle5 utils.tar.gz uninstall.sh update_${PKGNAME}_${PKGVER}_uninstall.bin + +## Cleanup +# Remove package specific temp stuff +rm -f ./install.sh ./uninstall.sh ./utils.tar.gz + +# Move our updates +mv -f *.bin ../ diff --git a/build/consts/patchconsts b/build/consts/patchconsts new file mode 100644 index 0000000..d51e3c8 --- /dev/null +++ b/build/consts/patchconsts @@ -0,0 +1,16 @@ +# Error constants for updates +# +# We start errors in the U050 range since we want to be able +# to distinguish updates from our original generation tool from +# these new ones. +ERR_GENERAL=U000 +ERR_KERNEL_SOURCE_MD5=U050 +ERR_KERNEL_WRITE=U051 +ERR_KERNEL_TARGET_MD5=U052 +ERR_UPSTART_INSERT_NODE=U053 +ERR_UPSTART_PAYLOAD_COPY=U054 +ERR_UPSTART_PAYLOAD_MKDIR=U055 +ERR_UPDATE_TARBALL_VALIDATION=U056 +ERR_UPDATE_SYSTEM_PATCH=U057 +ERR_UPDATE_SYSTEM_PATCH_RECOVERIES=U058 +ERR_UPDATE_BOOTSTRAP=U059 diff --git a/build/ui/blanket b/build/ui/blanket new file mode 100644 index 0000000..15d9903 --- /dev/null +++ b/build/ui/blanket @@ -0,0 +1,176 @@ +# +# Optional Setting: +# +# LOG_DOMAIN - The domain that logging statements will go under. If unset, this will default +# to "ota_install" +# +# Requires that the following have been sourced: +# * /etc/upstart/functions +# + +[ -z ${LOG_DOMAIN} ] && LOG_DOMAIN="ota_install" + +export _BLANKET_PERCENT_COMPLETE=0 + +blanket() +{ + local BLANKET=com.lab126.blanket + local OTAMODULE="${BLANKET}.ota" + local RES= + + if [ "${1}" != "isloaded" ]; then + if ! blanket isloaded ; then + case "${1}" in + progress|success|error|fail|end) + f_log W ${LOG_DOMAIN} guisetup "blanket=unloaded" "blanket not loaded - $@ not executing" + return 1 + ;; + begin) + # Load the OTA module in Blanket and display the splash screen. + lipc-set-prop $BLANKET load ota + RES=$? + if [ ${RES} -ne 0 ]; then + f_log W ${LOG_DOMAIN} guiload "load=ota" "unable to load ota blanket module" + return ${RES} + fi + + lipc-send-event $OTAMODULE otaSplashInit + RES=$? + if [ ${RES} -ne 0 ]; then + f_log W ${LOG_DOMAIN} guiinit "init=ota" "unable to send init event to ota blanket module" + return ${RES} + fi + return 0 + ;; + *) + ;; + esac + fi + fi + + case "${1}" in + progress) + # Update the progress indicator in the OTA splash screen. + lipc-send-event $OTAMODULE otaSplashProgress -i ${3} + RES=$? + if [ ${RES} -eq 0 ]; then + f_log D ${LOG_DOMAIN} guiprogress "progress=${3}" "update progress indicator" + else + f_log W ${LOG_DOMAIN} guiprogress "progress=${3},status=fail" "update progress indicator" + fi + ;; + success) + # Display a successful installation in the OTA splash screen. + lipc-send-event $OTAMODULE otaSplashSuccess + RES=$? + if [ ${RES} -eq 0 ]; then + f_log D ${LOG_DOMAIN} guisuccess "" "display success screen" + else + f_log W ${LOG_DOMAIN} guisuccess "status=fail" "display success screen" + fi + ;; + error|fail) + # Display an error and error string. + lipc-send-event $OTAMODULE otaSplashError -s "${3}" + RES=$? + if [ ${RES} -eq 0 ]; then + f_log D ${LOG_DOMAIN} guierror "" "display error screen : ${3}" + else + f_log W ${LOG_DOMAIN} guierror "status=fail" "display error screen : ${3}" + fi + ;; + end) + # Remove the splash screen and unload the OTA module from Blanket. + lipc-send-event $OTAMODULE otaSplashCleanup + RES=$? + if [ ${RES} -eq 0 ]; then + f_log D ${LOG_DOMAIN} guicleanup "" "cleanup ota module" + else + f_log W ${LOG_DOMAIN} guicleanup "status=fail" "cleanup ota module" + fi + lipc-set-prop $BLANKET unload ota + RES=$? + if [ ${RES} -eq 0 ]; then + f_log D ${LOG_DOMAIN} guiunload "" "unload blanket ota module" + else + f_log W ${LOG_DOMAIN} guiunload "status=fail" "unload blanket ota module" + fi + ;; + isloaded) + lipc-get-prop $BLANKET load | grep -q '\bota\b' + return $? + ;; + *) ;; + esac +} + +display_error_code() +{ + blanket error -i ${1#U} +} + +display_stage_data() +{ + local xpos=48 + local ypos=38 + local lpad=$(( $xpos - $(expr length "${1}") )) + local lbuf=$(printf "%${lpad}s") + eips 1 $ypos "${lbuf}${1}" +} + +display_failure_screen() +{ + display_error_code ${1:-U001} +} + +display_success_screen() +{ + blanket success +} + +display_update_screen() +{ + blanket begin + blanket progress -i 0 +} + +update_percent_complete() +{ + local x=$(printf "%d" $1 2>/dev/null) + [ -z ${x} ] && x=0 + + # Even though the underlying progressbar code doesn't support + # going forwards & backwards, allow it here + if [ ${x} -ne 0 ]; then + _BLANKET_PERCENT_COMPLETE=$((${_BLANKET_PERCENT_COMPLETE} + $x)) + __check_bounds + blanket progress -i ${_BLANKET_PERCENT_COMPLETE} + fi +} + +reset_progressbar() +{ + _BLANKET_PERCENT_COMPLETE=0 + blanket end + [ $# -eq 0 ] && display_update_screen +} + +set_percent_complete() +{ + local x=${_BLANKET_PERCENT_COMPLETE} + _BLANKET_PERCENT_COMPLETE=$(printf "%d" ${1} 2>/dev/null) + [ -z ${_BLANKET_PERCENT_COMPLETE} ] && _BLANKET_PERCENT_COMPLETE=0 + __check_bounds + if [ ${x} -ne ${_BLANKET_PERCENT_COMPLETE} ]; then + blanket progress -i ${1} + fi +} + +__check_bounds() +{ + if [ ${_BLANKET_PERCENT_COMPLETE} -gt 100 ]; then + _BLANKET_PERCENT_COMPLETE=100 + elif [ ${_BLANKET_PERCENT_COMPLETE} -lt 0 ]; then + _BLANKET_PERCENT_COMPLETE=0 + fi +} diff --git a/build/ui/progressbar b/build/ui/progressbar new file mode 100644 index 0000000..6bfbd4e --- /dev/null +++ b/build/ui/progressbar @@ -0,0 +1,62 @@ +# +# Before calling any functions, requires that the following +# have already been defined/sourced in the calling script: +# +# SCALING - Number of times an individual file will be processed +# FILECOUNT - Number of files that will have operations performed on them +# +# For example, most updates set SCALING=3 because a patched file is +# processed like so: (patch to tmp, copy to root file system, verify +# version on root filesystem). Scaling can change depending on options +# passed during update generation. +# +# Alternatively, if you know the exact number of times that you'll be +# calling "update_percent_complete_scaled 1", the values could be set +# like so: +# +# SCALING=1 +# FILECOUNT=NO_OF_UPDATE_CALLS +# +# +# Also requires that the following have been sourced: +# * "gui abstraction" - blanket or eips +# +# NOTE: There's no cleanup of PROG_COMPLETE since this is solely tmpfs +# on device and is expected to be rebooted immediately after execution. + +SCALING=1 +FILECOUNT=1 +PROG_COMPLETE=$(mktemp) +_COMPLETE_COUNT=0 +_CUR_PERCENT_COMPLETE=0 + +update_percent_complete_scaled() +{ + local x=$(printf "%d" $1 2>/dev/null) + [ -z ${x} ] && x=0 + _COMPLETE_COUNT=$((${_COMPLETE_COUNT} + $x)) +# f_log D ${LOG_DOMAIN} prog-complete "complete=${_COMPLETE_COUNT},filecount=${FILECOUNT},scaling=${SCALING}" "" + + if [ ${_COMPLETE_COUNT} -lt 0 ]; then + _COMPLETE_COUNT=0 + elif [ ${_COMPLETE_COUNT} -gt $((${SCALING} * ${FILECOUNT})) ]; then + _COMPLETE_COUNT=$((${SCALING} * ${FILECOUNT})) + fi + + local _PROGRESS_PERCENT=$(($((${_COMPLETE_COUNT} * 100)) / $((${SCALING} * ${FILECOUNT})) )) + + if [ ${_CUR_PERCENT_COMPLETE} -lt ${_PROGRESS_PERCENT} ]; then + set_percent_complete ${_PROGRESS_PERCENT} + _CUR_PERCENT_COMPLETE=${_PROGRESS_PERCENT} + fi +} + +update_percent_complete_from_pipe() +{ + local dummy + while read dummy; do + echo "${dummy}" + [ ! -d "/${dummy}" ] && update_percent_complete_scaled 1 + done + echo "export _COMPLETE_COUNT=${_COMPLETE_COUNT}" > ${PROG_COMPLETE} +} diff --git a/src/install.sh b/src/install.sh new file mode 100755 index 0000000..f8eeab4 --- /dev/null +++ b/src/install.sh @@ -0,0 +1,42 @@ +#!/bin/sh +## +# +# lightfix installer (c) Cluster aka Alexey Avyukgin +# mailto: clusterrr@clusterrr.com +# +## + +# Pull some helper functions for logging +source /etc/upstart/functions + +[ -f utils.tar.gz ] && { + tar xvf utils.tar.gz + rm -f utils.tar.gz +} + +# Pull some helper functions for progress bar handling +source consts/patchconsts +source ui/blanket +source ui/progressbar + +LOG_DOMAIN=lightfix +SCALING=1 +FILECOUNT=2 + +logmsg() +{ + f_log $1 ${LOG_DOMAIN} $2 "$3" "$4" +} + +HACKNAME="${LOG_DOMAIN}" +HACKVER="0.0.1" + +cat /etc/crontab/root | grep -v FrontLight > /etc/crontab/root +update_percent_complete_scaled 1 + +echo "* * * * * if [ \"\`cat /sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity | /bin/grep Light\`\" == \"FrontLight(Intensity) = 1\" ] ; then echo -n 0 > /sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity ; fi" >> /etc/crontab/root +update_percent_complete_scaled 1 + +logmsg "Lightfix installed" + +return 0 diff --git a/src/uninstall.sh b/src/uninstall.sh new file mode 100755 index 0000000..a80a6f3 --- /dev/null +++ b/src/uninstall.sh @@ -0,0 +1,39 @@ +#!/bin/sh +## +# +# lightfix installer (c) Cluster aka Alexey Avyukgin +# mailto: clusterrr@clusterrr.com +# +## + +# Pull some helper functions for logging +source /etc/upstart/functions + +[ -f utils.tar.gz ] && { + tar xvf utils.tar.gz + rm -f utils.tar.gz +} + +# Pull some helper functions for progress bar handling +source consts/patchconsts +source ui/blanket +source ui/progressbar + +LOG_DOMAIN=lightfix +SCALING=1 +FILECOUNT=1 + +logmsg() +{ + f_log $1 ${LOG_DOMAIN} $2 "$3" "$4" +} + +HACKNAME="${LOG_DOMAIN}" +HACKVER="0.0.1" + +cat /etc/crontab/root | grep -v FrontLight > /etc/crontab/root +update_percent_complete_scaled 1 + +logmsg "Lightfix uninstalled" + +return 0 diff --git a/update_lightfix_0.0.1_install.bin b/update_lightfix_0.0.1_install.bin Binary files differnew file mode 100644 index 0000000..e8e6f81 --- /dev/null +++ b/update_lightfix_0.0.1_install.bin diff --git a/update_lightfix_0.0.1_uninstall.bin b/update_lightfix_0.0.1_uninstall.bin Binary files differnew file mode 100644 index 0000000..a6f7454 --- /dev/null +++ b/update_lightfix_0.0.1_uninstall.bin |