Add channels support to sparkle-cli

This commit is contained in:
Zorg committed 2021-06-27 22:40:16 -07:00
1 parent d8f5f58468
commit 78a66c7dda
3 files changed
+28 -4

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SPUCommandLineDriver : NSObject
- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose;
- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath allowedChannels:(NSSet<NSString *> *)allowedChannels customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose;
- (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow;
+9 -1
View File
@@ -16,6 +16,7 @@
@property (nonatomic, readonly) BOOL verbose;
@property (nonatomic) BOOL probingForUpdates;
@property (nonatomic, readonly) BOOL interactive;
@property (nonatomic, readonly) NSSet<NSString *> *allowedChannels;
@property (nonatomic, copy, readonly, nullable) NSString *customFeedURL;
@end
@@ -26,9 +27,10 @@
@synthesize verbose = _verbose;
@synthesize probingForUpdates = _probingForUpdates;
@synthesize interactive = _interactive;
@synthesize allowedChannels = _allowedChannels;
@synthesize customFeedURL = _customFeedURL;
- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose
- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath allowedChannels:(NSSet<NSString *> *)allowedChannels customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose
{
self = [super init];
if (self != nil) {
@@ -49,6 +51,7 @@
_verbose = verbose;
_interactive = interactiveInstallation;
_allowedChannels = allowedChannels;
_customFeedURL = [customFeedURL copy];
id <SPUUserDriver> userDriver = [[SPUCommandLineUserDriver alloc] initWithUpdatePermissionResponse:updatePermissionResponse deferInstallation:deferInstallation verbose:verbose];
@@ -84,6 +87,11 @@
}
}
- (NSSet<NSString *> *)allowedChannelsForUpdater:(SPUUpdater *)__unused updater
{
return self.allowedChannels;
}
- (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)__unused updater
{
return self.customFeedURL;
+18 -2
View File
@@ -20,10 +20,11 @@
#define PROBE_FLAG "probe"
#define INTERACTIVE_FLAG "interactive"
#define FEED_URL_FLAG "feed-url"
#define CHANNELS_FLAG "channels"
static void printUsage(char **argv)
{
fprintf(stderr, "Usage: %s bundle [--%s <app-path>] [--%s] [--%s] [--%s] [--%s] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, PROBE_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG, SEND_PROFILE_FLAG, DEFER_FLAG, INTERACTIVE_FLAG, VERBOSE_FLAG);
fprintf(stderr, "Usage: %s bundle [--%s app-path] [--%s] [--%s] [--%s chan1,chan2,…] [--%s feed-url] [--%s] [--%s] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, PROBE_FLAG, CHANNELS_FLAG, FEED_URL_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG, SEND_PROFILE_FLAG, DEFER_FLAG, INTERACTIVE_FLAG, VERBOSE_FLAG);
fprintf(stderr, "Description:\n");
fprintf(stderr, " Check if any new updates for a Sparkle supported bundle need to be installed.\n\n");
fprintf(stderr, " If any new updates need to be installed, the user application\n is terminated and the update is installed immediately unless --%s\n is specified. If the application was alive, then it will be relaunched after.\n\n", DEFER_FLAG);
@@ -36,6 +37,7 @@ static void printUsage(char **argv)
fprintf(stderr, " --%s\n Path to the application to watch for termination and to relaunch.\n If not provided, this is assumed to be the same as the bundle.\n", APPLICATION_FLAG);
fprintf(stderr, " --%s\n Immediately checks for updates to install.\n Without this, updates are checked only when needed on a scheduled basis.\n", CHECK_NOW_FLAG);
fprintf(stderr, " --%s\n Probe for updates. Check if any updates are available but do not install.\n An exit status of 0 is returned if a new update is available.\n", PROBE_FLAG);
fprintf(stderr, " --%s\n List of allowed Sparkle channels to look for updates in. By default,\n only the default channel is used.\n", CHANNELS_FLAG);
fprintf(stderr, " --%s\n URL for appcast feed. This URL will be used for the feed instead of the one\n in the bundle's Info.plist or in the bundle's user defaults.\n", FEED_URL_FLAG);
fprintf(stderr, " --%s\n Allows prompting the user for an authorization dialog prompt if the\n installer needs elevated privileges, or allows performing an interactive\n installer package.\n", INTERACTIVE_FLAG);
fprintf(stderr, " --%s\n If update permission is requested, this enables automatic update checks.\n Note that this behavior may overwrite the user's defaults for the bundle.\n This option has no effect if --%s is passed, or if the\n user has replied to this request already, or if the developer configured\n to skip it.\n", GRANT_AUTOMATIC_CHECKING_FLAG, CHECK_NOW_FLAG);
@@ -55,6 +57,7 @@ int main(int argc, char **argv)
struct option longOptions[] = {
{APPLICATION_FLAG, required_argument, NULL, 0},
{CHANNELS_FLAG, required_argument, NULL, 0},
{FEED_URL_FLAG, required_argument, NULL, 0},
{DEFER_FLAG, no_argument, NULL, 0},
{VERBOSE_FLAG, no_argument, NULL, 0},
@@ -68,6 +71,7 @@ int main(int argc, char **argv)
NSString *applicationPath = nil;
NSString *feedURL = nil;
NSSet<NSString *> *channels = [NSSet set];
BOOL deferInstall = NO;
BOOL verbose = NO;
BOOL checkForUpdatesNow = NO;
@@ -100,6 +104,18 @@ int main(int argc, char **argv)
printUsage(argv);
return EXIT_FAILURE;
}
} else if (strcmp(CHANNELS_FLAG, longOptions[optionIndex].name) == 0) {
assert(optarg != NULL);
NSString *channelsString = [[NSString alloc] initWithUTF8String:optarg];
if (channelsString == nil) {
printUsage(argv);
return EXIT_FAILURE;
}
if (channelsString.length > 0) {
channels = [NSSet setWithArray:[channelsString componentsSeparatedByString:@","]];
}
} else if (strcmp(DEFER_FLAG, longOptions[optionIndex].name) == 0) {
deferInstall = YES;
} else if (strcmp(VERBOSE_FLAG, longOptions[optionIndex].name) == 0) {
@@ -146,7 +162,7 @@ int main(int argc, char **argv)
updatePermissionResponse = [[SUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:YES sendSystemProfile:sendProfile];
}
SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath customFeedURL:feedURL updatePermissionResponse:updatePermissionResponse deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose];
SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath allowedChannels:channels customFeedURL:feedURL updatePermissionResponse:updatePermissionResponse deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose];
if (driver == nil) {
fprintf(stderr, "Error: Failed to initialize updater. Are the bundle paths provided valid?\n");
return EXIT_FAILURE;