Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Build Script (Build Phases->Run Script) Increment Build Version based on Username(User)

When compiling a project, this script should increment the Build Version of the Xcode project by one, when the system username matches. Keep in mind that these are just Unix commands in a script (not Applescript, Python, or Perl) inside Target->Build Phases->Run Script in Xcode.

I've done "echo $USER" in terminal. This prints the username of the logged-in user just fine, and it's the same string I placed in the conditional statement in the second block of code.

The first block of code works. The second, which adds the conditional statement, does not.

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"


#!/bin/bash
username=$USER
if [ username == "erik" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi

Syntax concerns:
Parsing of $USER (case sensitive)
Semicolon right after closing bracket in if statement
Then statement on same line as if statement

like image 534
Glimpse Avatar asked Oct 17 '12 04:10

Glimpse


1 Answers

You can see the script log in the Log Navigator, with your script i've got the following issue:

enter image description here

I believe the default comparison is case sensitive, to make it not sensitive you can change the username to uppercase/lowercase before comparison:

if [ `echo $USER | tr [:lower:] [:upper:]` = "USERNAME" ]; then
echo "Got user check"
fi

As you can see I moved $USER to the condition to avoid additional var usage and the script failure.

And the semicolon at if-then block is a normal thing, check the man page. then word might be moved to the new line if that is more convenient for you to read.

like image 151
A-Live Avatar answered Sep 27 '22 19:09

A-Live