Merge #10777: [tests] Avoid redundant assignments. Remove unused variables
[bitcoinplatinum.git] / contrib / macdeploy / detached-sig-apply.sh
blob91674a92e6fa6196c0190b6bf42fcdf32cf7d42f
1 #!/bin/sh
2 # Copyright (c) 2014-2015 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 set -e
8 UNSIGNED="$1"
9 SIGNATURE="$2"
10 ARCH=x86_64
11 ROOTDIR=dist
12 TEMPDIR=signed.temp
13 OUTDIR=signed-app
15 if [ -z "$UNSIGNED" ]; then
16 echo "usage: $0 <unsigned app> <signature>"
17 exit 1
20 if [ -z "$SIGNATURE" ]; then
21 echo "usage: $0 <unsigned app> <signature>"
22 exit 1
25 rm -rf ${TEMPDIR} && mkdir -p ${TEMPDIR}
26 tar -C ${TEMPDIR} -xf ${UNSIGNED}
27 cp -rf "${SIGNATURE}"/* ${TEMPDIR}
29 if [ -z "${PAGESTUFF}" ]; then
30 PAGESTUFF=${TEMPDIR}/pagestuff
33 if [ -z "${CODESIGN_ALLOCATE}" ]; then
34 CODESIGN_ALLOCATE=${TEMPDIR}/codesign_allocate
37 find ${TEMPDIR} -name "*.sign" | while read i; do
38 SIZE=`stat -c %s "${i}"`
39 TARGET_FILE="`echo "${i}" | sed 's/\.sign$//'`"
41 echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
42 ${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
44 OFFSET=`${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'`
45 if [ -z ${QUIET} ]; then
46 echo "Attaching signature at offset ${OFFSET}"
49 dd if="$i" of="${i}.tmp" bs=1 seek=${OFFSET} count=${SIZE} 2>/dev/null
50 mv "${i}.tmp" "${TARGET_FILE}"
51 rm "${i}"
52 echo "Success."
53 done
54 mv ${TEMPDIR}/${ROOTDIR} ${OUTDIR}
55 rm -rf ${TEMPDIR}
56 echo "Signed: ${OUTDIR}"