Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
name: Publish GitHub release
if: startsWith(github.ref, 'refs/tags/v')
needs: [build, flatpak]
environment: release
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
Expand All @@ -54,6 +55,7 @@ jobs:
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_SIGNING_KEY: ${{ secrets.NIGHTCAP_RELEASE_SIGNING_KEY }}
run: |
set -Eeuo pipefail
tag="${GITHUB_REF_NAME}"
Expand All @@ -80,17 +82,41 @@ jobs:
for asset in "${assets[@]}"; do
sha256sum "$asset" > "$asset.sha256"
done
for asset in "${assets[@]}"; do cat "$asset.sha256"; done > SHA256SUMS
)
uploads+=(release/SHA256SUMS)
# Nightcap installs a release only when this signature checks out
# against the key built into it. The tag is signed with the sums so
# an old release's files cannot be republished under a newer tag.
public_key=packaging/release/nightcap-release.pub
if [[ -n "${RELEASE_SIGNING_KEY}" ]]; then
key_file="$(mktemp -p "${RUNNER_TEMP}")"
signed="$(mktemp -p "${RUNNER_TEMP}")"
trap 'rm -f -- "${key_file}" "${signed}"' EXIT
printf '%s\n' "${RELEASE_SIGNING_KEY}" > "${key_file}"
{ printf 'nightcap %s\n' "$tag"; cat release/SHA256SUMS; } > "${signed}"
openssl pkeyutl -sign -inkey "${key_file}" -rawin \
-in "${signed}" -out release/SHA256SUMS.sig
openssl pkeyutl -verify -pubin -inkey "${public_key}" -rawin \
-in "${signed}" -sigfile release/SHA256SUMS.sig
uploads+=(release/SHA256SUMS.sig)
elif [[ -f "${public_key}" ]]; then
echo "::error::NIGHTCAP_RELEASE_SIGNING_KEY is not set; Nightcap only installs signed releases"
exit 1
fi
./scripts/release_notes.sh "$tag" > release/notes.md
# A new release stays a draft until every file is up: Nightcap caches
# the latest release's file list for 6 hours.
if ! gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release create "$tag" --repo "$GITHUB_REPOSITORY" \
gh release create "$tag" --repo "$GITHUB_REPOSITORY" --draft \
--title "Nightcap $tag" --notes-file release/notes.md ||
gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null
fi
gh release edit "$tag" --repo "$GITHUB_REPOSITORY" \
--title "Nightcap $tag" --notes-file release/notes.md
gh release upload "$tag" --repo "$GITHUB_REPOSITORY" --clobber \
"${uploads[@]}"
gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --draft=false

# nightcap-bin downloads the pacman package from the release page, so this
# waits for the upload.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ desktop.ini
.env.*
!.env.example
*.pem
/.release-keys/
cookies*.txt
*credentials*
*secret*
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ Release notes on GitHub are taken from the matching section here.

## [Unreleased]

### Added

- Nightcap updates itself. It checks GitHub at most every 6 hours, and the AppImage installs a new
release in the background; the deb and Fedora rpm install it through pkexec. Settings has a new About
page with the version, Roblox build, Check/Update and links, and a version pill beside the name that
turns into Update when a release is out. `updates.nightcap` (`auto`, `notify` or `off`) picks how much
it does. Flatpak, Arch and Nix installs show their own update command to copy instead; on Arch it
names the AUR helper you have, or the `makepkg` steps without one.
- Settings is always dark, in neutral greys with one muted violet accent.
- When Roblox stops letting the installed version join and the newest one fails its test launch with
this Nightcap, Nightcap asks to update itself before starting. The AppImage then restarts on the new
release; a deb or rpm asks to be started again. Releases are checked against a signed `SHA256SUMS`
before anything is installed.

### Fixed

