Skip to content

Commit 1042b0d

Browse files
committed
Add basic .pkg installer script
Add a simple flat-package installer with postinstall script to configure the user's system gitconfig.
1 parent b5eca7c commit 1042b0d

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,7 @@ ASALocalRun/
331331

332332
# macOS Finder files
333333
.DS_Store
334+
335+
# GCM build output
336+
out/
337+

macos/installer/build-installer.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Product information
4+
NAME="Git Credential Manager"
5+
IDENTIFIER="com.microsoft.GitCredentialManager"
6+
INSTALL_LOCATION="/usr/local/share/gcm-core"
7+
8+
# Directories
9+
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
10+
ROOT="$( cd $THISDIR/../.. ; pwd -P )"
11+
OUT=$ROOT/out
12+
PKGSCRIPTS=$ROOT/macos/installer/scripts
13+
MACOUT=$OUT/macos
14+
INSTALLEROUT=$MACOUT/installer/
15+
PKGPAYLOAD=$INSTALLEROUT/payload
16+
17+
# Parse script arguments
18+
for i in "$@"
19+
do
20+
case $i in
21+
-v=*|--version=*)
22+
VERSION="${i#*=}"
23+
shift # past argument=value
24+
;;
25+
-c=*|--configuration=*)
26+
CONFIGURATION="${i#*=}"
27+
shift # past argument=value
28+
;;
29+
*)
30+
# unknown option
31+
;;
32+
esac
33+
done
34+
35+
# Set default arguments
36+
VERSION=${VERSION:=1.0}
37+
CONFIGURATION=${CONFIGURATION:=Release}
38+
39+
# Ensure output directories exist
40+
mkdir -p $MACOUT $PKGPAYLOAD
41+
42+
# Publish the core product
43+
dotnet publish --runtime osx-x64 --configuration $CONFIGURATION --output $PKGPAYLOAD $ROOT/common/src/Git-Credential-Manager
44+
45+
# Build the native credential helpers
46+
pod install --project-directory=$ROOT/macos/Microsoft.Authentication.Helper
47+
xcodebuild \
48+
-workspace $ROOT/macos/Microsoft.Authentication.Helper/Microsoft.Authentication.Helper.xcworkspace \
49+
-scheme Microsoft.Authentication.Helper \
50+
-configuration $CONFIGURATION \
51+
-derivedDataPath $MACOUT/Microsoft.Authentication.Helper
52+
53+
# Copy helper executables to payload directory
54+
cp $MACOUT/Microsoft.Authentication.Helper/Build/Products/$CONFIGURATION/Microsoft.Authentication.Helper $PKGPAYLOAD
55+
56+
# Copy uninstaller script
57+
cp $ROOT/macos/installer/uninstall-gcm.sh $PKGPAYLOAD
58+
59+
# Remove any unwanted .DS_Store files
60+
find $PKGPAYLOAD -name '*.DS_Store' -type f -delete
61+
62+
# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
63+
/bin/chmod -R 755 $PKGPAYLOAD
64+
65+
# Remove any extended attributes (ACEs)
66+
/usr/bin/xattr -rc $PKGPAYLOAD
67+
68+
# Build installer package
69+
/usr/bin/pkgbuild \
70+
--root $PKGPAYLOAD/ \
71+
--install-location "$INSTALL_LOCATION" \
72+
--scripts $PKGSCRIPTS/ \
73+
--identifier "$IDENTIFIER" \
74+
--version "$VERSION" \
75+
"$INSTALLEROUT/$NAME.pkg"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# When we're invoked from the macOS Installer, PATH is that of root's
5+
# Even invoking `launchctl asuser` or `su` the PATH remains the same
6+
# because the user's profile has not been run.
7+
# To ensure we have the user's correct PATH we run `path_helper` first.
8+
PATH=""
9+
eval $(/usr/libexec/path_helper -s)
10+
11+
git config --system credential.helper /usr/local/share/gcm-core/git-credential-manager
12+
git config --system credential.https://dev.azure.com.useHttpPath true
13+
14+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Make symlink to GCM in /usr/local/bin
5+
if [ ! -e /usr/local/bin/git-credential-manager ]
6+
then
7+
/bin/ln -s /usr/local/share/gcm-core/git-credential-manager /usr/local/bin/git-credential-manager
8+
fi
9+
10+
# Set system gitconfig for the current user
11+
USER_ID=`id -u "${USER}"`
12+
if [ "${COMMAND_LINE_INSTALL}" = "" ]
13+
then
14+
/bin/launchctl asuser "${USER_ID}" "${PWD}/configure-git.sh"
15+
fi
16+
17+
exit 0

macos/installer/uninstall-gcm.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Unconfigure GCM
4+
HELPER=`git config --system credential.helper`
5+
if [ $HELPER = "/usr/local/share/gcm-core/git-credential-manager" ]
6+
then
7+
echo "Resetting credential helper to 'osxkeychain'..."
8+
sudo git config --system credential.helper osxkeychain
9+
else
10+
echo "GCM was not configured as the Git credential helper."
11+
fi
12+
13+
# Remove GCM symlink
14+
if [ -L /usr/local/bin/git-credential-manager ]
15+
then
16+
echo "Deleting GCM symlink..."
17+
rm /usr/local/bin/git-credential-manager
18+
else
19+
echo "No GCM symlink found."
20+
fi
21+
22+
# Forget package installation/delete receipt
23+
sudo pkgutil --forget com.microsoft.GitCredentialManager
24+
25+
# Remove application files
26+
if [ -d /usr/local/share/gcm-core/ ]
27+
then
28+
echo "Deleting GCM application files..."
29+
sudo rm -rf /usr/local/share/gcm-core/
30+
else
31+
echo "No GCM application files found."
32+
fi

0 commit comments

Comments
 (0)