-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssh_stuff.cpp
More file actions
42 lines (34 loc) · 1.12 KB
/
Copy pathssh_stuff.cpp
File metadata and controls
42 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "ssh_stuff.h"
bool check_ssh_connection() {
int returnCode = system("ssh -q -o ConnectTimeout=1 root@10.11.99.1 'exit'");
if (returnCode == 0) {
return true;
}
return false;
}
json parseMetadata() {
// Get all contents of metadata-files and insert the file-name inside each content
const char command[] = R"(ssh root@10.11.99.1 'tail -vn +1 /home/root/.local/share/remarkable/xochitl/*.metadata \
| sed "s/==> \/home.*xochitl\/\(.*\)\.metadata <==.*/{\n\"UUID\": \"\1\",/" \
| tr -d "\n" \
| tr -s " " \
| sed "s/,{/,/g" \
| sed "s/}{/}, {/g" \
| sed "s/^.*$/[&]/"')";
FILE *stream = popen(command, "r");
if (stream == nullptr) {
throw std::runtime_error("Couldn't read files from the tablet");
}
char buffer[128];
std::string result;
while(fgets(buffer, sizeof(buffer), stream) != nullptr) {
result += buffer;
}
unsigned long i = result.length() - 1;
while (isspace(result[i]) != 0) {
i--;
}
result = result.substr(0, i + 1);
pclose(stream);
return json::parse(result);
}