Skip to content

Commit

Permalink
Add openwrt version information and exclude it from autobackups
Browse files Browse the repository at this point in the history
  • Loading branch information
widgetii committed Mar 13, 2021
1 parent 63ad3e6 commit f16dc0a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ add_executable(ipc_chip_info
src/tools.h
src/version.h

src/vendors/xm.h
src/vendors/openwrt.c
src/vendors/openwrt.h
src/vendors/xm.c
src/vendors/xm.h

${CMAKE_CURRENT_BINARY_DIR}/version.c
)
Expand Down
1 change: 1 addition & 0 deletions src/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
char system_id[128];
char system_manufacturer[128];
char board_id[128];
char board_ver[128];
char board_manufacturer[128];
char board_specific[1024];
char ram_specific[1024];
Expand Down
1 change: 1 addition & 0 deletions src/chipid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
extern char system_id[128];
extern char system_manufacturer[128];
extern char board_id[128];
extern char board_ver[128];
extern char board_manufacturer[128];
extern char board_specific[1024];
extern char ram_specific[1024];
Expand Down
25 changes: 18 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include "ram.h"
#include "sensors.h"
#include "tools.h"
#include "vendors/xm.h"
#include "version.h"

#include "vendors/openwrt.h"
#include "vendors/xm.h"

void Help() {
printf("ipc_chip_info, version: ");
const char *vers = get_git_version();
Expand Down Expand Up @@ -68,10 +70,16 @@ void print_board_id() {
if (!*board_manufacturer && !*board_id)
return;

yaml_printf("board:\n"
" vendor: %s\n"
" model: %s\n%s",
board_manufacturer, board_id, board_specific);
yaml_printf("board:\n");

if (*board_manufacturer)
yaml_printf(" vendor: %s\n", board_manufacturer);
if (*board_id)
yaml_printf(" model: %s\n", board_id);
if (*board_ver)
yaml_printf(" version: %s\n", board_ver);
if (*board_specific)
yaml_printf("%s", board_specific);
}

void print_chip_id() {
Expand Down Expand Up @@ -137,6 +145,9 @@ bool get_board_id() {
if (is_xm_board()) {
gather_xm_board_info();
return true;
} else if (is_openwrt_board()) {
gather_openwrt_board_info();
return true;
}
return false;
}
Expand All @@ -151,8 +162,8 @@ static void generic_system_data() { linux_mem(); }

#define MAX_YAML 1024 * 64
static bool backup_mode() {
// prevent double backup creation
if (!udp_lock())
// prevent double backup creation and don't backup OpenWrt firmware
if (!udp_lock() || is_openwrt_board())
return false;

int fds[2];
Expand Down
32 changes: 32 additions & 0 deletions src/vendors/openwrt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include "chipid.h"
#include "tools.h"
#include "vendors/openwrt.h"

bool is_openwrt_board() {
if (!access("/etc/openwrt_version", 0)) {
strcpy(board_manufacturer, "OpenWrt");
return true;
}
return false;
}

static bool detect_openwrt_product() {
char buf[256];

if (!get_regex_line_from_file("/etc/openwrt_version", "(.+)", buf,
sizeof(buf))) {
return false;
}
strcpy(board_ver, buf);
return true;
}

void gather_openwrt_board_info() { detect_openwrt_product(); }
9 changes: 9 additions & 0 deletions src/vendors/openwrt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef OPENWRT_H
#define OPENWRT_H

#include <stdbool.h>

void gather_openwrt_board_info();
bool is_openwrt_board();

#endif /* OPENWRT_H */

0 comments on commit f16dc0a

Please sign in to comment.