stable startingpoint
This commit is contained in:
parent
18b32f088e
commit
f42c0eaf28
|
@ -63,24 +63,14 @@ alias ls='ls -ha -w100'
|
||||||
# interactive login
|
# interactive login
|
||||||
which screen &> /dev/null && {
|
which screen &> /dev/null && {
|
||||||
[[ -t 0 ]] && {
|
[[ -t 0 ]] && {
|
||||||
|
eval $(resize) # important
|
||||||
|
printf "\r" # weird but needed
|
||||||
test -n "$STY" || {
|
test -n "$STY" || {
|
||||||
resize # call twice
|
|
||||||
resize # otherwise COLUMNS/ROWS is 0
|
|
||||||
# resize # call twice
|
|
||||||
# resize # otherwise COLUMNS/ROWS is 0
|
|
||||||
# # add URL-hash as extra screen session
|
|
||||||
# test -z "$HASH" || {
|
|
||||||
# grep 'screen -t #' /root/.screenrc || {
|
|
||||||
# echo "screen -t xrsh+URL 3 /bin/sh -c 'source /etc/profile.sh; ${HASH}; sh'" | sed "s/'#/'/g" >> /root/.screenrc
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# execute URL hash or GNU screen
|
# execute URL hash or GNU screen
|
||||||
test -n "$HASH" && hook URI/fragment "${HASH:1}"
|
test -n "$HASH" && hook URI/fragment "${HASH:1}"
|
||||||
test -z "$HASH" && screen -Aa -R -T screen-256color -c /root/.screenrc
|
test -z "$HASH" && screen -Aa -R -T screen-256color -c /root/.screenrc
|
||||||
}
|
}
|
||||||
test -n "$STY" && {
|
test -n "$STY" && {
|
||||||
resize # call twice
|
|
||||||
resize # otherwise COLUMNS/ROWS is 0
|
|
||||||
test -f /root/motd && cat /root/motd || cat /etc/motd;
|
test -f /root/motd && cat /root/motd || cat /etc/motd;
|
||||||
say "welcome to eex r, shell. For an optimal user experience, connect a Bluetooth keyboard." &
|
say "welcome to eex r, shell. For an optimal user experience, connect a Bluetooth keyboard." &
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# JOA
|
#
|
||||||
# Automatically generated make config: don't edit
|
# Automatically generated make config: don't edit
|
||||||
# Busybox version: 1.36.1
|
# Busybox version: 1.36.1
|
||||||
# Mon Dec 30 10:23:26 2024
|
# Thu Jan 9 11:13:11 2025
|
||||||
#
|
#
|
||||||
CONFIG_HAVE_DOT_CONFIG=y
|
CONFIG_HAVE_DOT_CONFIG=y
|
||||||
|
|
||||||
|
@ -1210,14 +1210,14 @@ CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS=y
|
||||||
#
|
#
|
||||||
# System Logging Utilities
|
# System Logging Utilities
|
||||||
#
|
#
|
||||||
CONFIG_KLOGD=y
|
# CONFIG_KLOGD is not set
|
||||||
CONFIG_FEATURE_KLOGD_KLOGCTL=y
|
# CONFIG_FEATURE_KLOGD_KLOGCTL is not set
|
||||||
CONFIG_LOGGER=y
|
CONFIG_LOGGER=y
|
||||||
# CONFIG_LOGREAD is not set
|
# CONFIG_LOGREAD is not set
|
||||||
# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
|
# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
|
||||||
CONFIG_SYSLOGD=y
|
CONFIG_SYSLOGD=y
|
||||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||||
CONFIG_FEATURE_REMOTE_LOG=y
|
# CONFIG_FEATURE_REMOTE_LOG is not set
|
||||||
# CONFIG_FEATURE_SYSLOGD_DUP is not set
|
# CONFIG_FEATURE_SYSLOGD_DUP is not set
|
||||||
# CONFIG_FEATURE_SYSLOGD_CFG is not set
|
# CONFIG_FEATURE_SYSLOGD_CFG is not set
|
||||||
# CONFIG_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS is not set
|
# CONFIG_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS is not set
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// SPDX: GPL-3.0-or-later
|
||||||
#define FUSE_USE_VERSION 35
|
#define FUSE_USE_VERSION 35
|
||||||
|
|
||||||
#include <fuse3/fuse.h>
|
#include <fuse3/fuse.h>
|
||||||
|
@ -8,32 +9,86 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static const char *script_path;
|
static const char *script_path;
|
||||||
|
static int use_serial = 0;
|
||||||
|
static char serial_device[256];
|
||||||
|
static const char *END_TOKEN = "\0\0\0";
|
||||||
|
|
||||||
static int call_script(const char *action, const char *path, char **output) {
|
static int call_script_serial(const char *command, char **output) {
|
||||||
char command[4096];
|
int fd = open(serial_device, O_RDWR | O_NOCTTY);
|
||||||
FILE *fp;
|
if (fd < 0) {
|
||||||
|
perror("open serial device");
|
||||||
snprintf(command, sizeof(command), "%s %s '%s'", script_path, action, path);
|
|
||||||
fp = popen(command, "r");
|
|
||||||
if (!fp) {
|
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the command to the serial device
|
||||||
|
size_t command_len = strlen(command);
|
||||||
|
if (write(fd, command, command_len) != command_len) {
|
||||||
|
perror("write to serial");
|
||||||
|
close(fd);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the response
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
*output = NULL;
|
*output = NULL;
|
||||||
char line[1024];
|
char buffer[1024];
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
ssize_t bytes_read;
|
||||||
size_t len = strlen(line);
|
|
||||||
*output = realloc(*output, size + len + 1);
|
while ((bytes_read = read(fd, buffer, sizeof(buffer))) > 0) {
|
||||||
memcpy(*output + size, line, len);
|
*output = realloc(*output, size + bytes_read + 1);
|
||||||
size += len;
|
memcpy(*output + size, buffer, bytes_read);
|
||||||
|
size += bytes_read;
|
||||||
|
|
||||||
|
if (size >= 3 && memcmp(*output + size - 3, END_TOKEN, 3) == 0) {
|
||||||
|
size -= 3; // Remove the END_TOKEN
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_read < 0) {
|
||||||
|
perror("read from serial");
|
||||||
|
free(*output);
|
||||||
|
close(fd);
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*output) {
|
if (*output) {
|
||||||
(*output)[size] = '\0';
|
(*output)[size] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return pclose(fp);
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int call_script(const char *action, const char *path, char **output) {
|
||||||
|
char command[4096];
|
||||||
|
|
||||||
|
snprintf(command, sizeof(command), "%s %s '%s'", script_path, action, path);
|
||||||
|
|
||||||
|
if (use_serial) {
|
||||||
|
return call_script_serial(command, output);
|
||||||
|
} else {
|
||||||
|
FILE *fp = popen(command, "r");
|
||||||
|
if (!fp) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = 0;
|
||||||
|
*output = NULL;
|
||||||
|
char line[1024];
|
||||||
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
|
size_t len = strlen(line);
|
||||||
|
*output = realloc(*output, size + len + 1);
|
||||||
|
memcpy(*output + size, line, len);
|
||||||
|
size += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*output) {
|
||||||
|
(*output)[size] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return pclose(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fusescript_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
|
static int fusescript_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
|
||||||
|
@ -103,11 +158,6 @@ static int fusescript_readdir(const char *path, void *buf, fuse_fill_dir_t fille
|
||||||
(void) fi;
|
(void) fi;
|
||||||
(void) flags;
|
(void) flags;
|
||||||
|
|
||||||
if (strcmp(path, "/") != 0) {
|
|
||||||
// If the path is not the root, return an error
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add default entries for directories
|
// Add default entries for directories
|
||||||
filler(buf, ".", NULL, 0, 0); // Current directory
|
filler(buf, ".", NULL, 0, 0); // Current directory
|
||||||
filler(buf, "..", NULL, 0, 0); // Parent directory
|
filler(buf, "..", NULL, 0, 0); // Parent directory
|
||||||
|
@ -188,6 +238,112 @@ static int fusescript_rmdir(const char *path) {
|
||||||
return ret == 0 ? 0 : -EIO;
|
return ret == 0 ? 0 : -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add getxattr function
|
||||||
|
static int fusescript_getxattr(const char *path, const char *name, char *value, size_t size) {
|
||||||
|
char command[4096];
|
||||||
|
snprintf(command, sizeof(command), "%s getxattr '%s' '%s'", script_path, path, name);
|
||||||
|
|
||||||
|
FILE *fp = popen(command, "r");
|
||||||
|
if (!fp) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *output = NULL;
|
||||||
|
size_t output_len = 0;
|
||||||
|
char line[1024];
|
||||||
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
|
size_t len = strlen(line);
|
||||||
|
output = realloc(output, output_len + len + 1);
|
||||||
|
memcpy(output + output_len, line, len);
|
||||||
|
output_len += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (output) {
|
||||||
|
output[output_len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = pclose(fp);
|
||||||
|
if (ret != 0 || !output) {
|
||||||
|
free(output);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
// Return the size of the required buffer
|
||||||
|
free(output);
|
||||||
|
return output_len;
|
||||||
|
} else if (size < output_len) {
|
||||||
|
// Buffer too small
|
||||||
|
free(output);
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the attribute value
|
||||||
|
memcpy(value, output, output_len);
|
||||||
|
free(output);
|
||||||
|
return output_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add setxattr function
|
||||||
|
static int fusescript_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) {
|
||||||
|
char value_str[4096];
|
||||||
|
snprintf(value_str, sizeof(value_str), "%.*s", (int)size, value);
|
||||||
|
|
||||||
|
char command[4096];
|
||||||
|
snprintf(command, sizeof(command), "%s setxattr '%s' '%s' '%s'", script_path, path, name, value_str);
|
||||||
|
|
||||||
|
int ret = system(command);
|
||||||
|
return ret == 0 ? 0 : -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add listxattr function
|
||||||
|
static int fusescript_listxattr(const char *path, char *list, size_t size) {
|
||||||
|
char command[4096];
|
||||||
|
snprintf(command, sizeof(command), "%s listxattr '%s'", script_path, path);
|
||||||
|
|
||||||
|
FILE *fp = popen(command, "r");
|
||||||
|
if (!fp) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *output = NULL;
|
||||||
|
size_t output_len = 0;
|
||||||
|
char line[1024];
|
||||||
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
|
size_t len = strlen(line);
|
||||||
|
output = realloc(output, output_len + len + 1);
|
||||||
|
memcpy(output + output_len, line, len);
|
||||||
|
output_len += len;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "listxattr script output: %s\n", output);
|
||||||
|
fprintf(stderr, "listxattr output length: %zu\n", output_len);
|
||||||
|
|
||||||
|
if (output) {
|
||||||
|
output[output_len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = pclose(fp);
|
||||||
|
if (ret != 0 || !output) {
|
||||||
|
free(output);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
// Return the size of the required buffer
|
||||||
|
free(output);
|
||||||
|
return output_len;
|
||||||
|
} else if (size < output_len) {
|
||||||
|
// Buffer too small
|
||||||
|
free(output);
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the attribute list
|
||||||
|
memcpy(list, output, output_len);
|
||||||
|
free(output);
|
||||||
|
return output_len;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct fuse_operations fusescript_ops = {
|
static const struct fuse_operations fusescript_ops = {
|
||||||
.getattr = fusescript_getattr,
|
.getattr = fusescript_getattr,
|
||||||
.readdir = fusescript_readdir,
|
.readdir = fusescript_readdir,
|
||||||
|
@ -198,21 +354,43 @@ static const struct fuse_operations fusescript_ops = {
|
||||||
.mkdir = fusescript_mkdir,
|
.mkdir = fusescript_mkdir,
|
||||||
.unlink = fusescript_unlink,
|
.unlink = fusescript_unlink,
|
||||||
.rmdir = fusescript_rmdir,
|
.rmdir = fusescript_rmdir,
|
||||||
|
.getxattr = fusescript_getxattr,
|
||||||
|
.setxattr = fusescript_setxattr,
|
||||||
|
.listxattr = fusescript_listxattr,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr, "Usage: %s <script> <mountpoint>\n", argv[0]);
|
fprintf(stderr, "Usage: %s <script_or_serialdevice> <mountpoint>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
script_path = realpath(argv[1], NULL);
|
if (strncmp(argv[2], "/dev/", 5) == 0) {
|
||||||
if (!script_path) {
|
use_serial = 1;
|
||||||
perror("realpath");
|
strncpy(serial_device, argv[2], sizeof(serial_device) - 1);
|
||||||
return 1;
|
serial_device[sizeof(serial_device) - 1] = '\0';
|
||||||
}
|
|
||||||
|
|
||||||
argv[1] = argv[2];
|
if (argc < 4) {
|
||||||
return fuse_main(argc - 1, argv + 1, &fusescript_ops, NULL);
|
fprintf(stderr, "Missing mountpoint for serial device\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
script_path = realpath(argv[1], NULL);
|
||||||
|
if (!script_path) {
|
||||||
|
perror("realpath");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
argv[1] = argv[3];
|
||||||
|
return fuse_main(argc - 2, argv + 1, &fusescript_ops, NULL);
|
||||||
|
} else {
|
||||||
|
script_path = realpath(argv[1], NULL);
|
||||||
|
if (!script_path) {
|
||||||
|
perror("realpath");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
argv[1] = argv[2];
|
||||||
|
return fuse_main(argc - 1, argv + 1, &fusescript_ops, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue