Skip to content

Commit 5018524

Browse files
committed
Install gitx (the CLI) via Install.sh.
To do this we use a modified gitx_askpasswd to ask for sudo permissions during build. Modifications to gitx_askpasswd include: - Ability to specify the dialog info text (or title) via STDIN or a GITX_ASKPASSWD_DIALOG_TITLE env variable. Install.sh uses the env var in 'sudo -A -E' to kindly request the password. The point of this is to provide a sensible title which lets the user/dev know why he has to enter his password in a dialog that is obviously not from Mac OS X. Install.sh will now also create the folder hierarchy needed for the install paths set in Install.xcconfig using 'sudo -A -E' if neccessary (if the folders don't exist).
1 parent 7b28685 commit 5018524

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

Install.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
#include "Release.xcconfig"
2727

2828
CUSTOM_INSTALL_DIR = $(DEVELOPER_DIR)/Applications/Utilities/Third-Party // used with the Install.sh script
29+
CLI_CUSTOM_INSTALL_DIR = /usr/local/bin // used with the Install.sh script

gitx_askpasswd_main.m

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ @interface GAPAppDelegate : NSObject
2424
NSSecureTextField* mPasswordField;
2525
}
2626

27-
-(NSPanel*) passwordPanel;
27+
-(NSPanel*) passwordPanel:(NSString *)title;
2828

2929
-(IBAction) doOKButton: (id)sender;
3030
-(IBAction) doCancelButton: (id)sender;
@@ -45,14 +45,15 @@ -(void) dealloc
4545
[super dealloc];
4646
}
4747

48-
-(NSPanel*) passwordPanel
48+
-(NSPanel*) passwordPanel:(NSString *)title
4949
{
5050
if( !mPasswordPanel )
5151
{
5252
NSRect box = NSMakeRect( 100, 100, 250, 100 );
53-
mPasswordPanel = [[NSPanel alloc] initWithContentRect: box
54-
styleMask: NSTitledWindowMask
55-
backing: NSBackingStoreBuffered defer: NO];
53+
mPasswordPanel = [[NSPanel alloc] initWithContentRect: box
54+
styleMask: NSTitledWindowMask
55+
backing: NSBackingStoreBuffered
56+
defer: NO];
5657
[mPasswordPanel setHidesOnDeactivate: NO];
5758
[mPasswordPanel setLevel: NSFloatingWindowLevel];
5859
[mPasswordPanel center];
@@ -115,7 +116,7 @@ -(NSPanel*) passwordPanel
115116
[passwordLabel setBordered: NO];
116117
[passwordLabel setBezeled: NO];
117118
[passwordLabel setDrawsBackground: NO];
118-
[passwordLabel setStringValue: @"Please enter your password:"]; // +++ Localize.
119+
[passwordLabel setStringValue: title]; // +++ Localize.
119120
[[mPasswordPanel contentView] addSubview: passwordLabel];
120121
}
121122

@@ -148,7 +149,21 @@ int main( int argc, const char** argv )
148149
NSApplication * app = [NSApplication sharedApplication];
149150
GAPAppDelegate * appDel = [[GAPAppDelegate alloc] init];
150151
[app setDelegate: appDel];
151-
NSWindow* passPanel = [appDel passwordPanel];
152+
153+
NSString * title;
154+
const char * envtitle = getenv("GITX_ASKPASSWD_DIALOG_TITLE");
155+
156+
if (envtitle != NULL) {
157+
title = [NSString stringWithUTF8String:envtitle];
158+
} else {
159+
if (argc > 1) {
160+
title = [NSString stringWithUTF8String:argv[1]];
161+
} else {
162+
title = @"Please enter your password:";
163+
}
164+
}
165+
166+
NSWindow* passPanel = [appDel passwordPanel:title];
152167

153168
[app activateIgnoringOtherApps: YES];
154169
[passPanel makeKeyAndOrderFront: nil];

scripts/install.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,29 @@
1919
# limitations under the License.
2020

2121
# Installs GitX.app to $CUSTOM_INSTALL_DIR from Install.xcconfig
22+
# Installs gitx to $CLI_CUSTOM_INSTALL_DIR from Install.xcconfig using gitx_askpasswd
23+
24+
export SUDO_ASKPASS="$BUILT_PRODUCTS_DIR/gitx_askpasswd"
25+
export GITX_ASKPASSWD_DIALOG_TITLE="Please enter sudo pass for Install"
2226

2327
if [[ $BUILD_STYLE =~ "Install" ]]; then
24-
echo "Installing to ${CUSTOM_INSTALL_DIR}... (switch to build config other than Install to avoid)"
28+
if [[ ! -d "$CUSTOM_INSTALL_DIR" ]]; then
29+
echo "$CUSTOM_INSTALL_DIR doesn't exist. Will create it for you..."
30+
sudo -A -E /bin/mkdir -p "${CUSTOM_INSTALL_DIR}"
31+
fi
32+
if [[ ! -d "$CLI_CUSTOM_INSTALL_DIR" ]]; then
33+
echo "$CLI_CUSTOM_INSTALL_DIR doesn't exist. Will create it for you..."
34+
sudo -A -E /bin/mkdir -p "${CLI_CUSTOM_INSTALL_DIR}"
35+
fi
36+
echo "Installing ${FULL_PRODUCT_NAME} to ${CUSTOM_INSTALL_DIR}... "
37+
echo "Installing gitx command line tool to ${CLI_CUSTOM_INSTALL_DIR}..."
38+
echo "(switch to build config other than Install to avoid)"
2539
if [[ -e /opt/local/bin/rsync ]]; then
2640
/opt/local/bin/rsync -rlHEptog --xattrs --acls "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME" "$CUSTOM_INSTALL_DIR/"
41+
sudo -A -E /opt/local/bin/rsync -rlHEptog --xattrs --acls "$BUILT_PRODUCTS_DIR/gitx" "$CLI_CUSTOM_INSTALL_DIR/"
2742
else
2843
/usr/bin/rsync -rlHEptog "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME" "$CUSTOM_INSTALL_DIR/"
44+
sudo -A -E /usr/bin/rsync -rlHEptog "$BUILT_PRODUCTS_DIR/gitx" "$CLI_CUSTOM_INSTALL_DIR/"
2945
fi
3046
else
3147
echo '$BUILD_STYLE does not contain "Install"... nothing to copy'

0 commit comments

Comments
 (0)