1#!/bin/bash
2
3set -ex
4
5TARGET="${1:?"no TARGET name given"}"
6VERSION="${2:?"no version given"}"
7INFO_PLIST_OUT_PATH="${3:?"no output directory given"}"
8COPY_CMD="${4:?"no copy command given"}"
9ICON_PATH="${5:?"no icon path given"}"
10ICON_OUT_DIR="${6:?"no destination icon path given"}"
11
12# Do NOT change this to gnused. The inplace options for bsdsed and gnused differ.
13SED="/usr/bin/sed"
14
15GIT_VER=""
16
17if [ "$(git rev-parse --is-inside-git-dir)" = "true" ] || [ "$(git rev-parse --is-inside-work-tree)" = "true" ]; then
18  GIT_SHA="$(git rev-parse --short=12 HEAD)"
19  GIT_DESCRIPTION="$(git describe)"
20
21  TMP_REGEX='^.+-[0-9]+-g[0-9A-Fa-f]+$'
22  if [[ "${GIT_DESCRIPTION}" =~ ${TMP_REGEX} ]]; then
23    GIT_VER=" git-${GIT_SHA} $(date +'%Y%m%d')"
24  fi
25fi
26
27# Substitute FULL_VERSION in Info.plist file.
28${SED} -i '' -e "s/@FULL_VERSION@/${VERSION}${GIT_VER}/g" -e "s/@TARGET@/${TARGET}/g" "${INFO_PLIST_OUT_PATH}"
29
30# Copy icon.
31${COPY_CMD} "${ICON_PATH}" "${ICON_OUT_DIR}"
32
33exit 0
34