Skip to content

Commit

Permalink
Move system.json to SD and retain individual device settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 committed Oct 18, 2023
1 parent 88fe08d commit bd3853f
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/common/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "utils/json.h"

#define MAX_BRIGHTNESS 10
#define MAIN_UI_SETTINGS "/appconfigs/system.json"
#define MAIN_UI_SETTINGS "/mnt/SDCARD/system.json"
#define CMD_TO_RUN_PATH "/mnt/SDCARD/.tmp_update/cmd_to_run.sh"
#define RETROARCH_CONFIG "/mnt/SDCARD/RetroArch/.retroarch/retroarch.cfg"
#define HISTORY_PATH \
Expand Down
2 changes: 1 addition & 1 deletion src/common/theme/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "utils/file.h"
#include "utils/str.h"

#define SYSTEM_CONFIG "/appconfigs/system.json"
#define SYSTEM_CONFIG "/mnt/SDCARD/system.json"
#define FALLBACK_FONT "/customer/app/Exo-2-Bold-Italic.ttf"
#define FALLBACK_PATH "/mnt/SDCARD/miyoo/app/"
#define SYSTEM_RESOURCES "/mnt/SDCARD/.tmp_update/res/"
Expand Down
4 changes: 2 additions & 2 deletions src/tweaks/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ void action_resetMainUI(void *pt)
if (!_disable_confirm && !_confirmReset(title_str, "Are you sure you want to\nreset MainUI settings?"))
return;

system("rm -f /appconfigs/system.json");
system("rm -f /mnt/SDCARD/system.json");

char cmd_str[80];
sprintf(cmd_str, "cp /mnt/SDCARD/.tmp_update/res/miyoo%d_system.json /appconfigs/system.json", DEVICE_ID);
sprintf(cmd_str, "cp /mnt/SDCARD/.tmp_update/res/miyoo%d_system.json /mnt/SDCARD/system.json", DEVICE_ID);
system(cmd_str);

