Skip to content

Commit 8c7f183

Browse files
committed
Implement Auto-Update mechanism for Homebrew everytime a new version of ManageConky installs.
About this feature: I am using the closed-source objective-c framework "HomebrewCtl" which supports basic control for Homebrew on mac. To download the Framework and test it head to "https://github.com/npyl/HomebrewCtl-Issues/releases". Also, feel free to submit any issues and support me using my cryptocurrency keys.
1 parent 5eaa17f commit 8c7f183

File tree

19 files changed

+272
-5
lines changed

19 files changed

+272
-5
lines changed

Manage Conky.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
090E425D20D5782900D78902 /* HomebrewCtl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 090E425C20D5782900D78902 /* HomebrewCtl.framework */; };
1011
092114A52084BE9A0098AC5D /* Changelog.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 092114A42084BE9A0098AC5D /* Changelog.rtf */; };
1112
093BDFC020861BCD004E6354 /* Editor.xib in Resources */ = {isa = PBXBuildFile; fileRef = 093BDFBF20861BCD004E6354 /* Editor.xib */; };
1213
093BDFC320861C0E004E6354 /* MCConfigEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 093BDFC220861C0E004E6354 /* MCConfigEditor.m */; };
@@ -110,6 +111,7 @@
110111
/* End PBXCopyFilesBuildPhase section */
111112

