mirror of
https://github.com/FunKey-Project/FunKey-OS.git
synced 2025-12-14 08:38:52 +01:00
Added the utility scripts
This commit is contained in:
parent
04d2c698b6
commit
09dc20c6e7
20
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_get
Executable file
20
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_get
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
BRIGHTNESS_FILE="/etc/current_brightness"
|
||||||
|
BRIGHTNESS_DEFAULT_VALUE=100
|
||||||
|
|
||||||
|
# Sanity check: File does not exist
|
||||||
|
if [ ! -f "${BRIGHTNESS_FILE}" ]; then
|
||||||
|
#echo "error: \"${BRIGHTNESS_FILE}\" does not exist" >&2
|
||||||
|
echo ${BRIGHTNESS_DEFAULT_VALUE} > "${BRIGHTNESS_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sanity check: Check if integer
|
||||||
|
brightness=$(cat "${BRIGHTNESS_FILE}")
|
||||||
|
if ! [ "${brightness}" -ne "${brightness}" ] 2> /dev/null; then
|
||||||
|
#echo "error: \"${brightness}\" is not a number" >&2
|
||||||
|
echo ${BRIGHTNESS_DEFAULT_VALUE} > "${BRIGHTNESS_FILE}"
|
||||||
|
brightness=${BRIGHTNESS_DEFAULT_VALUE}
|
||||||
|
fi
|
||||||
|
echo ${brightness}
|
||||||
|
exit 0
|
||||||
7
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_get_sysfs
Executable file
7
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_get_sysfs
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SYSTEM_BRIGHTNESS="/sys/class/backlight/backlight/brightness"
|
||||||
|
|
||||||
|
let brightness=$(cat "${SYSTEM_BRIGHTNESS}")*10-10
|
||||||
|
echo ${brightness}
|
||||||
|
exit 0
|
||||||
28
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_set
Executable file
28
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_set
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
BRIGHTNESS_FILE="/etc/current_brightness"
|
||||||
|
SYSTEM_BRIGHTNESS="/sys/class/backlight/backlight/brightness"
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ ${#} != 1 ]; then
|
||||||
|
echo "Usage: ${0} new_brightness_percentage"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check value's range
|
||||||
|
if [ ${1} -gt 100 ]; then
|
||||||
|
echo "Usage: Wrong brightness percentage (${1}), must be between 0 and 100"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
brightness_percentage=${1}
|
||||||
|
|
||||||
|
# Set new brightness percentage
|
||||||
|
let value=${1}+10
|
||||||
|
let value/=10
|
||||||
|
echo ${value} > "${SYSTEM_BRIGHTNESS}"
|
||||||
|
|
||||||
|
# Set new brightness value in brightness file
|
||||||
|
if [ ${?} -eq 0 ]; then
|
||||||
|
echo ${brightness_percentage} > "${BRIGHTNESS_FILE}"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
18
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_set_sysfs
Executable file
18
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/brightness_set_sysfs
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SYSTEM_BRIGHTNESS="/sys/class/backlight/backlight/brightness"
|
||||||
|
|
||||||
|
if [ ${#} != 1 ]; then
|
||||||
|
echo "Usage: $0 new_brightness_percentage"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ${1} -gt 100 ]; then
|
||||||
|
echo "Usage: Wrong brightness percentage (${1}), must be between 0 and 100"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set new brightness percentage
|
||||||
|
let value=${1}+10
|
||||||
|
let value/=10
|
||||||
|
echo ${value} > "${SYSTEM_BRIGHTNESS}"
|
||||||
|
exit 0
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
notif_set 0 "Getting system stats..."
|
||||||
|
killall -s USR1 system_stats
|
||||||
|
exit 0
|
||||||
3
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/kill_emulators
Executable file
3
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/kill_emulators
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
killall mednafen gpsp psnes pcsx sdlgnuboy PicoDriveBin
|
||||||
|
exit 0
|
||||||
124
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/low_bat_check
Executable file
124
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/low_bat_check
Executable file
@ -0,0 +1,124 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# General constants declaration
|
||||||
|
THRESHOLD_PERCENT_LOW_BAT=5
|
||||||
|
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
||||||
|
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
|
||||||
|
SLEEP_SECS=2
|
||||||
|
RESCALE_MAX_PERCENTAGE=110
|
||||||
|
|
||||||
|
# Blink Low bat constants declaration
|
||||||
|
BLINK_ICON=0
|
||||||
|
LOW_BAT_SECS_DISPLAYED=5
|
||||||
|
LOW_BAT_SECS_NOT_DISPLAYED=5
|
||||||
|
|
||||||
|
# Files and commands declaration
|
||||||
|
USB_PRESENT_FILE="/sys/class/power_supply/axp20x-usb/present"
|
||||||
|
#USB_PRESENT_FILE="/sys/class/power_supply/axp20x-ac/present" # Cheat for no USB present simulation when debugging
|
||||||
|
BAT_PRESENT_FILE="/sys/class/power_supply/axp20x-battery/present"
|
||||||
|
BAT_PERCENT_FILE="/sys/class/power_supply/axp20x-battery/capacity"
|
||||||
|
BAT_PERCENT_RESCALED_FILE="/etc/current_battery_percentage"
|
||||||
|
LOW_BAT_ICON="/sys/class/graphics/fb0/low_battery"
|
||||||
|
SCHEDULE_SHUTDOWN_CMD="sched_shutdown"
|
||||||
|
SIGNAL_URS1_TO_EMULATORS_CMD="signal_usr1_to_emulators"
|
||||||
|
|
||||||
|
# Variables declaration
|
||||||
|
low_bat_status=0
|
||||||
|
low_bat_displayed=0
|
||||||
|
cur_secs_disp=0
|
||||||
|
cur_nb_extremely_low_bat_before_shutdown=0
|
||||||
|
|
||||||
|
# Default: Hide Low Bat Icon
|
||||||
|
eval ${ICON_HIDE_CMD}
|
||||||
|
|
||||||
|
# Check low bat #
|
||||||
|
while true; do
|
||||||
|
#echo "Bat present: "$(cat ${BAT_PRESENT_FILE})"
|
||||||
|
#echo "USB present: "$(cat ${USB_PRESENT_FILE})"
|
||||||
|
#echo "Bat percentage: "$(cat ${BAT_PERCENT_FILE})"
|
||||||
|
|
||||||
|
# Get current bat percentage here once
|
||||||
|
cur_bat_percent=$(cat "${BAT_PERCENT_FILE}")
|
||||||
|
#echo "cur_bat_percent = ${cur_bat_percent}"
|
||||||
|
|
||||||
|
# Rescale bat percentage between 0 and RESCALE_MAX_PERCENTAGE
|
||||||
|
bat_percent_rescaled=$(printf "%.f" $(echo $cur_bat_percent $RESCALE_MAX_PERCENTAGE | awk '{print $1*$2/100}'))
|
||||||
|
#echo "bat_percent_rescaled = ${bat_percent_rescaled}"
|
||||||
|
|
||||||
|
# Re-maximize to 100%
|
||||||
|
bat_percent_rescaled_maxed=$(( bat_percent_rescaled < 100 ? bat_percent_rescaled : 100 ))
|
||||||
|
#echo "bat_percent_rescaled_maxed = ${bat_percent_rescaled_maxed}"
|
||||||
|
|
||||||
|
# Save in file
|
||||||
|
echo ${bat_percent_rescaled_maxed} > "${BAT_PERCENT_RESCALED_FILE}"
|
||||||
|
|
||||||
|
# Low bat status detection
|
||||||
|
if [ "$(cat ${USB_PRESENT_FILE})" -eq "0" ]; then
|
||||||
|
|
||||||
|
# Value of 0 means wrong i2c reading
|
||||||
|
if [ "${cur_bat_percent}" -ne "0" ]; then
|
||||||
|
|
||||||
|
# Check if we must change state
|
||||||
|
if [ "{$cur_bat_percent}" -le "${THRESHOLD_PERCENT_LOW_BAT}" -a "${low_bat_status}" -eq "0" ]; then
|
||||||
|
|
||||||
|
# Set Low Bat status
|
||||||
|
low_bat_status=1
|
||||||
|
low_bat_displayed=1
|
||||||
|
cur_secs_disp=0
|
||||||
|
echo 1 > "${LOW_BAT_ICON}"
|
||||||
|
|
||||||
|
elif [ "${cur_bat_percent}" -gt "${THRESHOLD_PERCENT_LOW_BAT}" -a "${low_bat_status}" -eq "1" ]; then
|
||||||
|
|
||||||
|
# Reset status
|
||||||
|
low_bat_status=0
|
||||||
|
cur_nb_extremely_low_bat_before_shutdown=0
|
||||||
|
echo 0 > "${LOW_BAT_ICON}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ "${low_bat_status}" -eq "1" ]; then
|
||||||
|
|
||||||
|
# Reset status
|
||||||
|
low_bat_status=0
|
||||||
|
cur_nb_extremely_low_bat_before_shutdown=0
|
||||||
|
echo 0 > "${LOW_BAT_ICON}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Low bat processing
|
||||||
|
if [ "${low_bat_status}" -eq "1" ]; then
|
||||||
|
|
||||||
|
# Check extremely low bat for clean shutdown
|
||||||
|
if [ "${cur_bat_percent}" -le "${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT}" ]; then
|
||||||
|
let cur_nb_extremely_low_bat_before_shutdown++
|
||||||
|
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
|
||||||
|
|
||||||
|
# Clean shutdown
|
||||||
|
if [ "${cur_nb_extremely_low_bat_before_shutdown}" -ge "${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN}" ]; then
|
||||||
|
echo "Battery extremely low, shutting down now..."
|
||||||
|
sched_shutdown 1 & signal_usr1_to_emulators
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Blinking process
|
||||||
|
if [ "${BLINK_ICON}" -eq "1" ]; then
|
||||||
|
if [ "${low_bat_displayed}" -eq "1" -a "${cur_secs_disp}" -ge "${LOW_BAT_SECS_DISPLAYED}" ]; then
|
||||||
|
low_bat_displayed=0
|
||||||
|
cur_secs_disp=0
|
||||||
|
echo 0 > "${LOW_BAT_ICON}"
|
||||||
|
elif [ "${low_bat_displayed}" -eq "0" -a "${cur_secs_disp}" -ge "${LOW_BAT_SECS_NOT_DISPLAYED}" ]; then
|
||||||
|
low_bat_displayed=1
|
||||||
|
cur_secs_disp=0
|
||||||
|
echo 1 > "${LOW_BAT_ICON}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sleep before next check
|
||||||
|
sleep ${SLEEP_SECS}
|
||||||
|
|
||||||
|
# Increase vars
|
||||||
|
let cur_secs_disp+=${SLEEP_SECS}
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
7
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_clear
Executable file
7
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_clear
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Clear all current notifications
|
||||||
|
|
||||||
|
NOTIFICATION_DISPLAY="/sys/class/graphics/fb0/notification"
|
||||||
|
printf "clear" > "${NOTIFICATION_DISPLAY}"
|
||||||
|
|
||||||
|
exit 0
|
||||||
38
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_disp
Executable file
38
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_disp
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Display notification for a certain amount of time
|
||||||
|
# Special char: ^ to add a new line
|
||||||
|
# Set seconds to 0 to display indefinitely (until the next notif)
|
||||||
|
|
||||||
|
NOTIFICATION_DISPLAY="/sys/class/graphics/fb0/notification"
|
||||||
|
|
||||||
|
display_usage() {
|
||||||
|
echo -e "Usage:\n$(basename ${0}) nb_seconds_display message_to_display\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# If less than two arguments supplied, display usage
|
||||||
|
if [ ${#} -le 1 ]; then
|
||||||
|
echo "Display notification for a certain amount of time"
|
||||||
|
display_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get number of seconds to display notif
|
||||||
|
nb_secs=${1}
|
||||||
|
if ! [ "${nb_secs}" -ne "${nb_secs}" ] 2> /dev/null; then
|
||||||
|
echo "error: \"${nb_secs}\" is not a number" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print notif
|
||||||
|
printf "${*:2}" > "${NOTIFICATION_DISPLAY}"
|
||||||
|
|
||||||
|
# Clear notif if NB_SECS is not 0, otherwise never clear
|
||||||
|
if [ "${nb_secs}" -ne "0" ]; then
|
||||||
|
|
||||||
|
# Wait time before clearing notif
|
||||||
|
sleep ${nb_secs}
|
||||||
|
|
||||||
|
# Clear notif
|
||||||
|
printf "clear" > "${NOTIFICATION_DISPLAY}"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
36
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_set
Executable file
36
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/notif_set
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Erase previous notif and display new one in background process for a certain amount of seconds
|
||||||
|
# Special char: ^ to add a new line
|
||||||
|
# Set seconds to 0 to display indefinitely (until the next notif_set)
|
||||||
|
|
||||||
|
NOTIFICATION_DISPLAY="/sys/class/graphics/fb0/notification"
|
||||||
|
|
||||||
|
display_usage() {
|
||||||
|
echo -e "Usage:\n$(basename ${0}) nb_seconds_display message_to_display\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# If less than two arguments supplied, display usage
|
||||||
|
if [ $# -le 1 ]; then
|
||||||
|
echo "Erase previous notif and display new one in background process for a certain amount of time"
|
||||||
|
echo "Special char: ^ to add a new line"
|
||||||
|
echo "Set seconds to 0 to display indefinitely (until the next $(basename ${0}))"
|
||||||
|
display_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get number of seconds to display notif
|
||||||
|
nb_secs=${1}
|
||||||
|
if ! [ "${nb_secs}" -ne "${nb_secs}" ]; then
|
||||||
|
echo "error: \"${nb_secs}\" is not a number" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Kill previous notif_disp process
|
||||||
|
pkill notif_disp 2> /dev/null
|
||||||
|
|
||||||
|
## Clear previous notif
|
||||||
|
#printf "clear" > "${NOTIFICATION_DISPLAY}"
|
||||||
|
|
||||||
|
# Print new notif
|
||||||
|
notif_disp "$@" &
|
||||||
|
exit 0
|
||||||
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_bright_down
Executable file
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_bright_down
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
STEP_BRIGHTNESS=10
|
||||||
|
NOTIF_TIME_ON=2
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_brightness=$(brightness_get)
|
||||||
|
|
||||||
|
# Compute new brightness value
|
||||||
|
new_brightness=0
|
||||||
|
if [ "${current_brightness}" -gt "${STEP_BRIGHTNESS}" ]; then
|
||||||
|
let new_brightness=${current_brightness}-${STEP_BRIGHTNESS}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change brightness
|
||||||
|
if [ "${new_brightness}" -ne "${current_brightness}" ]; then
|
||||||
|
brightness_set ${new_brightness}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_set ${NOTIF_TIME_ON} " BRIGHTNESS: ${new_brightness}%%"
|
||||||
|
exit 0
|
||||||
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_bright_up
Executable file
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_bright_up
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
STEP_BRIGHTNESS=10
|
||||||
|
NOTIF_TIME_ON=2
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_brightness=$(brightness_get)
|
||||||
|
|
||||||
|
# Compute new brightness value
|
||||||
|
new_brightness=${current_brightness}+${STEP_BRIGHTNESS}
|
||||||
|
if [ "${new_brightness}" -gt "100" ]; then
|
||||||
|
new_brightness=100
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change brightness
|
||||||
|
if [ "${new_brightness}" -ne "${current_brightness}" ]; then
|
||||||
|
brightness_set ${new_brightness}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_set ${NOTIF_TIME_ON} " BRIGHTNESS: ${new_brightness}%%"
|
||||||
|
exit 0
|
||||||
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_volume_down
Executable file
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_volume_down
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
STEP_VOLUME=10
|
||||||
|
NOTIF_TIME_ON=2
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_volume=$(volume_get)
|
||||||
|
|
||||||
|
# Compute new volume value
|
||||||
|
new_volume=0
|
||||||
|
if [ "${current_volume}" -gt "${STEP_VOLUME}" ]; then
|
||||||
|
new_volume=${current_volume}-${STEP_VOLUME}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change volume
|
||||||
|
if [ "${new_volume}" -ne "${current_volume}" ]; then
|
||||||
|
volume_set ${new_volume}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_set ${NOTIF_TIME_ON} " VOLUME: ${new_volume}%%"
|
||||||
|
exit 0
|
||||||
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_volume_up
Executable file
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/quick_action_volume_up
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
STEP_VOLUME=10
|
||||||
|
NOTIF_TIME_ON=2
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_volume=$(volume_get)
|
||||||
|
|
||||||
|
# Compute new volume value
|
||||||
|
new_volume=${current_volume}+${STEP_VOLUME}
|
||||||
|
if [ "{new_$volume}" -gt "100" ]; then
|
||||||
|
new_volume=100
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change volume
|
||||||
|
if [ "${new_volume}" -ne "{current_$volume}" ]; then
|
||||||
|
volume_set ${new_volume}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_set ${NOTIF_TIME_ON} " VOLUME: ${new_volume}%%"
|
||||||
|
exit 0
|
||||||
15
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/sched_shutdown
Executable file
15
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/sched_shutdown
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "${#}" != "1" ]; then
|
||||||
|
echo "Usage: $0 seconds_before_shutdown"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
nb_secs_to_wait=$1
|
||||||
|
|
||||||
|
# Wait $nb_secs_to_wait seconds to catch signal USR2
|
||||||
|
# If the signal is caught, then it means a process canceled this shutdown
|
||||||
|
sleep ${nbl_secs_to_wait}
|
||||||
|
|
||||||
|
# Too late to cancel: init shutdown
|
||||||
|
shutdown_funkey
|
||||||
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/shutdown_funkey
Executable file
22
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/shutdown_funkey
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Notif fullscreen "Shutting down"
|
||||||
|
notif_set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
|
||||||
|
|
||||||
|
# Kill Emulators
|
||||||
|
#kill_emulators >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Kill Retrofe
|
||||||
|
#pkill retrofe
|
||||||
|
|
||||||
|
# Sync filesystems (useful in case poweroff could not finish)
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Unmount Roms partition
|
||||||
|
umount /mnt
|
||||||
|
|
||||||
|
# Shutdown amp
|
||||||
|
start_audio_amp 0 >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Poweroff
|
||||||
|
poweroff
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# This should replaced by storing the correct PID before
|
||||||
|
# launching an emulator and signaling only this one.
|
||||||
|
|
||||||
|
killall -s USR1 mednafen gpsp psnes pcsx sdlgnuboy PicoDriveBin >/dev/null 2>&1
|
||||||
|
exit 0
|
||||||
31
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_audio_amp
Executable file
31
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_audio_amp
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Check number of args
|
||||||
|
if [ "${#}" -ne "1" ]; then
|
||||||
|
echo "Usage: $0 [1 for on, 0 for off]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check Enable arg
|
||||||
|
enable=$1
|
||||||
|
if [ "${enable}" -eq "1" ]; then
|
||||||
|
echo "Turning ampli ON"
|
||||||
|
elif [ "${enable}" -eq "0" ]; then
|
||||||
|
echo "Turning ampli OFF"
|
||||||
|
else
|
||||||
|
echo "Usage: ${0} [1 for on, 0 for off]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# PA enable GPIO
|
||||||
|
GPIO_PF6=166
|
||||||
|
|
||||||
|
# Export GPIO
|
||||||
|
if [ ! -d "/sys/class/gpio/gpio${GPIO_PF6}" ]; then
|
||||||
|
echo ${GPIO_PF6} > "/sys/class/gpio/export"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable/disable cmd
|
||||||
|
echo "out" > "/sys/class/gpio/gpio${GPIO_PF6}/direction"
|
||||||
|
echo ${enable} > "/sys/class/gpio/gpio${GPIO_PF6}/value"
|
||||||
|
exit 0
|
||||||
12
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_gpio_manager
Executable file
12
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_gpio_manager
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
LOCK_FILE="/var/lock/gpio_manager.lock"
|
||||||
|
|
||||||
|
if [ -f "${LOCK_FILE}" ]; then
|
||||||
|
echo "${LOCK_FILE} already exists"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
touch "${LOCK_FILE}"
|
||||||
|
funkey_gpio_management
|
||||||
|
rm "${LOCK_FILE}"
|
||||||
|
exit 0
|
||||||
43
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_launcher
Executable file
43
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/start_launcher
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
LOCK_FILE="/var/lock/launcher.lock"
|
||||||
|
PREVENT_LAUNCHER_FILE="/mnt/prevent_launcher"
|
||||||
|
PREVENT_LAUNCHER_FILE2="/boot/prevent_launcher"
|
||||||
|
|
||||||
|
if [ -f "${LOCK_FILE}" ]; then
|
||||||
|
echo "${LOCK_FILE} already exists"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
touch "${LOCK_FILE}"
|
||||||
|
|
||||||
|
# Launch Previous Game
|
||||||
|
QUICK_LOAD_FILE="/root/quick_load_cmd"
|
||||||
|
if [ -f "${QUICK_LOAD_FILE}" ]; then
|
||||||
|
command=$(cat "${QUICK_LOAD_FILE}")
|
||||||
|
echo "Found quick load file, restarting previous game with command:"
|
||||||
|
echo ${command}
|
||||||
|
rm "${QUICK_LOAD_FILE}"
|
||||||
|
eval ${command}
|
||||||
|
termfix_all
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Loop to launch launcher indefinitely
|
||||||
|
while true; do
|
||||||
|
|
||||||
|
# Check if prevent launcher file present
|
||||||
|
if [ -f "${PREVENT_LAUNCHER_FILE}" ]; then
|
||||||
|
echo "Found file: ${PREVENT_LAUNCHER_FILE}, not launching launcher"
|
||||||
|
sleep 5
|
||||||
|
elif [ -f "${PREVENT_LAUNCHER_FILE2}" ]; then
|
||||||
|
echo "Found file: ${PREVENT_LAUNCHER_FILE2}, not launching launcher"
|
||||||
|
sleep 5
|
||||||
|
else
|
||||||
|
# Launch Retrofe
|
||||||
|
retrofe
|
||||||
|
|
||||||
|
# In case retrofe quits with errors, clear graphic VT
|
||||||
|
termfix_all
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
rm "${LOCK_FILE}"
|
||||||
|
exit 0
|
||||||
37
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/system_stats
Executable file
37
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/system_stats
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
UPDATE_PERIOD=2 #seconds
|
||||||
|
notif_dirty=0
|
||||||
|
perform=0
|
||||||
|
|
||||||
|
# USR1 callback
|
||||||
|
function toggle_perform()
|
||||||
|
{
|
||||||
|
let perform=1-${perform}
|
||||||
|
if [ "${perform}" -eq "0" ]; then
|
||||||
|
notif_clear
|
||||||
|
notif_dirty=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
trap toggle_perform SIGUSR1
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if [ "${perform}" -eq "1" ]; then
|
||||||
|
|
||||||
|
# Compute stats
|
||||||
|
cpu=$(printf "%.1f\n" $(mpstat -P ALL $UPDATE_PERIOD 1 | tail -1 | awk '{print 100-$12}'))
|
||||||
|
ram_mem=$(printf "%.1f\n" $(free | grep Mem | awk '{print $3/$2 * 100.0}'))
|
||||||
|
ram_swap=$(printf "%.1f\n" $(free | grep Swap | awk '{print $3/$2 * 100.0}'))
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
if [ "${notif_dirty}" == "1" ]]; then
|
||||||
|
notif_clear
|
||||||
|
notif_dirty=0
|
||||||
|
else
|
||||||
|
notif_set 0 "CPU:${cpu}%% RAM:${ram_mem}%% SWAP:${ram_swap}%%"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
sleep ${UPDATE_PERIOD}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
6
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/termfix_all
Executable file
6
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/termfix_all
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
for i in $(seq 0 11); do
|
||||||
|
termfix /dev/tty$i
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
257
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/upgrade_fk_incremental
Executable file
257
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/upgrade_fk_incremental
Executable file
@ -0,0 +1,257 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# Functions declaration #
|
||||||
|
#########################
|
||||||
|
notif_system_corruption () {
|
||||||
|
local time_on_screen=30
|
||||||
|
local reason=""
|
||||||
|
|
||||||
|
if [[ "$#" -ge "1" ]]; then
|
||||||
|
time_on_screen=$1
|
||||||
|
fi
|
||||||
|
if [[ "$#" -ge "2" ]]; then
|
||||||
|
reason=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
notif_set $time_on_screen "^YOUR SYSTEM IS CORRUPTED:^$reason^^PLEASE REFLASH YOUR SD CARD"
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_with_reason () {
|
||||||
|
local reason=$EXIT_CODE_FAILURE
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [[ "$#" -ge "1" ]]; then
|
||||||
|
reason=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "EXIT FAILURE $EXIT_CODE_FAILURE, check log file"
|
||||||
|
|
||||||
|
# Remove extraction folder
|
||||||
|
if [[ -d $EXTRACT_DIRECTORY ]]; then
|
||||||
|
echo "Removing extraction directory: $EXTRACT_DIRECTORY" >> $LOG_FILE_UPGRADE
|
||||||
|
rm -rf $EXTRACT_DIRECTORY
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy log file to UPGRADE_ARCHIVES_DIRECTORY
|
||||||
|
cp "$LOG_FILE_UPGRADE" "$LOG_FILE_UPGRADE_COPY"
|
||||||
|
|
||||||
|
exit $reason
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_failure () {
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE
|
||||||
|
}
|
||||||
|
|
||||||
|
get_targz_uncompressed_size () {
|
||||||
|
# check arg
|
||||||
|
if [[ "$#" != "1" ]]; then
|
||||||
|
extracted_size=0
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
extracted_size=$(tar tzvf "$1" | sed 's/ \+/ /g' | cut -f3 -d' ' | sed '2,$s/^/+ /' | paste -sd' ' | bc)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
################
|
||||||
|
# Exit reasons #
|
||||||
|
################
|
||||||
|
EXIT_CODE_SUCCESS=0
|
||||||
|
EXIT_CODE_FAILURE=1
|
||||||
|
EXIT_CODE_FAILURE_NO_VERSION=2
|
||||||
|
EXIT_CODE_FAILURE_WRONG_VERSION=3
|
||||||
|
EXIT_CODE_FAILURE_WRONG_TAR_GZ=4
|
||||||
|
EXIT_CODE_FAILURE_WRONG_MD5=5
|
||||||
|
EXIT_CODE_FAILURE_WRONG_EXTRACT_SIZE=6
|
||||||
|
EXIT_CODE_FAILURE_NO_SPACE=7
|
||||||
|
EXIT_CODE_FAILURE_EXTRACT_FAILED=8
|
||||||
|
EXIT_CODE_FAILURE_SCRIPT_NOT_FOUND=9
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# Files declaration #
|
||||||
|
#####################
|
||||||
|
FUNKEY_VERSION_FILE="/etc/funkey_version"
|
||||||
|
UPGRADE_ARCHIVES_DIRECTORY="/mnt/"
|
||||||
|
EXTRACT_DIRECTORY=$UPGRADE_ARCHIVES_DIRECTORY/update_tmp
|
||||||
|
LOG_FILES_DIRECTORY="/usr/local/etc/upgrade_logs/"
|
||||||
|
LOG_FILE_UPGRADE="$LOG_FILES_DIRECTORY/upgrade_log_$(date +%m-%d-%y_%T).txt"
|
||||||
|
LOG_FILE_UPGRADE_COPY="$UPGRADE_ARCHIVES_DIRECTORY/upgrade_log.txt"
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Vars declaration #
|
||||||
|
####################
|
||||||
|
upgrade_needed=0
|
||||||
|
upgrade_error=0
|
||||||
|
extracted_size=0
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Process Upgrade #
|
||||||
|
###################
|
||||||
|
# Init log files
|
||||||
|
mkdir -p $LOG_FILES_DIRECTORY
|
||||||
|
echo -e "******* Upgrade Incremental FunKey, $(date) *******\n" > $LOG_FILE_UPGRADE
|
||||||
|
test -f $LOG_FILE_UPGRADE_COPY && rm $LOG_FILE_UPGRADE_COPY
|
||||||
|
|
||||||
|
# Get current FunKey version
|
||||||
|
if [[ -f $FUNKEY_VERSION_FILE ]]; then
|
||||||
|
FUNKEY_VERSION=$(cat $FUNKEY_VERSION_FILE)
|
||||||
|
|
||||||
|
# Check if positive number (float or integer)
|
||||||
|
if [[ "$FUNKEY_VERSION" != ^[+-]?[0-9]*$ ]];then
|
||||||
|
echo "Current FunKey version = $FUNKEY_VERSION" >> $LOG_FILE_UPGRADE
|
||||||
|
elif [[ "$FUNKEY_VERSION" != ^[+-]?[0-9]+\.?[0-9]*$ ]];then
|
||||||
|
echo "Current FunKey version = $FUNKEY_VERSION" >> $LOG_FILE_UPGRADE
|
||||||
|
else
|
||||||
|
echo "WRONG FUNKEY VERSION FOUND: $FUNKEY_VERSION !" >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_system_corruption 20 "WRONG VERSION: $FUNKEY_VERSION"
|
||||||
|
|
||||||
|
# Exit failure
|
||||||
|
upgrade_error=1
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_NO_VERSION
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "NO FUNKEY VERSION FOUND !" >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
# Notif
|
||||||
|
notif_system_corruption 20 "NO VERSION"
|
||||||
|
|
||||||
|
# Exit failure
|
||||||
|
upgrade_error=1
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_WRONG_VERSION
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if upgrade file is present
|
||||||
|
upgrade_archive=$(ls -v $UPGRADE_ARCHIVES_DIRECTORY/upgrade_funkey_${FUNKEY_VERSION}_to_*.tar.gz 2> /dev/null | head -1)
|
||||||
|
other_upgrade_archives=$(ls $UPGRADE_ARCHIVES_DIRECTORY/upgrade_funkey_*.tar.gz 2> /dev/null)
|
||||||
|
if [[ ! -z "$upgrade_archive" ]]; then
|
||||||
|
echo -e "Upgrade archive found:\n $upgrade_archive" >> $LOG_FILE_UPGRADE
|
||||||
|
#echo -e "Upgrade archive found:\n $upgrade_archive"
|
||||||
|
upgrade_needed=1
|
||||||
|
elif [[ ! -z "$other_upgrade_archives" ]]; then
|
||||||
|
echo -e "Other upgrades files found:\n $other_upgrade_archives" >> $LOG_FILE_UPGRADE
|
||||||
|
else
|
||||||
|
echo "No upgrade files found" >> $LOG_FILE_UPGRADE
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$upgrade_needed" == "1" ]]; then
|
||||||
|
|
||||||
|
# Check if tar.gz file is valid
|
||||||
|
tar_gz_file_list=$(tar -tzf "$upgrade_archive" 2>/dev/null)
|
||||||
|
tar_gz_validity=$?
|
||||||
|
if [[ "$tar_gz_validity" != "0" ]]; then
|
||||||
|
echo "WRONG TAR.GZ FILE" >> $LOG_FILE_UPGRADE
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_WRONG_TAR_GZ
|
||||||
|
else
|
||||||
|
echo -e "\nList of files in archive:" >> $LOG_FILE_UPGRADE
|
||||||
|
echo $tar_gz_file_list >> $LOG_FILE_UPGRADE
|
||||||
|
echo -e "\n" >> $LOG_FILE_UPGRADE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if archive integrity is ok
|
||||||
|
file_no_ext=${upgrade_archive%.tar.gz}
|
||||||
|
md5_read=${file_no_ext##*_}
|
||||||
|
echo "MD5 read from file: $md5_read" >> $LOG_FILE_UPGRADE
|
||||||
|
md5_computed=$(md5sum $upgrade_archive | cut -d' ' -f1)
|
||||||
|
echo "MD5 computed from file: $md5_computed" >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
if [[ "$md5_read" != "$md5_computed" ]]; then
|
||||||
|
echo "WRONG MD5" >> $LOG_FILE_UPGRADE
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_WRONG_MD5
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get size of uncompressed data
|
||||||
|
get_targz_uncompressed_size "$upgrade_archive"
|
||||||
|
if [[ $extracted_size == "0" ]]; then
|
||||||
|
echo "CANNOT COMPUTE EXTRACTED SIZE" >> $LOG_FILE_UPGRADE
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_WRONG_EXTRACT_SIZE
|
||||||
|
fi
|
||||||
|
echo "Extracted archive size: $extracted_size" >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
# Check if enough space in /mnt for extraction
|
||||||
|
free_space=$(($(stat -f --format="%a*%S" $UPGRADE_ARCHIVES_DIRECTORY)))
|
||||||
|
echo "Free space in $UPGRADE_ARCHIVES_DIRECTORY: $free_space" >> $LOG_FILE_UPGRADE
|
||||||
|
if [[ "$free_space" -le "$extracted_size" ]]; then
|
||||||
|
missing_space=$(echo "$extracted_size - $free_space" | bc )
|
||||||
|
format_missing_space=$(numfmt --to=iec --suffix=B $missing_space)
|
||||||
|
echo "NOT ENOUGH FREE SPACE FOR EXTRACTION, MISSING $format_missing_space" >> $LOG_FILE_UPGRADE
|
||||||
|
echo "NOT ENOUGH FREE SPACE FOR EXTRACTION, MISSING $format_missing_space"
|
||||||
|
|
||||||
|
notif_set 20 "^NOT ENOUGH SPACE FOR UPDATE^PLEASE FREE $format_missing_space"
|
||||||
|
|
||||||
|
exit_with_reason $EXIT_CODE_FAILURE_NO_SPACE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove and create extraction folder
|
||||||
|
if [[ -d $EXTRACT_DIRECTORY ]]; then
|
||||||
|
echo "Removing extraction directory: $EXTRACT_DIRECTORY" >> $LOG_FILE_UPGRADE
|
||||||
|
rm -rf $EXTRACT_DIRECTORY
|
||||||
|
fi
|
||||||
|
mkdir $EXTRACT_DIRECTORY
|
||||||
|
|
||||||
|
# Notif before achive extraction
|
||||||
|
notif_set 0 "^^^^^^^ UPGRADE IN PROGRESS... ^ EXTRACTING FILES^^DO NOT TURN OFF THE CONSOLE! ^^^^^^"
|
||||||
|
|
||||||
|
# Extract archive
|
||||||
|
echo "Extracting to directory: $EXTRACT_DIRECTORY" >> $LOG_FILE_UPGRADE
|
||||||
|
tar xzf $upgrade_archive -C $EXTRACT_DIRECTORY 2> /dev/null
|
||||||
|
if [[ "$?" != "0" ]]; then
|
||||||
|
echo "EXTRACTION FAILED" >> $LOG_FILE_UPGRADE
|
||||||
|
exit_with_reason EXIT_CODE_FAILURE_EXTRACT_FAILED
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Extracted directory content:" >> $LOG_FILE_UPGRADE
|
||||||
|
ls $EXTRACT_DIRECTORY >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
# Check for update script
|
||||||
|
upgrade_script=$(ls $EXTRACT_DIRECTORY/launch_upgrade.sh 2> /dev/null | head -1)
|
||||||
|
if [[ -z "$upgrade_script" ]]; then
|
||||||
|
echo -e "UPGRADE SCRIPT NOT FOUND" >> $LOG_FILE_UPGRADE
|
||||||
|
echo -e "UPGRADE SCRIPT NOT FOUND"
|
||||||
|
|
||||||
|
notif_set 20 "^UPDATE FAILED:^SCRIPT NOT FOUND^^WRONG UPGRADE FILE"
|
||||||
|
exit_with_reason EXIT_CODE_FAILURE_SCRIPT_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Display notif before launching script
|
||||||
|
notif_set 0 "^^^^^^^ UPGRADE IN PROGRESS... ^$(basename "$upgrade_archive")^^DO NOT TURN OFF THE CONSOLE! ^^^^^^"
|
||||||
|
|
||||||
|
# Launch upgrade script
|
||||||
|
echo -e "Launching upgrade script" >> $LOG_FILE_UPGRADE
|
||||||
|
chmod 777 $upgrade_script
|
||||||
|
$upgrade_script "$LOG_FILE_UPGRADE"
|
||||||
|
if [[ "$?" != "0" ]]; then
|
||||||
|
echo -e "UPGRADE SCRIPT FAILURE" >> $LOG_FILE_UPGRADE
|
||||||
|
exit_failure
|
||||||
|
fi
|
||||||
|
echo -e "Upgrade script successfull" >> $LOG_FILE_UPGRADE
|
||||||
|
|
||||||
|
# Remove upgrade archive
|
||||||
|
echo -e "Remove upgrade archive" >> $LOG_FILE_UPGRADE
|
||||||
|
rm $upgrade_archive
|
||||||
|
|
||||||
|
# Remove and create extraction folder
|
||||||
|
if [[ -d $EXTRACT_DIRECTORY ]]; then
|
||||||
|
echo "Removing extraction directory: $EXTRACT_DIRECTORY" >> $LOG_FILE_UPGRADE
|
||||||
|
rm -rf $EXTRACT_DIRECTORY
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Notif upgrade successfull
|
||||||
|
notif_set 0 "^^^^^^^^ UPGRADE SUCCESSFUL^ REBOOTING NOW^^^^^^^"
|
||||||
|
sleep 2
|
||||||
|
notif_clear
|
||||||
|
|
||||||
|
# Reboot FunKey
|
||||||
|
reboot
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no upgrade, remove log file
|
||||||
|
if [[ "$upgrade_needed" == "0" && "$upgrade_error" == "0" ]]; then
|
||||||
|
rm $LOG_FILE_UPGRADE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exit success
|
||||||
|
exit $EXIT_CODE_SUCCESS
|
||||||
20
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_get
Executable file
20
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_get
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
VOLUME_FILE="/etc/current_volume"
|
||||||
|
VOLUME_DEFAULT_VALUE=50
|
||||||
|
|
||||||
|
# Sanity check: File does not exist
|
||||||
|
if [ ! -f "${VOLUME_FILE}" ]; then
|
||||||
|
#echo "error: \"${VOLUME_FILE}\" does not exist" >&2
|
||||||
|
echo ${VOLUME_DEFAULT_VALUE} > "${VOLUME_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sanity check: Check if integer
|
||||||
|
volume=$(cat "${VOLUME_FILE}")
|
||||||
|
if ! [ "${volume}" -ne "${volume}" ] ; then
|
||||||
|
#echo "error: \"${volume}\" is not a number" >&2
|
||||||
|
echo ${VOLUME_DEFAULT_VALUE} > "${VOLUME_FILE}"
|
||||||
|
volume=${VOLUME_DEFAULT_VALUE}
|
||||||
|
fi
|
||||||
|
echo ${volume}
|
||||||
|
exit 0
|
||||||
4
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_get_alsa
Executable file
4
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_get_alsa
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
amixer sget 'Headphone' | tail -1 | cut -d' ' -f7 | sed 's/[^0-9]//g'
|
||||||
|
exit 0
|
||||||
45
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_set
Executable file
45
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_set
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
VOLUME_FILE="/etc/current_volume"
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ ${#} != 1 ]; then
|
||||||
|
echo "Usage: ${0} new_volume_percentage"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check value's range
|
||||||
|
if [ ${1} -gt 100 ]; then
|
||||||
|
echo "Usage: Wrong volume percentage (${1}), must be between 0 and 100"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Scale new volume value between 0 and 63
|
||||||
|
volume_percent=${1}
|
||||||
|
volume_integer=$(echo ${volume_percent} 63 100 | awk '{printf int($1*$2/$3)}')
|
||||||
|
volume_decimal=$(echo ${volume_percent} 63 100 ${volume_integer} | awk '{printf (($1*$2/$3)-$4)*100}')
|
||||||
|
if [ "${volume_decimal}" -ge "63" ]; then
|
||||||
|
let volume_integer++
|
||||||
|
fi
|
||||||
|
volume_scaled=${volume_integer}
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_volume=$(volume_get)
|
||||||
|
|
||||||
|
# Turn on/off ampli if necessary
|
||||||
|
if [ "${current_volume}" -eq "0" -a "${volume_scaled}" -ne "0" ]; then
|
||||||
|
echo "Turning AMP on"
|
||||||
|
start_audio_amp 1
|
||||||
|
elif [ "${current_volume}" -ne "0" -a "${volume_scaled}" -eq "0" ]; then
|
||||||
|
echo "Turning AMP off"
|
||||||
|
start_audio_amp 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set new volume
|
||||||
|
amixer -q sset 'Headphone' ${volume_scaled} unmute
|
||||||
|
|
||||||
|
# Change new volume value in volume file
|
||||||
|
if [ ${?} -eq 0 ]; then
|
||||||
|
echo ${volume_percent} > "${VOLUME_FILE}"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
38
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_set_alsa
Executable file
38
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/volume_set_alsa
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ ${#} != 1 ]; then
|
||||||
|
echo "Usage: ${0} new_volume_percentage"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check value's range
|
||||||
|
if [ ${1} -gt 100 ]; then
|
||||||
|
echo "Usage: Wrong volume percentage (${1}), must be between 0 and 100"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Scale new volume value between 0 and 63
|
||||||
|
volume_percent=${1}
|
||||||
|
volume_integer=$(echo ${volume_percent} 63 100 | awk '{printf int($1*$2/$3)}')
|
||||||
|
volume_deccimal=$(echo ${volume_percent} 63 100 ${volume_integer} | awk '{printf (($1*$2/$3)-$4)*100}')
|
||||||
|
if [ "{$volume_decimal}" -ge "63" ]; then
|
||||||
|
let volume_integer++
|
||||||
|
fi
|
||||||
|
volume_scaled=${volume_integer}
|
||||||
|
|
||||||
|
# Get current value
|
||||||
|
current_volume=$(volume_get)
|
||||||
|
|
||||||
|
# Turn on/off ampli if necessary
|
||||||
|
if [ "${current_volume}" -eq "0" -a "${volume_scaled}" -ne "0" ]; then
|
||||||
|
echo "Turning AMP on"
|
||||||
|
start_audio_amp 1
|
||||||
|
elif [ "${current_volume}" -ne "0" -a "${volume_scaled}" -eq "0" ]; then
|
||||||
|
echo "Turning AMP off"
|
||||||
|
start_audio_amp 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set new volume
|
||||||
|
amixer -q sset 'Headphone' ${volume_scaled} unmute
|
||||||
|
exit 0
|
||||||
17
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/write_args_quick_load_file
Executable file
17
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/write_args_quick_load_file
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Write quick load file args
|
||||||
|
QUICK_LOAD_FILE="/root/quick_load_cmd"
|
||||||
|
|
||||||
|
printf "" > $QUICK_LOAD_FILE
|
||||||
|
|
||||||
|
whitespace="[[:space:]]"
|
||||||
|
for i in "$@"; do
|
||||||
|
if [[ "$i" != $whitespace && "$i" != "SDL_NOMOUSE=1" ]]
|
||||||
|
then
|
||||||
|
i=\""$i"\"
|
||||||
|
fi
|
||||||
|
printf "%s" "$i " >> $QUICK_LOAD_FILE
|
||||||
|
done
|
||||||
|
printf "\n" >> $QUICK_LOAD_FILE
|
||||||
|
exit 0
|
||||||
Loading…
x
Reference in New Issue
Block a user