github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/builders/dmg/entrypoint.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  # Setup PGP
     6  echo "${PGP_KEY_PASSWORD}" | base64 -d >'/tmp/pgp-pass'
     7  mkdir -p "${HOME}/.gnupg"
     8  cat >"${HOME}/.gnupg/gpg.conf" <<EOT
     9  yes
    10  passphrase-file /tmp/pgp-pass
    11  pinentry-mode loopback
    12  EOT
    13  
    14  echo "${PGP_KEY}" | base64 -d >'/tmp/private.pgp'
    15  gpg --import /tmp/private.pgp
    16  
    17  # Prepare build environment
    18  export BASEDIR="${PWD}/${GOMAIN}"
    19  
    20  # Configure Go
    21  export GOPROXY='https://proxy.golang.org,direct'
    22  
    23  # Generate dependencies
    24  GOFLAGS="${GOFLAGS}" sh -c "${GOGENERATE}"
    25  
    26  # Create icons
    27  mkdir -p '/tmp/out'
    28  cp "${BASEDIR}/icon.icns" '/tmp/out/icon.icns'
    29  
    30  # Build app
    31  export GOOS="darwin"
    32  export BINARIES=""
    33  for ARCH in ${ARCHITECTURES}; do
    34    export GOARCH="${ARCH}"
    35  
    36    # See https://github.com/pojntfx/bagop/blob/main/main.go#L45
    37    export DEBARCH="${GOARCH}"
    38    export MACPORTS_ARGS=""
    39    if [ "${ARCH}" = "386" ]; then
    40      export DEBARCH="i686"
    41    elif [ "${ARCH}" = "amd64" ]; then
    42      export DEBARCH="x86_64"
    43    elif [ "${ARCH}" = "arm" ]; then
    44      export DEBARCH="armv7l"
    45    elif [ "${ARCH}" = "arm64" ]; then
    46      export MACPORTS_ARGS="--arm64"
    47      export DEBARCH="aarch64"
    48    fi
    49  
    50    export CC="$(find /osxcross/bin/${DEBARCH}-apple-darwin*-cc)"
    51    export CXX="$(find /osxcross/bin/${DEBARCH}-apple-darwin*-c++)"
    52    export PKGCONFIG="$(find /osxcross/bin/${DEBARCH}-apple-darwin*-pkg-config)"
    53    export PKG_CONFIG="$(find /osxcross/bin/${DEBARCH}-apple-darwin*-pkg-config)"
    54  
    55    # Install MacPorts packages
    56    if [ "${MACPORTS}" != "" ]; then
    57      rm -rf /osxcross/macports/pkgs/
    58      osxcross-macports install ${MACPORTS_ARGS} --static ${MACPORTS}
    59    fi
    60  
    61    go build -ldflags="-X github.com/pojntfx/hydrapp/hydrapp/pkg/update.BranchTimestampRFC3339=${BRANCH_TIMESTAMP_RFC3339} -X github.com/pojntfx/hydrapp/hydrapp/pkg/update.BranchID=${BRANCH_ID} -X github.com/pojntfx/hydrapp/hydrapp/pkg/update.PackageType=dmg" -o "/tmp/${APP_ID}.${GOOS}-${DEBARCH}" "${GOMAIN}"
    62  
    63    export BINARIES="${BINARIES} /tmp/${APP_ID}.${GOOS}-${DEBARCH}"
    64  done
    65  
    66  lipo -create -output "/tmp/out/${APP_ID}.${GOOS}" ${BINARIES}
    67  
    68  cp "${BASEDIR}/Info.plist" '/tmp/out/'
    69  
    70  mkdir -p "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt/${APP_NAME}.app/Contents/"{MacOS,Resources}
    71  cp "/tmp/out/${APP_ID}.${GOOS}" "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt/${APP_NAME}.app/Contents/MacOS/${APP_ID}"
    72  cp '/tmp/out/Info.plist' "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt/${APP_NAME}.app/Contents"
    73  cp '/tmp/out/icon.icns' "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt/${APP_NAME}.app/Contents/Resources"
    74  rcodesign sign "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt/${APP_NAME}.app"
    75  
    76  genisoimage -V "Install $(echo ${APP_NAME} | cut -c -24)" -D -R -apple -no-pad -o "/tmp/out/${APP_ID}.${GOOS}-uncompressed.dmg" "/tmp/out/${APP_ID}.${GOOS}.dmg.mnt"
    77  dmg "/tmp/out/${APP_ID}.${GOOS}-uncompressed.dmg" "/tmp/out/${APP_ID}.${GOOS}.dmg"
    78  rcodesign sign "/tmp/out/${APP_ID}.${GOOS}.dmg"
    79  gpg --detach-sign --armor "/tmp/out/${APP_ID}.${GOOS}.dmg"
    80  
    81  cp "/tmp/out/${APP_ID}.${GOOS}.dmg" "/tmp/out/${APP_ID}.${GOOS}.dmg.asc" "/hydrapp/dst"
    82  
    83  cd /hydrapp/dst
    84  
    85  gpg --output "repo.asc" --armor --export
    86  tree -J . -I 'index.html|index.json' | jq '.[0].contents' | jq ". |= map( . + {time: \"${BRANCH_TIMESTAMP_RFC3339}\"} )" | tee 'index.json'
    87  
    88  if [ "${DST_UID}" != "" ] && [ "${DST_GID}" != "" ]; then
    89    chown -R "${DST_UID}:${DST_GID}" /hydrapp/dst
    90  fi