23 #ifndef JAIABOT_SRC_LIB_METADATA_H
24 #define JAIABOT_SRC_LIB_METADATA_H
30 #include <boost/algorithm/string.hpp>
32 #include <goby/version.h>
43 auto jaia_name_c = getenv(
"JAIA_DEVICE_NAME");
44 std::string jaia_device_name;
47 jaia_device_name = std::string(jaia_name_c);
52 if (gethostname(buffer, 256) == 0)
54 jaia_device_name = std::string(buffer);
58 jaia_device_name =
"<No Name>";
68 #ifdef JAIABOT_VERSION_GITHASH
69 jaiabot_version.set_git_hash(JAIABOT_VERSION_GITHASH);
70 jaiabot_version.set_git_branch(JAIABOT_VERSION_GITBRANCH);
73 auto execute_command = [](
const char* cmd) -> std::string {
74 std::array<char, 128> buffer;
76 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd,
"r"), pclose);
79 throw std::runtime_error(
"popen() failed!");
81 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
82 { result += buffer.data(); }
88 std::string cmd =
"apt-cache policy jaiabot-embedded";
89 std::string output = execute_command(cmd.c_str());
91 std::regex installed_pattern(R
"(Installed: (\S+))");
92 std::smatch installed_match;
93 if (std::regex_search(output, installed_match, installed_pattern))
95 std::string installed_version = installed_match[1];
97 if (installed_version !=
"(none)")
100 std::regex repo_pattern(R
"(packages\.jaia\.tech/ubuntu/([a-z]*)/([X0-9]+\.y*))");
101 std::smatch repo_match;
102 if (std::regex_search(output, repo_match, repo_pattern))
104 std::string repo = repo_match[1];
105 std::string release_branch = repo_match[2];
107 jaiabot_version.set_deb_repository(repo);
108 jaiabot_version.set_deb_release_branch(release_branch);
116 std::string cmd =
"apt-cache policy moos-ivp-apps";
117 std::string output = execute_command(cmd.c_str());
119 std::regex installed_pattern(R
"(Installed: (\S+))");
120 std::smatch installed_match;
121 if (std::regex_search(output, installed_match, installed_pattern))
123 std::string installed_version = installed_match[1];
125 if (installed_version !=
"(none)")
133 std::ifstream image_version_file(
"/etc/jaiabot/version");
134 if (image_version_file.is_open())
137 std::map<std::string, std::string> version_info;
139 while (std::getline(image_version_file, line))
141 auto equal_pos = line.find(
'=');
142 if (equal_pos == std::string::npos)
145 std::string value = line.substr(equal_pos + 1);
146 boost::trim_if(value, boost::is_any_of(
"\""));
147 version_info[line.substr(0, equal_pos)] = value;
149 if (version_info.count(
"JAIABOT_IMAGE_VERSION"))
151 if (version_info.count(
"RASPI_FIRMWARE_VERSION"))
153 if (version_info.count(
"JAIABOT_IMAGE_BUILD_DATE"))
155 if (version_info.count(
"JAIABOT_FIRST_BOOT_DATE"))