45 auto jaia_name_c = getenv(
"JAIA_DEVICE_NAME");
46 std::string jaia_device_name;
49 jaia_device_name = std::string(jaia_name_c);
54 if (gethostname(buffer, 256) == 0)
56 jaia_device_name = std::string(buffer);
60 jaia_device_name =
"<No Name>";
65 auto& jaiabot_version = *
metadata.mutable_jaiabot_version();
70#ifdef JAIABOT_VERSION_GITHASH
71 jaiabot_version.set_git_hash(JAIABOT_VERSION_GITHASH);
72 jaiabot_version.set_git_branch(JAIABOT_VERSION_GITBRANCH);
75 auto execute_command = [](
const char* cmd) -> std::string {
76 std::array<char, 128> buffer;
78 auto close_pipe = [](FILE* f) { pclose(f); };
79 std::unique_ptr<FILE,
decltype(close_pipe)> pipe(popen(cmd,
"r"), close_pipe);
82 throw std::runtime_error(
"popen() failed!");
84 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
85 { 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"]);
160 std::string eeprom_json =
161 execute_command(
"rpi-eeprom-update -j -m /dev/stderr 2>&1 1>/dev/null");
162 std::regex bootloader_pattern(R
"(\"BOOTLOADER_CURRENT\"\s*:\s*([0-9]+))");
163 std::smatch bootloader_match;
164 if (std::regex_search(eeprom_json, bootloader_match, bootloader_pattern))
166 metadata.set_raspi_eeprom_version(std::stoll(bootloader_match[1]));
172 if (version_info.count(
"JAIABOT_IMAGE_BUILD_DATE"))
173 metadata.set_jaiabot_image_build_date(version_info[
"JAIABOT_IMAGE_BUILD_DATE"]);
174 if (version_info.count(
"JAIABOT_FIRST_BOOT_DATE"))
175 metadata.set_jaiabot_image_first_boot_date(version_info[
"JAIABOT_FIRST_BOOT_DATE"]);