|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# KUAL KPVBooklet helper |
| 4 | +# |
| 5 | + |
| 6 | +# KOReader's working directory |
| 7 | +KOREADER_DIR="/mnt/us/koreader" |
| 8 | + |
| 9 | +# Load our helper functions... |
| 10 | +if [ -f "${KOREADER_DIR}/libkohelper.sh" ] ; then |
| 11 | + source "${KOREADER_DIR}/libkohelper.sh" |
| 12 | +else |
| 13 | + echo "Can't source helper functions, aborting!" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +## Handle logging... |
| 18 | +logmsg() |
| 19 | +{ |
| 20 | + # Use the right tools for the platform |
| 21 | + if [ "${INIT_TYPE}" == "sysv" ] ; then |
| 22 | + msg "koreader: ${1}" "I" |
| 23 | + elif [ "${INIT_TYPE}" == "upstart" ] ; then |
| 24 | + f_log I koreader kual "" "${1}" |
| 25 | + fi |
| 26 | + |
| 27 | + # And handle user visual feedback via eips... |
| 28 | + eips_print_bottom_centered "${1}" 1 |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +# Handle cre's settings... |
| 33 | +set_cre_prop() |
| 34 | +{ |
| 35 | + # We need at least two args |
| 36 | + if [ $# -lt 2 ] ; then |
| 37 | + logmsg "not enough arg passed to set_cre_prop" |
| 38 | + return |
| 39 | + fi |
| 40 | + |
| 41 | + cre_prop_key="${1}" |
| 42 | + cre_prop_value="${2}" |
| 43 | + |
| 44 | + cre_config="/mnt/us/extensions/kpvbooklet/bin/booklet.ini" |
| 45 | + |
| 46 | + touch ${cre_config} |
| 47 | + |
| 48 | + # Check that the config exists... |
| 49 | + if [ -f "${cre_config}" ] ; then |
| 50 | + # dos2unix |
| 51 | + sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}" |
| 52 | + |
| 53 | + grep ^${cre_prop_key}= "${cre_config}">/dev/null |
| 54 | + if [ $? -eq 1 ] ; then |
| 55 | + echo "${cre_prop_key}=${cre_prop_value}">>"${cre_config}" |
| 56 | + logmsg "Set ${cre_prop_key} to ${cre_prop_value}" |
| 57 | + return |
| 58 | + fi |
| 59 | + |
| 60 | + # And finally set the prop |
| 61 | + sed -re "s/^(${cre_prop_key})(=)(.*?)$/\1\2${cre_prop_value}/" -i "${cre_config}" |
| 62 | + if [ $? -eq 0 ] ; then |
| 63 | + logmsg "Set ${cre_prop_key} to ${cre_prop_value}" |
| 64 | + else |
| 65 | + logmsg "Failed to set ${cre_prop_key}" |
| 66 | + fi |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +#eips_print_bottom_centered "test now" 1 |
| 71 | +# logmsg "its working OK $@" |
| 72 | + |
| 73 | +set_cre_prop ${1} ${2} |
| 74 | + |
| 75 | + |
0 commit comments