Detect not only 'Raspbian', but also 'Debian' and 'NixOS'

This commit is contained in:
Jan Vornberger 2022-05-30 23:56:15 +02:00
commit e2b1fcdbf9

View file

@ -28,7 +28,6 @@
# #
******************************************************************************/ ******************************************************************************/
#include "DEV_Config.h" #include "DEV_Config.h"
#include <fcntl.h>
/** /**
* GPIO * GPIO
@ -202,53 +201,47 @@ void DEV_Delay_ms(UDOUBLE xms)
static int DEV_Equipment_Testing(void) static int DEV_Equipment_Testing(void)
{ {
int i; FILE *fp;
int fd; char issue_str[64];
char value_str[20];
fd = open("/etc/issue", O_RDONLY); fp = fopen("/etc/issue", "r");
printf("Current environment: "); if (fp == NULL) {
while(1) { Debug("Unable to open /etc/issue");
if (fd < 0) { return -1;
Debug( "Read failed Pin\n");
return -1;
}
for(i=0;; i++) {
if (read(fd, &value_str[i], 1) < 0) {
Debug( "failed to read value!\n");
return -1;
}
if(value_str[i] ==32) {
printf("\r\n");
break;
}
printf("%c",value_str[i]);
}
break;
} }
if (fread(issue_str, 1, sizeof(issue_str), fp) <= 0) {
Debug("Unable to read from /etc/issue");
return -1;
}
issue_str[sizeof(issue_str)-1] = '\0';
fclose(fp);
printf("Current environment: ");
#ifdef RPI #ifdef RPI
if(i<5) { char systems[][9] = {"Raspbian", "Debian", "NixOS"};
printf("Unrecognizable\r\n"); int detected = 0;
} else { for(int i=0; i<3; i++) {
char RPI_System[10] = {"Raspbian"}; if (strstr(issue_str, systems[i]) != NULL) {
for(i=0; i<6; i++) { printf("%s\n", systems[i]);
if(RPI_System[i]!= value_str[i]) { detected = 1;
printf("Please make JETSON !!!!!!!!!!\r\n");
return -1;
}
} }
} }
if (!detected) {
printf("not recognized\n");
printf("Built for Raspberry Pi, but unable to detect environment.\n");
printf("Perhaps you meant to 'make JETSON' instead?\n");
return -1;
}
#endif #endif
#ifdef JETSON #ifdef JETSON
if(i<5) { char system[] = {"Ubuntu"};
Debug("Unrecognizable\r\n"); if (strstr(issue_str, system) != NULL) {
printf("%s\n", system);
} else { } else {
char JETSON_System[10]= {"Ubuntu"}; printf("not recognized\n");
for(i=0; i<6; i++) { printf("Built for Jetson, but unable to detect environment.\n");
if(JETSON_System[i]!= value_str[i] ) { printf("Perhaps you meant to 'make RPI' instead?\n");
printf("Please make RPI !!!!!!!!!!\r\n"); return -1;
return -1;
}
}
} }
#endif #endif
return 0; return 0;