112113
/* Begin PBXFileReference section */
114+
090E425C20D5782900D78902 /* HomebrewCtl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HomebrewCtl.framework; path = "Manage Conky/Frameworks/HomebrewCtl.framework"; sourceTree = "<group>"; };
113115
092114A42084BE9A0098AC5D /* Changelog.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Changelog.rtf; path = "Supporting Files/Changelog.rtf"; sourceTree = "<group>"; };
114116
093BDFBF20861BCD004E6354 /* Editor.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Editor.xib; sourceTree = "<group>"; };
115117
093BDFC120861C0E004E6354 /* MCConfigEditor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCConfigEditor.h; sourceTree = "<group>"; };
@@ -178,6 +180,7 @@
178180
buildActionMask = 2147483647;
179181
files = (
180182
095F9B412077DE6E003C60C1 /* FinderSync.framework in Frameworks */,
183+
090E425D20D5782900D78902 /* HomebrewCtl.framework in Frameworks */,
181184
77F6D6D51F65EB2E00A61645 /* ServiceManagement.framework in Frameworks */,
182185
27F326D865D8A2AC31DFA4ED /* Pods_Manage_Conky.framework in Frameworks */,
183186
);
@@ -278,6 +281,7 @@
278281
77F6D6D31F65EB2E00A61645 /* Frameworks */ = {
279282
isa = PBXGroup;
280283
children = (
284+
090E425C20D5782900D78902 /* HomebrewCtl.framework */,
281285
095F9B402077DE6E003C60C1 /* FinderSync.framework */,
282286
095F9B3E2077DD74003C60C1 /* Foundation.framework */,
283287
095F9B3C2077DD6E003C60C1 /* Cocoa.framework */,
@@ -752,6 +756,13 @@
752756
CODE_SIGN_STYLE = Automatic;
753757
COMBINE_HIDPI_IMAGES = YES;
754758
DEVELOPMENT_TEAM = CC63MSFH9N;
759+
FRAMEWORK_SEARCH_PATHS = (
760+
"$(inherited)",
761+
"$(PROJECT_DIR)/Manage\\ Conky",
762+
"$(PROJECT_DIR)/Manage\\ Conky",
763+
"$(PROJECT_DIR)/Manage\\ Conky/Frameworks",
764+
"$(PROJECT_DIR)/Manage\\ Conky/Frameworks",
765+
);
755766
INFOPLIST_FILE = "Manage Conky/Info.plist";
756767
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
757768
MACOSX_DEPLOYMENT_TARGET = 10.13;
@@ -771,6 +782,13 @@
771782
CODE_SIGN_STYLE = Automatic;
772783
COMBINE_HIDPI_IMAGES = YES;
773784
DEVELOPMENT_TEAM = CC63MSFH9N;
785+
FRAMEWORK_SEARCH_PATHS = (
786+
"$(inherited)",
787+
"$(PROJECT_DIR)/Manage\\ Conky",
788+
"$(PROJECT_DIR)/Manage\\ Conky",
789+
"$(PROJECT_DIR)/Manage\\ Conky/Frameworks",
790+
"$(PROJECT_DIR)/Manage\\ Conky/Frameworks",
791+
);
774792
INFOPLIST_FILE = "Manage Conky/Info.plist";
775793
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
776794
MACOSX_DEPLOYMENT_TARGET = 10.13;

Manage Conky.xcodeproj/xcuserdata/npyl.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<key>Manage Conky.xcscheme</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>11</integer>
10+
<integer>4</integer>
1111
</dict>
1212
<key>ManageConkySMJobBlessHelper.xcscheme</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>10</integer>
15+
<integer>3</integer>
1616
</dict>
1717
</dict>
1818
</dict>

Manage Conky/ConkyPreferencesSheetController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "ConkyPreferencesSheetController.h"
1010

1111
#import <ServiceManagement/ServiceManagement.h>
12+
#import "Frameworks/HomebrewCtl.framework/Headers/HomebrewCtl.h"
1213
#import "NSAlert+runModalSheet.h"
1314
#import "PFMoveApplication.h"
1415
#import "ViewController.h"
@@ -448,6 +449,12 @@ - (void)updaterDidRelaunchApplication:(SUUpdater *)updater
448449
*/
449450
NSLog(@"Must install ConkyX after update...");
450451
[self installConky];
452+
453+
// TODO: This should happen on scheduled times! :D
454+
/* Upon every ManageConky update, also update Homebrew */
455+
DefaultHomebrewCtl *dhc = [DefaultHomebrewCtl controller];
456+
[dhc updateHomebrew];
457+
[dhc upgradeHomebrew];
451458
}
452459

453460
//
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Headers
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/HomebrewCtl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Modules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Resources
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// HomebrewCtl.h
3+
// HomebrewCtl
4+
//
5+
// Created by npyl on 03/06/2018.
6+
// Copyright © 2018 npyl. All rights reserved.
7+
//
8+
9+
/*
10+
* Installing Homebrew (https://brew.sh) at custom location is not officially supported;
11+
* though this framework has the goal to "put some pressure" to the team to support it
12+
* and to provide a cool API for Homebrew-control from Objective-C.
13+
*/
14+
15+
#import <Cocoa/Cocoa.h>
16+
17+
#define HOMEBREW_CTL_API_VER 0.3
18+
19+
/* Cool Defines */
20+
#define DEFAULT_HOMEBREW_PREFIX @"/usr/local"
21+
22+
/* HomebrewCtl errors */
23+
#define HOMEBREWCTL_ERROR_DOMAIN @"HomebrewCtlErrorDomain"
24+
25+
#define kHCMalformedPathPassedMsg @"Path has incorrect structure; Please check your `location` argument"
26+
#define kHCInstallFailedInstallationAlreadyExistsMsg @"A Homebrew installation already exists at location specified"
27+
#define kHCFailedToCreateHomebrewDicectoryErrorMsg @"Failed to create Homebrew directory inside the location you provided" /* e.g. mkdir problem */
28+
29+
30+
enum HomebrewCtlErrors {
31+
kHCMalformedPathPassed = -1,
32+
kHCInstallFailedInstallationAlreadyExists = -2,
33+
kHCFailedToUpdate = -3,
34+
kHCFailedToUpgrade = -4,
35+
};
36+
37+
38+
@interface HomebrewCtl : NSObject
39+
{
40+
NSThread *th;
41+
}
42+
43+
+ (instancetype)init;
44+
+ (instancetype)controller;
45+
46+
@property BOOL overwriteExistingInstallation;
47+
@property BOOL installationFinished;
48+
@property BOOL needsUpgrade;
49+
50+
/**
51+
* Download and install Homebrew in a custom location
52+
*
53+
* @note Doesn't add new Homebrew installation to $PATH
54+
* @note Aborts if installation already present at `location`; Please set `overwriteExistingInstallation` accordingly.
55+
*
56+
* @warning BEWARE; If you choose to overwrite your installation will be completely removed; you will loose all your software.
57+
*
58+
* @param location Location to install Homebrew
59+
* @param error Error
60+
* @return Returns `YES` on success, or `NO` on failure.
61+
*/
62+
- (BOOL)installHomebrewAt:(NSString *)location error:(NSError **)error;
63+
- (void)installHomebrewAt:(NSString *)location completionHandler:(void (^)(NSInteger terminationStatus, NSError *error))completionHandler;
64+
65+
/**
66+
* Uninstall a Homebrew installation
67+
*
68+
* @note Removes caches and logs by default
69+
* @param location Location of Homebrew installation
70+
*/
71+
- (BOOL)uninstallHomebrewAt:(NSString *)location error:(NSError **)error;
72+
73+
/**
74+
* Update a Homebrew installation
75+
*
76+
* @param location Location of Homebrew installation
77+
*/
78+
- (void)updateHomebrewAt:(NSString *)location;
79+
80+
/**
81+
* Upgrade a Homebrew installation
82+
*
83+
* @param location Location of Homebrew installation
84+
*/
85+
- (void)upgradeHomebrewAt:(NSString *)location;
86+
87+
/**
88+
* Check if a Homebrew installation exists at a location
89+
*
90+
* @param location The containing directory of the Homebrew installation
91+
* @return `YES` if it exists, or `NO` if it doesn't.
92+
*/
93+
- (BOOL)installationExistsAt:(NSString *)location;
94+
95+
- (BOOL)installLibraries:(NSArray *)arr at:(NSString *)location;
96+
97+
- (void)addBINToPATHForInstallation:(NSString *)location;
98+
99+
- (void)waitUntilFinished;
100+
101+
@end
102+
103+
@interface DefaultHomebrewCtl : HomebrewCtl
104+
105+
- (BOOL)installHomebrew:(NSError **)error;
106+
- (void)installHomebrewWithCompletionHandler:(void (^)(NSInteger terminationStatus, NSError *error))completionHandler;
107+
- (BOOL)uninstallHomebrew:(NSError **)error;
108+
- (void)updateHomebrew;
109+
- (void)upgradeHomebrew;
110+
- (BOOL)installationExists;
111+
- (void)addBINToPATH;
112+
113+
@end
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
framework module HomebrewCtl {
2+
umbrella header "HomebrewCtl.h"
3+
4+
export *
5+
module * { export * }
6+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildMachineOSBuild</key>
6+
<string>17G39b</string>
7+
<key>CFBundleDevelopmentRegion</key>
8+
<string>en</string>
9+
<key>CFBundleExecutable</key>
10+
<string>HomebrewCtl</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>org.npyl.HomebrewCtl</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>HomebrewCtl</string>
17+
<key>CFBundlePackageType</key>
18+
<string>FMWK</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSupportedPlatforms</key>
22+
<array>
23+
<string>MacOSX</string>
24+
</array>
25+
<key>CFBundleVersion</key>
26+
<string>1</string>
27+
<key>DTCompiler</key>
28+
<string>com.apple.compilers.llvm.clang.1_0</string>
29+
<key>DTPlatformBuild</key>
30+
<string>9F1027a</string>
31+
<key>DTPlatformVersion</key>
32+
<string>GM</string>
33+
<key>DTSDKBuild</key>
34+
<string>17E189</string>
35+
<key>DTSDKName</key>
36+
<string>macosx10.13</string>
37+
<key>DTXcode</key>
38+
<string>0940</string>
39+
<key>DTXcodeBuild</key>
40+
<string>9F1027a</string>
41+
<key>NSHumanReadableCopyright</key>
42+
<string>Copyright © 2018 npyl. All rights reserved.</string>
43+
</dict>
44+
</plist>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
# InstallHomebrewAt.sh
4+
# HomebrewCtl
5+
#
6+
# Created by npyl on 03/06/2018.
7+
# Copyright © 2018 npyl. All rights reserved.
8+
9+
LOCATION=$1
10+
11+
mkdir -p $LOCATION/Homebrew
12+
13+
# check exit status
14+
if [ $? != 0 ]
15+
then
16+
exit $?
17+
fi
18+
19+
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C $LOCATION/Homebrew
20+
21+
exit $?
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# InstallLibrariesAt.sh
4+
# HomebrewCtl
5+
#
6+
# Created by npyl on 15/06/2018.
7+
# Copyright © 2018 npyl. All rights reserved.
8+
9+
LOCATION=$1
10+
LIBS=${@:2}
11+
12+
$LOCATION/Homebrew/bin/brew install $LIBS
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# UninstallHomebrewAt.sh
4+
# HomebrewCtl
5+
#
6+
# Created by npyl on 04/06/2018.
7+
# Copyright © 2018 npyl. All rights reserved.
8+
9+
LOCATION=$1
10+
11+
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > /tmp/uninstall
12+
chmod +x /tmp/uninstall
13+
/tmp/uninstall --path=$LOCATION/Homebrew --force
14+
15+
exit $?
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# UpdateHomebrewAt.sh
4+
# HomebrewCtl
5+
#
6+
# Created by npyl on 03/06/2018.
7+
# Copyright © 2018 npyl. All rights reserved.
8+
9+
LOCATION=$1
10+
11+
$LOCATION/Homebrew/bin/brew update
12+
13+
exit $?
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# UpgradeHomebrewAt.sh
4+
# HomebrewCtl
5+
#
6+
# Created by npyl on 03/06/2018.
7+
# Copyright © 2018 npyl. All rights reserved.
8+
9+
LOCATION=$1
10+
11+
$LOCATION/Homebrew/bin/brew upgrade
12+
13+
exit $?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A

Pods/Pods.xcodeproj/xcuserdata/npyl.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)