github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/builders/msi/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  # Re-initialize WINE at runtime
    18  rm -rf /root/.wine
    19  wine64 cmd.exe /c dir
    20  mv /tmp/msys64 /root/.wine/drive_c/msys64
    21  mkdir -p '/root/.wine/drive_c/go' '/root/.wine/drive_c/tmp' '/root/.wine/drive_c/users/root/Documents/go-workspace'
    22  
    23  # Prepare build environment
    24  export BASEDIR="${PWD}/${GOMAIN}"
    25  
    26  # Configure Go
    27  export GOPROXY='https://proxy.golang.org,direct'
    28  
    29  # Install MSYS2 packages
    30  if [ "${MSYS2PACKAGES}" != "" ]; then
    31    wine64 bash.exe -c "pacman --noconfirm --ignore pacman --needed -S ${MSYS2PACKAGES}"
    32  fi
    33  
    34  # Generate dependencies
    35  GOFLAGS="${GOFLAGS}" sh -c "${GOGENERATE}"
    36  
    37  # Create icons
    38  mkdir -p '/tmp/out'
    39  cp "${BASEDIR}/icon.ico" '/tmp/out/icon.ico'
    40  
    41  # Build app
    42  export GOOS="windows"
    43  export GOARCH="${ARCHITECTURE}"
    44  
    45  # See https://github.com/pojntfx/bagop/blob/main/main.go#L45
    46  export DEBARCH="${GOARCH}"
    47  if [ "${ARCHITECTURE}" = "386" ]; then
    48    export DEBARCH="i686"
    49  elif [ "${ARCHITECTURE}" = "amd64" ]; then
    50    export DEBARCH="x86_64"
    51  elif [ "${ARCHITECTURE}" = "arm" ]; then
    52    export DEBARCH="armv7l"
    53  elif [ "${ARCHITECTURE}" = "arm64" ]; then
    54    export DEBARCH="aarch64"
    55  fi
    56  
    57  if [ "${ARCHITECTURE}" = "amd64" ]; then
    58    GOPATH='/root/.wine/drive_c/go' go mod download -x
    59  
    60    cp -r . '/root/.wine/drive_c/users/root/Documents/go-workspace'
    61    rm -rf '/root/.wine/drive_c/users/root/Documents/go-workspace/out'
    62  
    63    wine64 bash.exe -c "export PATH=$PATH:/ucrt64/bin:/msys64/usr/bin GOPATH=/c/go GOROOT=/ucrt64/lib/go TMP=/c/tmp TEMP=/c/tmp GOARCH=amd64 CGO_ENABLED=1 GOPROXY='https://proxy.golang.org,direct' GOFLAGS=${GOFLAGS} && cd /c/users/root/Documents/go-workspace && git config --add safe.directory '*' && go build -ldflags='-linkmode=external -H=windowsgui -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=msi' -x -v -o out/${APP_ID}.${GOOS}-${DEBARCH}.exe ${GOMAIN}"
    64  
    65    # Copy binaries to staging directory
    66    yes | cp -rf /root/.wine/drive_c/users/root/Documents/go-workspace/out/* '/tmp/out'
    67  
    68    find /root/.wine/drive_c/msys64/ucrt64/ -regex "${MSYS2INCLUDE}" -print0 | tar -c --null --files-from - | tar -C '/tmp/out' -x --strip-components=5
    69  else
    70    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=msi" -o "/tmp/out/${APP_ID}.${GOOS}-${DEBARCH}.exe" "${GOMAIN}"
    71  fi
    72  
    73  cd '/tmp/out'
    74  
    75  # Create and analyze files to include in the installer
    76  find . -type f | wixl-heat -p ./ --directory-ref INSTALLDIR --component-group ApplicationContent --var 'var.SourceDir' >/tmp/hydrapp.wxi
    77  
    78  xmllint --xpath "//*[local-name()='DirectoryRef']" /tmp/hydrapp.wxi >/tmp/hydrapp-directories.xml
    79  xmllint --xpath "//*[local-name()='ComponentRef']" /tmp/hydrapp.wxi >/tmp/hydrapp-component-refs.xml
    80  
    81  export STARTID="$(cat /tmp/hydrapp.wxi | grep ${APP_ID}.${GOOS}-${DEBARCH}.exe | xmllint --xpath 'string(//File/@Id)' -)"
    82  
    83  # Build WiX installer
    84  wixl -v -D SourceDir="." -v -o "/hydrapp/dst/${APP_ID}.${GOOS}-${DEBARCH}.msi" <(cat "${BASEDIR}/${APP_ID}.wxl" | perl -p -e 'use File::Slurp; my $text = read_file("/tmp/hydrapp-directories.xml"); s+<hydrappDirectories />+$text+g' | perl -p -e 'use File::Slurp; my $text = read_file("/tmp/hydrapp-component-refs.xml"); s+<hydrappComponentRefs />+$text+g' | perl -p -e 's+{ StartID }+$ENV{STARTID}+g')
    85  
    86  gpg --detach-sign --armor "/hydrapp/dst/${APP_ID}.${GOOS}-${DEBARCH}.msi"
    87  
    88  cd /hydrapp/dst
    89  
    90  gpg --output "repo.asc" --armor --export
    91  tree -J . -I 'index.html|index.json' | jq '.[0].contents' | jq ". |= map( . + {time: \"${BRANCH_TIMESTAMP_RFC3339}\"} )" | tee 'index.json'
    92  
    93  if [ "${DST_UID}" != "" ] && [ "${DST_GID}" != "" ]; then
    94    chown -R "${DST_UID}:${DST_GID}" /hydrapp/dst
    95  fi