Skip to content
Snippets Groups Projects

main: automatically update python files

Merged q3k requested to merge q3k/autoupdate into main
1 file
+ 53
8
Compare changes
  • Side-by-side
  • Inline
+ 53
8
@@ -6,18 +6,33 @@
#include "st3m_mode.h"
#include "st3m_sys_data.h"
#include "st3m_tar.h"
#include "st3m_version.h"
#include "esp_system.h"
#include "esp_vfs.h"
#include "esp_vfs_fat.h"
static const char *TAG = "st3m-fs";
static bool _updating = false;
static const char *sysflag = "/flash/sys/.sys-installed";
static void _extract_callback(const char *path) {
char msg[256];
snprintf(msg, 256, "Installing %s...", path);
// Strip /flash/sys/ from displayed paths...
const char *prefix = "/flash/sys/";
if (strstr(path, prefix) == path) {
path += strlen(prefix);
}
if (_updating) {
snprintf(msg, 256, "Updating %s", path);
} else {
snprintf(msg, 256, "Installing %s", path);
}
size_t limit = 30;
if (strlen(msg) > limit) {
strlcpy(msg + limit, "...", 256 - limit);
}
st3m_mode_set(st3m_mode_kind_starting, msg);
}
@@ -37,10 +52,16 @@ static void _extract_sys_data(void) {
FILE *f = fopen(sysflag, "w");
assert(f != NULL);
fprintf(f, "remove me to reinstall /sys on next startup");
fprintf(f, "%s", st3m_version);
fclose(f);
}
typedef enum {
sys_state_absent = 0,
sys_state_diff_version = 1,
sys_state_correct = 2,
} sys_state_t;
void flow3r_fs_init(void) {
st3m_fs_init();
@@ -50,16 +71,40 @@ void flow3r_fs_init(void) {
return;
}
bool have_mpy = false;
sys_state_t state = sys_state_absent;
char local_version[128];
struct stat st;
if (stat(sysflag, &st) == 0) {
have_mpy = S_ISREG(st.st_mode);
if (stat(sysflag, &st) == 0 && S_ISREG(st.st_mode)) {
state = sys_state_diff_version;
FILE *f = fopen(sysflag, "r");
size_t len = fread(local_version, 1, sizeof(local_version) - 1, f);
fclose(f);
local_version[len] = 0;
if (strcmp(st3m_version, local_version) == 0) {
state = sys_state_correct;
}
}
if (!have_mpy) {
if (state == sys_state_absent) {
st3m_mode_set(st3m_mode_kind_starting, "Installing /flash/sys...");
ESP_LOGI(TAG, "No %s on flash, preparing sys directory...", sysflag);
_updating = false;
ESP_LOGI(
TAG,
"Installing /sys/flash... (st3m version: %s, local version: none)",
st3m_version);
_extract_sys_data();
st3m_mode_set(st3m_mode_kind_starting,
"Installed, continuing startup...");
}
if (state == sys_state_diff_version) {
st3m_mode_set(st3m_mode_kind_starting, "Updating /flash/sys...");
_updating = true;
ESP_LOGI(TAG,
"Updating /sys/flash... (st3m version: %s, local version: %s)",
st3m_version, local_version);
_extract_sys_data();
st3m_mode_set(st3m_mode_kind_starting,
"Updated, continuing startup...");
}
esp_err_t ret = st3m_fs_sd_mount();
Loading