feat: Update 2 files
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 25s
Build-Test-Publish / build (linux/arm64) (push) Failing after 53s

This commit is contained in:
j842
2025-08-17 21:35:00 +12:00
parent 84697c0723
commit d5bbd16b16
2 changed files with 107 additions and 25 deletions

View File

@@ -27,6 +27,12 @@ export INSTALL_LOCAL="false"
[ -f "${SCRIPT_DIR}/output/dropshell" ] || die "Build failed." [ -f "${SCRIPT_DIR}/output/dropshell" ] || die "Build failed."
# Get version from the built binary (format: YYYY.MMDD.HHMM)
VERSION=$("${SCRIPT_DIR}/output/dropshell" version | tr -d '[:space:]')
[ -z "$VERSION" ] && die "Failed to get version from dropshell"
echo "Publishing dropshell version ${VERSION} for ${ARCH}"
# download the sos binary # download the sos binary
mkdir -p "${TEMP_DIR}" mkdir -p "${TEMP_DIR}"
trap 'rm -rf "${TEMP_DIR}"' EXIT trap 'rm -rf "${TEMP_DIR}"' EXIT
@@ -34,8 +40,23 @@ trap 'rm -rf "${TEMP_DIR}"' EXIT
curl -L -o "${SOS}" "https://getbin.xyz/sos" curl -L -o "${SOS}" "https://getbin.xyz/sos"
chmod +x "${SOS}" chmod +x "${SOS}"
# upload arch-specific binary # Create metadata file with version information
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}" METADATA_FILE="${TEMP_DIR}/metadata.json"
cat > "${METADATA_FILE}" <<EOF
{
"version": "${VERSION}",
"architecture": "${ARCH}",
"project": "${PROJECT}"
}
EOF
# upload arch-specific binary with metadata
# The sos tool should support --metadata flag or similar for version info
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}" \
--metadata "version=${VERSION}"
# Also upload with version-specific tag for direct version access
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:${VERSION}-${ARCH}"
# upload generic install script # upload generic install script
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/dropshell-install.sh" "dropshell-install:latest" "${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/dropshell-install.sh" "dropshell-install:latest"
@@ -43,4 +64,4 @@ chmod +x "${SOS}"
# upload server auto-setup script # upload server auto-setup script
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/dropshell-server-autosetup.sh" "dropshell-server-autosetup:latest" "${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/dropshell-server-autosetup.sh" "dropshell-server-autosetup:latest"
echo "Successfully published dropshell:latest-${ARCH} to getbin.xyz" echo "Successfully published dropshell:latest-${ARCH} (version ${VERSION}) to getbin.xyz"

View File

@@ -254,8 +254,6 @@ complete -F _dropshell_completions ds
// determine the architecture of the system // determine the architecture of the system
std::string arch = shared_commands::get_arch(); std::string arch = shared_commands::get_arch();
std::string url = "https://gitea.jde.nz/public/dropshell/releases/download/latest/dropshell." + arch;
// check that the user that owns the exe is the current user this process is running as. // check that the user that owns the exe is the current user this process is running as.
struct stat st; struct stat st;
if (stat(exe_path.c_str(), &st) != 0) { if (stat(exe_path.c_str(), &st) != 0) {
@@ -269,48 +267,111 @@ complete -F _dropshell_completions ds
return -1; return -1;
} }
// Get current version (format: YYYY.MMDD.HHMM)
std::string runvercmd = exe_path.string() + " version";
std::string currentver = _exec(runvercmd.c_str());
currentver = trim(currentver);
info << "Current version: " << currentver << std::endl;
info << "Checking for updates..." << std::endl;
shared_commands::cLocalTempFolder local_temp_folder; shared_commands::cLocalTempFolder local_temp_folder;
std::filesystem::path sos_path = local_temp_folder.path() / "sos";
// Download sos to check metadata
bool should_download = true;
if (!download_file("https://getbin.xyz/sos", sos_path))
{
warning << "Failed to download sos utility, proceeding with direct download." << std::endl;
}
else
{
chmod(sos_path.c_str(), 0755);
// Use sos to get metadata about the remote dropshell binary
std::string info_cmd = sos_path.string() + " info getbin.xyz dropshell:latest-" + arch;
std::string info_output = _exec(info_cmd.c_str());
// Parse the version from the info output
// The metadata should contain version in format: "version: YYYY.MMDD.HHMM"
std::size_t version_pos = info_output.find("version: ");
if (version_pos != std::string::npos)
{
std::string remote_version = info_output.substr(version_pos + 9);
remote_version = remote_version.substr(0, remote_version.find('\n'));
remote_version = trim(remote_version);
info << "Latest available version: " << remote_version << std::endl;
// Compare versions (both in YYYY.MMDD.HHMM format)
if (!remote_version.empty() && currentver >= remote_version)
{
info << "Dropshell is already up to date." << std::endl;
return 0;
}
if (!remote_version.empty() && currentver < remote_version)
{
info << "New version available, downloading..." << std::endl;
}
}
else
{
debug << "Version information not found in metadata, proceeding with download." << std::endl;
}
}
if (!should_download)
{
return 0;
}
// Download new version from getbin.xyz
std::string url = "https://getbin.xyz/dropshell:latest-" + arch;
std::filesystem::path temp_file = local_temp_folder.path() / "dropshell"; std::filesystem::path temp_file = local_temp_folder.path() / "dropshell";
bool download_okay = download_file(url, temp_file); bool download_okay = download_file(url, temp_file);
if (!download_okay) if (!download_okay)
{ {
error << "Failed to download new version of dropshell." << std::endl; error << "Failed to download new version of dropshell from " << url << std::endl;
return -1; return -1;
} }
// make executable // make executable
chmod(temp_file.c_str(), 0755); chmod(temp_file.c_str(), 0755);
// check if the new version is the same as the old version // Get version of downloaded binary to double-check
uint64_t new_hash = hash_file(temp_file);
uint64_t old_hash = hash_file(exe_path);
if (new_hash == old_hash)
{
info << "Confirmed dropshell is the latest version." << std::endl;
return 0;
}
std::string runvercmd = exe_path.string() + " version";
std::string currentver = _exec(runvercmd.c_str());
runvercmd = temp_file.string() + " version"; runvercmd = temp_file.string() + " version";
std::string newver = _exec(runvercmd.c_str()); std::string newver = _exec(runvercmd.c_str());
newver = trim(newver);
// Final version check
if (currentver >= newver) if (currentver >= newver)
{ {
info << "Current dropshell version: " << currentver << ", published version: " << newver << std::endl; info << "Downloaded version (" << newver << ") is not newer than current (" << currentver << ")" << std::endl;
info << "Release version is not newer, no update needed." << std::endl; info << "No update needed." << std::endl;
return 0; return 0;
} }
// move the new version to the old version. info << "Updating from version " << currentver << " to " << newver << std::endl;
std::filesystem::rename(exe_path, exe_path.parent_path() / "dropshell.old");
// Backup old version and replace with new
std::filesystem::path backup_path = exe_path.parent_path() / "dropshell.old";
if (std::filesystem::exists(backup_path))
{
std::filesystem::remove(backup_path);
}
std::filesystem::rename(exe_path, backup_path);
std::filesystem::rename(temp_file, exe_path); std::filesystem::rename(temp_file, exe_path);
// remove the old version. // Remove the backup after successful replacement
std::filesystem::remove(exe_path.parent_path() / "dropshell.old"); std::filesystem::remove(backup_path);
// execute the new version info << "Update complete. Restarting dropshell..." << std::endl;
execlp("bash", "bash", "-c", (exe_path.parent_path() / "dropshell").string() + "install", (char *)nullptr);
// Execute the new version
execlp("bash", "bash", "-c", (exe_path.string() + " install").c_str(), (char *)nullptr);
error << "Failed to execute new version of dropshell." << std::endl; error << "Failed to execute new version of dropshell." << std::endl;
return -1; return -1;
} }