if (DEVICE_ID == MIYOO354) {
Expand Down
Binary file modified static/build/.tmp_update/bin/MainUI-283-clean
Binary file not shown.
Binary file modified static/build/.tmp_update/bin/MainUI-283-expert
Binary file not shown.
Binary file modified static/build/.tmp_update/bin/MainUI-354-clean
Binary file not shown.
Binary file modified static/build/.tmp_update/bin/MainUI-354-expert
Binary file not shown.
29 changes: 21 additions & 8 deletions static/build/.tmp_update/bin/shutdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,58 @@ if [ "$0" = "/tmp/_shutdown" ]; then
killall -9 main # mandatory to avoid the suppression of .tmp_update !
killall -9 updater
killall -9 runtime.sh
killall -9 smbd
killall -9 smbd

kill_hooked_tasks
sleep 0.1
kill_hooked_tasks -9

sync

if [ -f /mnt/SDCARD/system.json ]; then
mkdir -p /mnt/SDCARD/.tmp_update/config/system
mv -f /mnt/SDCARD/system.json "/mnt/SDCARD/.tmp_update/config/system/$(read_uuid).json"
sync
fi

rm -f /appconfigs/system.json 2> /dev/null
rm -f /mnt/SDCARD/update.log 2> /dev/null

umount /etc/passwd /etc/group /etc/profile
umount /mnt/SDCARD/miyoo/app/MainUI
umount /mnt/SDCARD/RetroArch/retroarch
umount /customer/lib/libgamename.so
swapoff /mnt/SDCARD/cachefile
umount -r /mnt/SDCARD
umount /mnt/SDCARD

############# DEBUG #############
# fuser -m /mnt/SDCARD > /appconfigs/shutdown.log
# lsof /mnt/SDCARD >> /appconfigs/shutdown.log
# mount >> /appconfigs/shutdown.log
#################################

if [ "$1" = "-r" ]; then
/sbin/reboot
else
if [ "$(cat /tmp/deviceModel)" = "283" ]; then
/sbin/reboot # no poweroff command on Miyoo Mini
/sbin/reboot # no poweroff command on Miyoo Mini
else
/sbin/poweroff
fi
fi

fi

if [ ! -f /tmp/_shutdown ]; then
cp -f "$0" /tmp/_shutdown
fi

# run the script totally detached from current shell
pgrep -f /tmp/_shutdown || (set -m; su root -c "/usr/bin/nohup /tmp/_shutdown $1 </dev/null >/dev/null 2>&1 &")
pgrep -f /tmp/_shutdown || (
set -m
su root -c "/usr/bin/nohup /tmp/_shutdown $1 </dev/null >/dev/null 2>&1 &"
)
while true; do
sleep 10
done
24 changes: 22 additions & 2 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,26 @@ init_system() {

start_audioserver

device_settings="/mnt/SDCARD/.tmp_update/config/system/$(read_uuid).json"
if [ -f "$device_settings" ]; then
cp -f "$device_settings" /mnt/SDCARD/system.json
fi

# make sure MainUI settings exist
if [ ! -f /mnt/SDCARD/system.json ]; then
if [ -f /appconfigs/system.json ]; then
cp -f /appconfigs/system.json /mnt/SDCARD/system.json
else
cp -f $sysdir/res/miyoo${DEVICE_ID}_system.json /mnt/SDCARD/system.json
fi
fi

# link /appconfigs/system.json to SD card
if [ -L /appconfigs/system.json ] && [ "$(readlink /appconfigs/system.json)" == "/mnt/SDCARD/system.json" ]; then
rm /appconfigs/system.json
fi
ln -s /mnt/SDCARD/system.json /appconfigs/system.json

if [ $DEVICE_ID -eq $MODEL_MM ]; then
# init charger detection
if [ ! -f /sys/devices/gpiochip0/gpio/gpio59/direction ]; then
Expand All @@ -505,11 +525,11 @@ init_system() {

if [ $(/customer/app/jsonval vol) -ne 20 ] || [ $(/customer/app/jsonval mute) -ne 0 ]; then
# Force volume and mute settings
cat /appconfigs/system.json |
cat /mnt/SDCARD/system.json |
sed 's/^\s*"vol":\s*[0-9][0-9]*/\t"vol":\t20/g' |
sed 's/^\s*"mute":\s*[0-9][0-9]*/\t"mute":\t0/g' \
> temp
mv -f temp /appconfigs/system.json
mv -f temp /mnt/SDCARD/system.json
fi
fi

Expand Down
40 changes: 20 additions & 20 deletions static/build/.tmp_update/script/diagnostics/util_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ program=$(basename "$0" .sh)
##################

main() {
log "Generating system snapshot, please wait"
snapshot
log "Starting exporter"
$diagsdir/util_exporter.sh
log "Generating system snapshot, please wait"
snapshot
log "Starting exporter"
$diagsdir/util_exporter.sh
}

##################
Expand Down Expand Up @@ -102,18 +102,18 @@ get_lcd_voltage() { # Check LCD voltage incase it's been changed by user
echo "$((voltage_tenths / 10)).$((voltage_tenths % 10)) volts."
}

actual_uptime() {
actual_uptime() {
uptime=$(cut -d. -f1 /proc/uptime)

uptime_days=$((uptime / 60 / 60 / 24))
uptime_hours=$((uptime / 60 / 60 % 24))
uptime_minutes=$((uptime / 60 % 60))
uptime_seconds=$((uptime % 60))

echo "Uptime: $uptime_days days, $uptime_hours hours, $uptime_minutes minutes, $uptime_seconds seconds"
}

system_healthcheck () {
system_healthcheck() {
log "Generating system healthcheck"
write_info "Onion version:" "cat $sysdir/onionVersion/version.txt" $sysinfo_file
write_info "Firmware version:" "/etc/fw_printenv miyoo_version" $sysinfo_file
Expand All @@ -130,9 +130,9 @@ system_healthcheck () {
write_info "LCD Voltage:" "get_lcd_voltage" $sysinfo_file
write_info "Framebuffer info:" "cat /proc/mi_modules/fb/mi_fb0" $sysinfo_file
write_info "More framebuffer info:" "fbset" $sysinfo_file
write_info "System.json state:" "cat /appconfigs/system.json" $sysinfo_file
write_info "Keymap state:" "cat $sysdir/config/keymap.json" $sysinfo_file
write_info "Config folder dump" "ls -alhR $sysdir/config/" $sysinfo_file
write_info "System.json state:" "cat /mnt/SDCARD/system.json" $sysinfo_file
write_info "Keymap state:" "cat $sysdir/config/keymap.json" $sysinfo_file
write_info "Config folder dump" "ls -alhR $sysdir/config/" $sysinfo_file
dmesg > "$workingdir/sysinfo/dmesg.log"
log "Finished generating healthcheck"
}
Expand Down Expand Up @@ -173,23 +173,23 @@ wpa_supplicant_health_check() {
fi
}

wpa_supplicant_contains_networks() {
wpa_supplicant_contains_networks() {
if [[ -f "$wpa_conf_path" ]]; then
num_ssids=$(grep -c "ssid=" "$wpa_conf_path")
num_disabled=$(grep -c "disabled=" "$wpa_conf_path")

echo "$num_ssids SSIDs configured, $num_disabled SSIDs disabled"
else
echo "Wpa_supplicant.conf is not present"
fi
}

get_wpa_supplicant() { # print the file aswell but remove the users ssid/psk - worth doing a full formatting check on the file incase syntax is broken by someone manually editing.
if [ ! -f "$wpa_conf_path" ]; then
echo "File not found: $wpa_conf_path"
fi
if [ ! -f "$wpa_conf_path" ]; then
echo "File not found: $wpa_conf_path"
fi

sed 's/ssid="[^"]*"/ssid="redacted"/g; s/psk="[^"]*"/psk="redacted"/g' "$wpa_conf_path"
sed 's/ssid="[^"]*"/ssid="redacted"/g; s/psk="[^"]*"/psk="redacted"/g' "$wpa_conf_path"
}

check_hostapd_conf() {
Expand Down Expand Up @@ -221,7 +221,7 @@ wifi_healthcheck() {
write_info "Network service:" "get_netserv_status" $networkinfo_file
write_info "Checking size of hostapd.conf:" "check_hostapd_conf" $networkinfo_file
write_info "Checking size of dnsmasq.conf" "check_dnsmasq_conf" $networkinfo_file
write_info "Wpa_supplicant.conf health:" "wpa_supplicant_health_check" $networkinfo_file
write_info "Wpa_supplicant.conf health:" "wpa_supplicant_health_check" $networkinfo_file
write_info "Wpa_supplicant.conf ssid count:" "wpa_supplicant_contains_networks" $networkinfo_file
write_info "Wpa_supplicant.conf sanitised dump:" "get_wpa_supplicant" $networkinfo_file
write_info "WiFi Status:" "ifconfig" $networkinfo_file
Expand Down Expand Up @@ -265,9 +265,9 @@ create_dir_logs() { # Currently creates a list of roms which can take a while de
fi
done
}

##################
## CALL MAIN FUNCTION ##
##################

main "$@"
main "$@"
28 changes: 14 additions & 14 deletions static/build/.tmp_update/script/network/wpsclient.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export IMGPOP=$sysdir/bin/imgpop
# Syntax: ./imgpop duration delay image_path x_position y_position.

main() {
if ifconfig wlan0 &>/dev/null; then
if ifconfig wlan0 &> /dev/null; then
if is_running wpa_supplicant && is_running udhcpc; then
wifiup
wifiup
fi
sleep 1
log "WPS: Wi-Fi is up"
Expand All @@ -25,27 +25,27 @@ main() {
wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf
sleep 2
killall -9 imgpop
sed -i 's/"wifi":\s*0/"wifi": 1/' /appconfigs/system.json # tell mainui that wifi needs to be kept up once started
sed -i 's/"wifi":\s*0/"wifi": 1/' /mnt/SDCARD/system.json # tell mainui that wifi needs to be kept up once started

if is_running wpa_supplicant; then
wifiup
sleep 1
fi

touch /tmp/dont_restart_wifi
sync
fi

start_udhcpc
$WPACLI disable_network all > /dev/null 2>&1 &# disconnect any existing networks
$WPACLI disable_network all > /dev/null 2>&1 & # disconnect any existing networks
log "WPS: Disconnecting from current network"
$WPACLI wps_pbc # start wps
log "WPS: Trying to connect to WPS host"

start_time=$(date +%s)

while true; do
IP=$(ip route get 1 2>/dev/null | awk '{print $NF;exit}')
IP=$(ip route get 1 2> /dev/null | awk '{print $NF;exit}')

if [ -z "$IP" ]; then
wpsflicker
Expand All @@ -60,9 +60,9 @@ main() {
log "WPS: Failed to connect.."
sleep 5
exit
else
else
wpsconnected
fi
fi
fi
else
break
Expand All @@ -77,8 +77,8 @@ main() {
exit
}

start_udhcpc(){
udhcpc -i wlan0 -s /etc/init.d/udhcpc.script > /dev/null 2>&1 &
start_udhcpc() {
udhcpc -i wlan0 -s /etc/init.d/udhcpc.script > /dev/null 2>&1 &
}

kill_udhcpc() {
Expand All @@ -89,19 +89,19 @@ kill_udhcpc() {

conn_cleanup() {
kill_udhcpc
start_udhcpc
start_udhcpc
}

is_running() {
process_name="$1"
pgrep "$process_name" > /dev/null
}

wifiquery(){
wifiquery() {
$IMGPOP 5 0 "$icondir/wifiquery.png" 84 428 > /dev/null 2>&1 &
}

wifiup(){
wifiup() {
$IMGPOP 5 0 "$icondir/wifiup.png" 84 428 > /dev/null 2>&1 &
}

Expand Down
2 changes: 1 addition & 1 deletion static/dist/miyoo/app/.tmp_update/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ run_installation() {

if [ $system_only -ne 1 ]; then
if [ $reset_configs -eq 1 ]; then
cp -f $sysdir/res/miyoo${DEVICE_ID}_system.json /appconfigs/system.json
cp -f $sysdir/res/miyoo${DEVICE_ID}_system.json /mnt/SDCARD/system.json
fi

# Start the battery monitor
Expand Down

0 comments on commit bd3853f

Please sign in to comment.