Skip to content

Commit 824ba03

Browse files
authored
Merge pull request #64 from czipperz/quote-bash-variables
Quote bash variables in installation scripts
2 parents 4659c50 + 53e73f2 commit 824ba03

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

src/osx/Installer.Mac/build.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ echo "Building Installer.Mac..."
88

99
# Directories
1010
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
11-
ROOT="$( cd $THISDIR/../../.. ; pwd -P )"
12-
SRC=$ROOT/src
13-
OUT=$ROOT/out
14-
INSTALLER_SRC=$SRC/osx/Installer.Mac
15-
INSTALLER_OUT=$OUT/osx/Installer.Mac
11+
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
12+
SRC="$ROOT/src"
13+
OUT="$ROOT/out"
14+
INSTALLER_SRC="$SRC/osx/Installer.Mac"
15+
INSTALLER_OUT="$OUT/osx/Installer.Mac"
1616

1717
# Parse script arguments
1818
for i in "$@"
1919
do
20-
case $i in
20+
case "$i" in
2121
--configuration=*)
2222
CONFIGURATION="${i#*=}"
2323
shift # past argument=value
@@ -33,16 +33,16 @@ esac
3333
done
3434

3535
# Perform pre-execution checks
36-
CONFIGURATION=${CONFIGURATION:=Debug}
36+
CONFIGURATION="${CONFIGURATION:=Debug}"
3737
if [ -z "$VERSION" ]; then
3838
die "--version was not set"
3939
fi
4040

41-
PAYLOAD=$INSTALLER_OUT/pkg/$CONFIGURATION/payload
42-
PKGOUT=$INSTALLER_OUT/pkg/$CONFIGURATION/gcmcore-osx-$VERSION.pkg
41+
PAYLOAD="$INSTALLER_OUT/pkg/$CONFIGURATION/payload"
42+
PKGOUT="$INSTALLER_OUT/pkg/$CONFIGURATION/gcmcore-osx-$VERSION.pkg"
4343

4444
# Layout and pack
45-
$INSTALLER_SRC/layout.sh --configuration=$CONFIGURATION --output=$PAYLOAD || exit 1
46-
$INSTALLER_SRC/pack.sh --payload=$PAYLOAD --version=$VERSION --output=$PKGOUT || exit 1
45+
"$INSTALLER_SRC/layout.sh" --configuration="$CONFIGURATION" --output="$PAYLOAD" || exit 1
46+
"$INSTALLER_SRC/pack.sh" --payload="$PAYLOAD" --version="$VERSION" --output="$PKGOUT" || exit 1
4747

4848
echo "Build of Installer.Mac complete."

src/osx/Installer.Mac/layout.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ make_absolute () {
1616

1717
# Directories
1818
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
19-
ROOT="$( cd $THISDIR/../../.. ; pwd -P )"
20-
SRC=$ROOT/src
21-
OUT=$ROOT/out
22-
INSTALLER_SRC=$SRC/osx/Installer.Mac
23-
MSAUTH_OUT=$OUT/osx/Microsoft.Authentication.Helper.Mac
24-
GCM_SRC=$SRC/shared/Git-Credential-Manager
19+
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
20+
SRC="$ROOT/src"
21+
OUT="$ROOT/out"
22+
INSTALLER_SRC="$SRC/osx/Installer.Mac"
23+
MSAUTH_OUT="$OUT/osx/Microsoft.Authentication.Helper.Mac"
24+
GCM_SRC="$SRC/shared/Git-Credential-Manager"
2525

2626
# Build parameters
2727
FRAMEWORK=netcoreapp2.1
@@ -30,7 +30,7 @@ RUNTIME=osx-x64
3030
# Parse script arguments
3131
for i in "$@"
3232
do
33-
case $i in
33+
case "$i" in
3434
--configuration=*)
3535
CONFIGURATION="${i#*=}"
3636
shift # past argument=value
@@ -49,53 +49,53 @@ esac
4949
done
5050

5151
# Perform pre-execution checks
52-
CONFIGURATION=${CONFIGURATION:=Debug}
52+
CONFIGURATION="${CONFIGURATION:=Debug}"
5353
if [ -z "$PAYLOAD" ]; then
5454
die "--output was not set"
5555
fi
5656
if [ -z "$SYMBOLOUT" ]; then
5757
SYMBOLOUT="$PAYLOAD.sym"
5858
fi
5959

60-
MSAUTH_BIN=$MSAUTH_OUT/bin/$CONFIGURATION/native
61-
MSAUTH_SYM=$MSAUTH_OUT/bin/$CONFIGURATION/native.sym
62-
if [ ! -d $MSAUTH_BIN ]; then
60+
MSAUTH_BIN="$MSAUTH_OUT/bin/$CONFIGURATION/native"
61+
MSAUTH_SYM="$MSAUTH_OUT/bin/$CONFIGURATION/native.sym"
62+
if [ ! -d "$MSAUTH_BIN" ]; then
6363
die "No native helper binaries found. Did you build?"
6464
fi
6565

6666
# Cleanup any old payload directory
67-
if [ -d $PAYLOAD ]; then
67+
if [ -d "$PAYLOAD" ]; then
6868
echo "Cleaning old payload directory '$PAYLOAD'..."
69-
rm -rf $PAYLOAD
69+
rm -rf "$PAYLOAD"
7070
fi
7171

7272
# Ensure payload and symbol directories exists
73-
mkdir -p $PAYLOAD $SYMBOLOUT
73+
mkdir -p "$PAYLOAD" "$SYMBOLOUT"
7474