- With Vulkan on NVIDIA under Wayland, joining a game no longer crashes when the window changes size
Expand Down
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ add_library(mocktail_update STATIC
src/update/file_lock.cc
src/update/http_download.cc
src/update/host_abi_deriver.cc
src/update/nightcap_install_method.cc
src/update/nightcap_release.cc
src/update/nightcap_self_update.cc
src/update/payload_integrity.cc
src/update/payload_store.cc
src/update/pinned_apk_provider.cc
Expand All @@ -236,9 +239,27 @@ target_link_libraries(mocktail_update PUBLIC
)
mocktail_apply_compile_options(mocktail_update)

set(MOCKTAIL_RELEASE_KEY
"${PROJECT_SOURCE_DIR}/packaging/release/nightcap-release.pub" CACHE FILEPATH
"Ed25519 public key (PEM) that signs each release's SHA256SUMS; without it Nightcap cannot update itself")
set(_nightcap_release_key "")
if(EXISTS "${MOCKTAIL_RELEASE_KEY}")
file(READ "${MOCKTAIL_RELEASE_KEY}" _nightcap_release_key)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${MOCKTAIL_RELEASE_KEY}")
else()
message(STATUS "Nightcap: no release key at ${MOCKTAIL_RELEASE_KEY}; Nightcap updates are off in this build")
endif()
file(CONFIGURE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/generated/nightcap_release_key.h"
CONTENT "#pragma once\ninline constexpr char kNightcapReleasePublicKey[] = R\"key(@_nightcap_release_key@)key\";\n"
@ONLY)

add_executable(mocktail_updater src/update/main.cc)
target_link_libraries(mocktail_updater PRIVATE Mocktail::Update)
target_include_directories(mocktail_updater PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/generated")
target_compile_definitions(mocktail_updater PRIVATE
"MOCKTAIL_PROJECT_VERSION=\"${PROJECT_VERSION}\""
"MOCKTAIL_DEFAULT_COMPATIBILITY_MANIFEST=\"${MOCKTAIL_DEFAULT_COMPATIBILITY_MANIFEST}\""
"MOCKTAIL_DEFAULT_SIGNING_TRUST_MANIFEST=\"${MOCKTAIL_DEFAULT_SIGNING_TRUST_MANIFEST}\""
"MOCKTAIL_DEFAULT_DOWNLOAD_SOURCES_MANIFEST=\"${MOCKTAIL_DEFAULT_DOWNLOAD_SOURCES_MANIFEST}\""
Expand Down
5 changes: 5 additions & 0 deletions config/mocktail.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,8 @@ updates:
# Reserved for desktop update integrations. `mocktail_updater` itself never
# launches another process after changing the active payload.
launch_after_update: false
# String (default: auto): Nightcap's own updates. auto checks GitHub at
# most every 6 hours and an AppImage installs a new release by itself;
# notify only checks; off never asks GitHub. A Roblox build that needs
# a newer Nightcap still shows the update dialog.
nightcap: auto
7 changes: 5 additions & 2 deletions include/runtime/failure_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ bool FailureDialogsEnabled(const Environment& environment);

bool ShowFailureDialog(const Environment& environment,
std::string_view message);
// The heading defaults to "Signed out".
// The heading defaults to "Signed out". A `command` is shown under the
// message with a button that copies it. The button says Close instead of
// Continue when there is a command or Nightcap `quits` after the dialog.
bool ShowWarningDialog(const Environment& environment,
std::string_view message,
std::string_view heading = {});
std::string_view heading = {},
std::string_view command = {}, bool quits = false);
std::optional<bool> AskYesNo(const Environment& environment,
std::string_view heading, std::string_view body,
std::string_view decline,
Expand Down
39 changes: 39 additions & 0 deletions include/runtime/payload_update_preflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,45 @@ std::string QueryRobloxUpgradeAction(const std::string& version_name,
using UpgradeActionQuery = std::function<std::string(
const std::string& version_name, const std::atomic<bool>* cancel)>;

// The installed Roblox version, e.g. "2.746.123"; empty when none is.
std::string ActiveVersionName(const RuntimePaths& paths);

struct NightcapUpdateNeed {
bool required = false;
std::string installed_roblox;
std::string newest_roblox;
};

// Required when this build rejected the newest Roblox and Roblox refuses the
// installed one. Roblox is asked only when such a rejection is on record.
NightcapUpdateNeed AssessNightcapUpdateNeed(const RuntimePaths& paths,
std::string_view runtime_build_id,
const UpgradeActionQuery& ask_roblox);

struct NightcapUpdaterStatus {
std::string error;
std::string installed;
std::string installed_pending;
bool newer = false;
bool can_install = false;
std::string kind;
std::string latest;
std::string command;
std::string note;
};

// kCached asks GitHub only when the last answer is 6 hours old; kOffline
// never asks; kForce always does.
enum class NightcapCheck { kCached, kOffline, kForce };

NightcapUpdaterStatus ReadNightcapUpdaterStatus(const Environment& environment,
const RuntimePaths& paths,
NightcapCheck check);

// `mocktail_updater nightcap install` behind the update progress window.
PayloadUpdatePreflightResult RunNightcapInstall(const Environment& environment,
const RuntimePaths& paths);

class BackgroundPayloadUpdate final {
public:
~BackgroundPayloadUpdate();
Expand Down
2 changes: 2 additions & 0 deletions include/ui/settings_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum class SettingKind {
// textures_folder.
kFolder,
kCache,
// This Nightcap's version and the newest release, with Check or Update.
kNightcapRelease,
// Installs a sky pack into the asset overlay, or removes it.
kSky,
// Picks the font that replaces Roblox's, or goes back to Roblox's.
Expand Down
1 change: 1 addition & 0 deletions include/update/http_download.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct HttpTransferRequest {
int maximum_attempts = 3;
long retry_delay_ms = 2000;
int maximum_redirects = 5;
std::string progress_label = "Roblox";
};

struct HttpBytesResult {
Expand Down
48 changes: 48 additions & 0 deletions include/update/nightcap_install_method.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef MOCKTAIL_UPDATE_NIGHTCAP_INSTALL_METHOD_H_
#define MOCKTAIL_UPDATE_NIGHTCAP_INSTALL_METHOD_H_

#include <filesystem>
#include <functional>
#include <optional>
#include <string>
#include <string_view>

namespace mocktail::update {

enum class InstallKind { kAppImage, kArch, kDeb, kRpm, kFlatpak, kNix, kSource };

std::string_view InstallKindName(InstallKind kind);

struct InstallMethod {
InstallKind kind = InstallKind::kSource;
std::filesystem::path appimage;
// The system package owning the executable; only "nightcap" is a release.
std::string package;
std::string distro_version;
bool self_update = false;
// What the user runs instead, when Nightcap cannot update itself.
std::string command;
std::string reason;
};

struct InstallProbe {
std::filesystem::path executable;
std::optional<std::string> appimage_variable;
bool flatpak = false;
std::string os_id;
std::string os_version_id;
// `manager` is pacman, dpkg or rpm; nullopt when it owns no package there.
std::function<std::optional<std::string>(std::string_view manager,
const std::filesystem::path& path)>
owner;
std::function<bool(std::string_view program)> has_program;
std::function<bool(const std::filesystem::path& file)> writable_regular_file;
};

InstallMethod DetectInstallMethod(const InstallProbe& probe);

InstallProbe SystemInstallProbe();

} // namespace mocktail::update

#endif // MOCKTAIL_UPDATE_NIGHTCAP_INSTALL_METHOD_H_
54 changes: 54 additions & 0 deletions include/update/nightcap_release.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef MOCKTAIL_UPDATE_NIGHTCAP_RELEASE_H_
#define MOCKTAIL_UPDATE_NIGHTCAP_RELEASE_H_

#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "update/nightcap_install_method.h"

namespace mocktail::update {

inline constexpr char kReleaseDownloadPrefix[] =
"https://github.com/CoderDayton/nightcap/releases/download/";
inline constexpr char kSumsAsset[] = "SHA256SUMS";
inline constexpr char kSumsSignatureAsset[] = "SHA256SUMS.sig";

struct ReleaseAsset {
std::string name;
std::string url;
std::uint64_t size = 0;
};

struct NightcapRelease {
std::string version;
std::string page;
std::vector<ReleaseAsset> assets;

const ReleaseAsset* Find(std::string_view name) const;
};

// Refuses drafts, prereleases, non-vX.Y.Z tags and assets off the tag's path.
std::optional<NightcapRelease> ParseLatestRelease(std::string_view body,
std::string* error = nullptr);

std::optional<int> CompareVersions(std::string_view a, std::string_view b);

std::optional<std::string> AssetNameFor(const InstallMethod& method,
std::string_view version);

// `sha256sum` output: "<64 hex> <name>" lines, hashes lowercased.
std::optional<std::map<std::string, std::string>> ParseSums(
std::string_view text, std::string* error = nullptr);

// `signature` is the raw 64 bytes `openssl pkeyutl -sign -rawin` writes.
bool VerifyEd25519(std::string_view message, std::string_view signature,
std::string_view public_key_pem,
std::string* error = nullptr);

} // namespace mocktail::update

#endif // MOCKTAIL_UPDATE_NIGHTCAP_RELEASE_H_
73 changes: 73 additions & 0 deletions include/update/nightcap_self_update.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef MOCKTAIL_UPDATE_NIGHTCAP_SELF_UPDATE_H_
#define MOCKTAIL_UPDATE_NIGHTCAP_SELF_UPDATE_H_

#include <chrono>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <optional>
#include <string>
#include <vector>

#include "update/http_download.h"
#include "update/nightcap_install_method.h"

namespace mocktail::update {

inline constexpr char kNightcapLatestReleaseUrl[] =
"https://api.github.com/repos/CoderDayton/nightcap/releases/latest";
// GitHub allows 60 unauthenticated API requests an hour per address.
inline constexpr std::chrono::hours kNightcapCheckInterval{6};

struct NightcapUpdaterEnvironment {
std::filesystem::path data_root;
std::filesystem::path cache_root;
std::string running_version;
std::string public_key_pem;
InstallMethod method;
std::function<HttpBytesResult(const HttpTransferRequest&)> fetch;
std::function<HttpDownloadResult(const HttpTransferRequest&,
const std::filesystem::path&, int)>
download;
std::function<int(const std::vector<std::string>&)> run;
std::function<std::int64_t()> now;
};

struct NightcapStatus {
std::string installed;
std::optional<std::string> latest;
std::string installed_pending;
std::string page;
InstallMethod method;
std::int64_t checked_at = 0;
bool newer = false;
bool can_install = false;
std::string note;

std::string ToJson() const;
};

// Asks GitHub at most every kNightcapCheckInterval unless `force`; `offline`
// answers only from the last check.
std::optional<NightcapStatus> CheckNightcapRelease(
const NightcapUpdaterEnvironment& environment, bool force, bool offline,
std::string* error);

// Removes the partial AppImage copy a stopped install left beside the
// AppImage. Does nothing while another install holds the lock.
void CleanUpInterruptedInstall(const NightcapUpdaterEnvironment& environment);

// Installs the newest release when it is newer than the running one, after
// checking SHA256SUMS against the release key and the download against it.
// Progress goes to `progress_fd` in the Roblox updater's format.
bool InstallNightcapRelease(const NightcapUpdaterEnvironment& environment,
int progress_fd, std::string* message,
std::string* error);

NightcapUpdaterEnvironment SystemNightcapUpdaterEnvironment(
std::filesystem::path data_root, std::filesystem::path cache_root,
std::string running_version, std::string public_key_pem);

} // namespace mocktail::update

#endif // MOCKTAIL_UPDATE_NIGHTCAP_SELF_UPDATE_H_
Loading
Loading