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>";
63 auto& jaiabot_version = *
metadata.mutable_jaiabot_version();
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
75 std::array<char, 128> buffer;
77 std::unique_ptr<FILE,
decltype(&pclose)> pipe(popen(cmd,
"r"), pclose);
80 throw std::runtime_error(
"popen() failed!");
82 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
84 result += buffer.data();
91 std::string cmd =
"apt-cache policy jaiabot-embedded";
92 std::string output = execute_command(cmd.c_str());
94 std::regex installed_pattern(R
"(Installed: (\S+))");
95 std::smatch installed_match;
96 if (std::regex_search(output, installed_match, installed_pattern))
98 std::string installed_version = installed_match[1];
100 if (installed_version !=
"(none)")
103 std::regex repo_pattern(R
"(packages\.jaia\.tech/ubuntu/([a-z]*)/([X0-9]+\.y*))");
104 std::smatch repo_match;
105 if (std::regex_search(output, repo_match, repo_pattern))
107 std::string repo = repo_match[1];
108 std::string release_branch = repo_match[2];
110 jaiabot_version.set_deb_repository(repo);
111 jaiabot_version.set_deb_release_branch(release_branch);
119 std::string cmd =
"apt-cache policy moos-ivp-apps";
120 std::string output = execute_command(cmd.c_str());
122 std::regex installed_pattern(R
"(Installed: (\S+))");
123 std::smatch installed_match;
124 if (std::regex_search(output, installed_match, installed_pattern))
126 std::string installed_version = installed_match[1];
128 if (installed_version !=
"(none)")
129 metadata.set_ivp_version(installed_version);
133 metadata.set_goby_version(goby::VERSION_STRING);
136 std::ifstream image_version_file(
"/etc/jaiabot/version");
137 if (image_version_file.is_open())
140 std::map<std::string, std::string> version_info;
142 while (std::getline(image_version_file, line))
144 auto equal_pos = line.find(
'=');
145 if (equal_pos == std::string::npos)
148 std::string value = line.substr(equal_pos + 1);
149 boost::trim_if(value, boost::is_any_of(
"\""));
150 version_info[line.substr(0, equal_pos)] = value;
152 if (version_info.count(
"JAIABOT_IMAGE_VERSION"))
153 metadata.set_jaiabot_image_version(version_info[
"JAIABOT_IMAGE_VERSION"]);
154 if (version_info.count(
"RASPI_FIRMWARE_VERSION"))
155 metadata.set_raspi_firmware_version(version_info[
"RASPI_FIRMWARE_VERSION"]);
156 if (version_info.count(
"JAIABOT_IMAGE_BUILD_DATE"))
157 metadata.set_jaiabot_image_build_date(version_info[
"JAIABOT_IMAGE_BUILD_DATE"]);
158 if (version_info.count(
"JAIABOT_FIRST_BOOT_DATE"))
159 metadata.set_jaiabot_image_first_boot_date(version_info[
"JAIABOT_FIRST_BOOT_DATE"]);