mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Add interactive option to sparkle-cli
This allows installation by requesting the user to enter a password when elevated privileges are necessary. This only works if the application is alive before installation begins.
This commit is contained in:
1 parent
ec0889ef83
commit
a113ce49bd
3 files changed
+19
-8
No files matched your search
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUCommandLineDriver : NSObject
|
||||
|
||||
- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose;
|
||||
- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose;
|
||||
|
||||
- (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
@property (nonatomic, readonly) NSString *applicationBundlePath;
|
||||
@property (nonatomic, readonly) BOOL verbose;
|
||||
@property (nonatomic) BOOL probingForUpdates;
|
||||
@property (nonatomic, readonly) BOOL interactive;
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,8 +26,9 @@
|
||||
@synthesize applicationBundlePath = _applicationBundlePath;
|
||||
@synthesize verbose = _verbose;
|
||||
@synthesize probingForUpdates = _probingForUpdates;
|
||||
@synthesize interactive = _interactive;
|
||||
|
||||
- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose
|
||||
- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
@@ -46,6 +48,7 @@
|
||||
}
|
||||
|
||||
_verbose = verbose;
|
||||
_interactive = interactiveInstallation;
|
||||
|
||||
_applicationBundlePath = applicationBundle.bundlePath;
|
||||
|
||||
@@ -57,7 +60,9 @@
|
||||
|
||||
- (BOOL)updaterShouldInheritInstallPrivileges:(SUUpdater *)__unused updater
|
||||
{
|
||||
return YES;
|
||||
// If the installation is interactive, we can show an authorization prompt for requesting additional privileges,
|
||||
// otherwise we should have the installer inherit the updater's privileges.
|
||||
return !self.interactive;
|
||||
}
|
||||
|
||||
// In case we find an update during probing, otherwise we leave this to the user driver
|
||||
|
||||
+11
-5
@@ -18,25 +18,27 @@
|
||||
#define GRANT_AUTOMATIC_CHECKING_FLAG "grant-automatic-checks"
|
||||
#define SEND_PROFILE_FLAG "send-profile"
|
||||
#define PROBE_FLAG "probe"
|
||||
#define INTERACTIVE_FLAG "interactive"
|
||||
|
||||
static void printUsage(char **argv)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s bundle [--%s <app-path>] [--%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, VERBOSE_FLAG);
|
||||
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, "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);
|
||||
fprintf(stderr, " To check if an update is available without installing, use --%s.\n\n", PROBE_FLAG);
|
||||
fprintf(stderr, " if no updates are available now, or if the last update check was recently\n (unless --%s is specified) then nothing is done.\n\n", CHECK_NOW_FLAG);
|
||||
fprintf(stderr, " If update permission is requested and --%s is not\n specified, then checking for updates is aborted.\n\n", GRANT_AUTOMATIC_CHECKING_FLAG);
|
||||
fprintf(stderr, " Unlike an application that uses Sparkle, this tool will not request for\n escalated authorization. Instead, this tool is expected to run under\n the privileges required to update the bundle. For example, if the bundle to\n update is owned by root, you may have to run this tool as root. Another\n example is a non-admin user attempting to update an app in /Applications\n\n");
|
||||
fprintf(stderr, " This tool does not linger around for long, and prefers to exit immediately.\n If --%s is specified, this tool will exit leaving a spawned process\n for finishing the installation.\n", DEFER_FLAG);
|
||||
fprintf(stderr, " Unless --%s is specified, this tool will not request for escalated\n authorization. The default behavior assumes this tool will for example be ran\n as root to update an application owned by root.\n\n", INTERACTIVE_FLAG);
|
||||
fprintf(stderr, " If --%s is specified, this tool will exit leaving a spawned process\n for finishing the installation after the target application terminates.\n", DEFER_FLAG);
|
||||
fprintf(stderr, "Options:\n");
|
||||
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 Allows prompting the user for an authorization dialog prompt if the\n installer needs elevated privileges. Without this flag, the tool would have\n to run under the sufficient install privileges. Note this flag may not\n function if the target application is terminated before installation begins.\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);
|
||||
fprintf(stderr, " --%s\n Choose to send system profile information if update permission is requested.\n This option can only take effect if --%s is passed.\n", SEND_PROFILE_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG);
|
||||
fprintf(stderr, " --%s\n Defer installation until after the application terminates on its own. The\n application will not be relaunched.\n", DEFER_FLAG);
|
||||
fprintf(stderr, " --%s\n Defer installation until after the application terminates on its own. The\n application will not be relaunched. This option does not work together with\n --%s.\n", DEFER_FLAG, INTERACTIVE_FLAG);
|
||||
fprintf(stderr, " --%s\n Enable verbose logging.\n", VERBOSE_FLAG);
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ int main(int argc, char **argv)
|
||||
{GRANT_AUTOMATIC_CHECKING_FLAG, no_argument, NULL, 0},
|
||||
{SEND_PROFILE_FLAG, no_argument, NULL, 0},
|
||||
{PROBE_FLAG, no_argument, NULL, 0},
|
||||
{INTERACTIVE_FLAG, no_argument, NULL, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -62,6 +65,7 @@ int main(int argc, char **argv)
|
||||
BOOL grantAutomaticChecking = NO;
|
||||
BOOL sendProfile = NO;
|
||||
BOOL probeForUpdates = NO;
|
||||
BOOL interactive = NO;
|
||||
|
||||
while (YES) {
|
||||
int optionIndex = 0;
|
||||
@@ -91,6 +95,8 @@ int main(int argc, char **argv)
|
||||
sendProfile = YES;
|
||||
} else if (strcmp(PROBE_FLAG, longOptions[optionIndex].name) == 0) {
|
||||
probeForUpdates = YES;
|
||||
} else if (strcmp(INTERACTIVE_FLAG, longOptions[optionIndex].name) == 0) {
|
||||
interactive = YES;
|
||||
}
|
||||
case ':':
|
||||
break;
|
||||
@@ -118,7 +124,7 @@ int main(int argc, char **argv)
|
||||
updatePermission = [SUUpdatePermission updatePermissionWithChoice:SUAutomaticallyCheck sendProfile:sendProfile];
|
||||
}
|
||||
|
||||
SUCommandLineDriver *driver = [[SUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath updatePermission:updatePermission deferInstallation:deferInstall verbose:verbose];
|
||||
SUCommandLineDriver *driver = [[SUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath updatePermission:updatePermission deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose];
|
||||
if (driver == nil) {
|
||||
fprintf(stderr, "Error: Failed to initialize updater. Are the bundle paths provided valid?\n");
|
||||
printUsage(argv);
|
||||
|
||||
Reference in new issue
Block a user