7575
# Copy uninstaller script
7676
echo "Copying uninstall script..."
77-
cp $INSTALLER_SRC/uninstall.sh $PAYLOAD || exit 1
77+
cp "$INSTALLER_SRC/uninstall.sh" "$PAYLOAD" || exit 1
7878

7979
# Copy native authentication helper executables
8080
echo "Copying native helpers..."
81-
cp -R $MSAUTH_BIN/ $PAYLOAD || exit 1
81+
cp -R "$MSAUTH_BIN/" "$PAYLOAD" || exit 1
8282

8383
# Publish core application executables
8484
echo "Publishing core application..."
85-
dotnet publish $GCM_SRC \
86-
--configuration=$CONFIGURATION \
87-
--framework=$FRAMEWORK \
88-
--runtime=$RUNTIME \
89-
--output=$(make_absolute $PAYLOAD) || exit 1
85+
dotnet publish "$GCM_SRC" \
86+
--configuration="$CONFIGURATION" \
87+
--framework="$FRAMEWORK" \
88+
--runtime="$RUNTIME" \
89+
--output="$(make_absolute "$PAYLOAD")" || exit 1
9090

9191
# Collect symbols
9292
echo "Collecting managed symbols..."
93-
mv $PAYLOAD/*.pdb $SYMBOLOUT || exit 1
93+
mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1
9494
echo "Collecting native symbols..."
95-
cp -R $MSAUTH_SYM/ $SYMBOLOUT || exit 1
95+
cp -R "$MSAUTH_SYM/" "$SYMBOLOUT" || exit 1
9696

9797
# Remove any unwanted .DS_Store files
9898
echo "Removing unnecessary files..."
99-
find $PAYLOAD -name '*.DS_Store' -type f -delete || exit 1
99+
find "$PAYLOAD" -name '*.DS_Store' -type f -delete || exit 1
100100

101101
echo "Layout complete."

src/osx/Installer.Mac/pack.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ die () {
66

77
# Directories
88
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
9-
ROOT="$( cd $THISDIR/../../.. ; pwd -P )"
10-
SRC=$ROOT/src
11-
OUT=$ROOT/out
12-
INSTALLER_SRC=$SRC/osx/Installer.Mac
9+
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
10+
SRC="$ROOT/src"
11+
OUT="$ROOT/out"
12+
INSTALLER_SRC="$SRC/osx/Installer.Mac"
1313

1414
# Product information
1515
IDENTIFIER="com.microsoft.GitCredentialManager"
@@ -18,7 +18,7 @@ INSTALL_LOCATION="/usr/local/share/gcm-core"
1818
# Parse script arguments
1919
for i in "$@"
2020
do
21-
case $i in
21+
case "$i" in
2222
--version=*)
2323
VERSION="${i#*=}"
2424
shift # past argument=value
@@ -43,29 +43,29 @@ if [ -z "$VERSION" ]; then
4343
fi
4444
if [ -z "$PAYLOAD" ]; then
4545
die "--payload was not set"
46-
elif [ ! -d $PAYLOAD ]; then
46+
elif [ ! -d "$PAYLOAD" ]; then
4747
die "Could not find '$PAYLOAD'. Did you run layout.sh first?"
4848
fi
4949
if [ -z "$PKGOUT" ]; then
5050
die "--output was not set"
5151
fi
5252

5353
# Cleanup any old package file
54-
if [ -e $PKGOUT ]; then
54+
if [ -e "$PKGOUT" ]; then
5555
echo "Deleteing old package '$PKGOUT'..."
56-
rm $PKGOUT
56+
rm "$PKGOUT"
5757
fi
5858

5959
# Ensure the parent directory for the package exists
60-
mkdir -p $(dirname "$PKGOUT")
60+
mkdir -p "$(dirname "$PKGOUT")"
6161

6262
# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
6363
echo "Setting file permissions..."
64-
/bin/chmod -R 755 $PAYLOAD || exit 1
64+
/bin/chmod -R 755 "$PAYLOAD" || exit 1
6565

6666
# Remove any extended attributes (ACEs)
6767
echo "Removing extended attributes..."
68-
/usr/bin/xattr -rc $PAYLOAD || exit 1
68+
/usr/bin/xattr -rc "$PAYLOAD" || exit 1
6969

7070
# Build installer package
7171
echo "Building installer package..."

src/osx/Installer.Mac/scripts/postinstall

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function IsBrewPkgInstalled
88
if [ $? -eq 0 ]
99
then
1010
# Check if the package has been installed
11-
brew ls --versions $1 > /dev/null
11+
brew ls --versions "$1" > /dev/null
1212
if [ $? -eq 0 ]
1313
then
1414
return 0
@@ -27,7 +27,7 @@ fi
2727
/bin/ln -Fs /usr/local/share/gcm-core/git-credential-manager /usr/local/bin/git-credential-manager
2828

2929
# Set system gitconfig for the current user
30-
USER_ID=`id -u "${USER}"`
30+
USER_ID="$(id -u "${USER}")"
3131
if [ "${COMMAND_LINE_INSTALL}" = "" ]
3232
then
3333
/bin/launchctl asuser "${USER_ID}" "${PWD}/configure-git.sh"

src/osx/Installer.Mac/uninstall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
# Unconfigure GCM
4-
HELPER=`git config --system credential.helper`
5-
if [ $HELPER = "/usr/local/share/gcm-core/git-credential-manager" ]
4+
HELPER="$(git config --system credential.helper)"
5+
if [ "$HELPER" = "/usr/local/share/gcm-core/git-credential-manager" ]
66
then
77
echo "Resetting credential helper to 'osxkeychain'..."
88
sudo git config --system credential.helper osxkeychain

0 commit comments

Comments
 (0)