124 lines
No EOL
4.5 KiB
C
124 lines
No EOL
4.5 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ncurses.h>
|
|
|
|
/* define ANSI escape chars */
|
|
#define RESET "\033[0m"
|
|
#define BOLD "\033[1m"
|
|
#define UNDERLINE "\033[4m"
|
|
#define BLINK "\033[5m"
|
|
#define REVERSED "\033[7m"
|
|
#define BLACK "\033[30m"
|
|
#define RED "\033[31m"
|
|
#define GREEN "\033[32m"
|
|
#define YELLOW "\033[33m"
|
|
#define BLUE "\033[34m"
|
|
#define MAGENTA "\033[35m"
|
|
#define CYAN "\033[36m"
|
|
#define WHITE "\033[37m"
|
|
#define BG_BLACK "\033[40m"
|
|
#define BG_RED "\033[41m"
|
|
#define BG_GREEN "\033[42m"
|
|
#define BG_YELLOW "\033[43m"
|
|
#define BG_BLUE "\033[44m"
|
|
#define BG_MAGENTA "\033[45m"
|
|
#define BG_CYAN "\033[46m"
|
|
#define BG_WHITE "\033[47m"
|
|
|
|
/* declare global constants */
|
|
|
|
|
|
/* declare reusable functions */
|
|
|
|
/* read out shell command output */
|
|
char* readout(const char* command, char* buffer, size_t size) {
|
|
FILE *fp = popen(command, "r");
|
|
if (fp == NULL) {
|
|
perror("popen");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
if (fgets(buffer, size, fp) == NULL) {
|
|
perror("fgets");
|
|
pclose(fp);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
pclose(fp);
|
|
/* remove the newline character at the end of the buffer */
|
|
buffer[strcspn(buffer, "\n")] = 0;
|
|
return buffer;
|
|
}
|
|
|
|
void startup_screen() {
|
|
printf("\n\n");
|
|
printf(CYAN" █████ ███ ████ \n");
|
|
printf(" ░░███ ░░░ ░░███ \n");
|
|
printf(" █████ ██████ ████████ ███████ ████ ████████ ██████ ░███ \n");
|
|
printf(" ███░░ ███░░███░░███░░███ ░░░███░ ░░███ ░░███░░███ ███░░███ ░███ \n");
|
|
printf("░░█████ ░███████ ░███ ░███ ░███ ░███ ░███ ░███ ░███████ ░███ \n");
|
|
printf(" ░░░░███░███░░░ ░███ ░███ ░███ ███ ░███ ░███ ░███ ░███░░░ ░███ \n");
|
|
printf(" ██████ ░░██████ ████ █████ ░░█████ █████ ████ █████░░██████ █████\n");
|
|
printf("░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░ \n\n");
|
|
printf(" v0.0.1\n" RESET);
|
|
}
|
|
|
|
/* declare functions for startup checks */
|
|
void util_check() {
|
|
printf("curl: ");
|
|
if (system("curl --version > /dev/null 2>&1") == 0) {
|
|
printf(GREEN"OK\n"RESET);
|
|
} else {
|
|
printf(RED"FAIL\n"RESET);
|
|
}
|
|
printf("rtl-sdr: ");
|
|
if (system("ls /usr/bin/rtl_sdr > /dev/null 2>&1") == 0) {
|
|
printf(GREEN"OK\n"RESET);
|
|
} else {
|
|
printf(RED"FAIL\n"RESET);
|
|
}
|
|
}
|
|
|
|
|
|
/* making sure program has everything it needs to run, more checks will be introduced as capabilities are added */
|
|
void startup_checks() {
|
|
printf("######################################################################\n");
|
|
printf(MAGENTA"STARTUP CHECKS\n"RESET);
|
|
printf("----------------------------------------------------------------------\n");
|
|
printf(MAGENTA"SYSTEM STATUS\n\n"RESET);
|
|
printf("date: %s\n", readout("date \"+%D\"", (char[100]){0}, 100));
|
|
printf("time: %s\n", readout("date \"+%T\"", (char[100]){0}, 100));
|
|
/* internet connectivity check */
|
|
int status = system("ping -c 1 fsf.org > /dev/null 2>&1");
|
|
if (status == 0) {
|
|
printf("internet connectivity status: ");
|
|
printf(GREEN"online\n"RESET);
|
|
} else {
|
|
printf("internet connectivity status: ");
|
|
printf(RED"offline\n"RESET);
|
|
printf(RED"internet-dependent capabilities will be unavailable!"RESET);
|
|
}
|
|
printf("----------------------------------------------------------------------\n");
|
|
/* utilities presence check */
|
|
printf(MAGENTA"UTILITIES\n\n"RESET);
|
|
util_check();
|
|
printf("----------------------------------------------------------------------\n");
|
|
printf(MAGENTA"all checks finished!\n"RESET);
|
|
printf("######################################################################\n");
|
|
}
|
|
|
|
/* define functions for dashboard - WIP */
|
|
|
|
/*
|
|
void start_dashboard() {
|
|
initscr();
|
|
cbreak();
|
|
noecho();
|
|
}
|
|
*/
|
|
|
|
|
|
int main() {
|
|
startup_screen();
|
|
startup_checks();
|
|
return 0;
|
|
} |