github.com/yggdrasil-network/yggdrasil-go@v0.5.6/contrib/msi/build-msi.sh (about)

     1  #!/bin/sh
     2  
     3  # This script generates an MSI file for Yggdrasil for a given architecture. It
     4  # needs to run on Windows within MSYS2 and Go 1.21 or later must be installed on
     5  # the system and within the PATH. This is ran currently by GitHub Actions (see
     6  # the workflows in the repository).
     7  #
     8  # Author: Neil Alexander <neilalexander@users.noreply.github.com>
     9  
    10  # Get arch from command line if given
    11  PKGARCH=$1
    12  if [ "${PKGARCH}" == "" ];
    13  then
    14    echo "tell me the architecture: x86, x64, arm or arm64"
    15    exit 1
    16  fi
    17  
    18  # Download the wix tools!
    19  dotnet tool install --global wix --version 5.0.0
    20  
    21  # Build Yggdrasil!
    22  [ "${PKGARCH}" == "x64" ] && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./build
    23  [ "${PKGARCH}" == "x86" ] && GOOS=windows GOARCH=386 CGO_ENABLED=0 ./build
    24  [ "${PKGARCH}" == "arm" ] && GOOS=windows GOARCH=arm CGO_ENABLED=0 ./build
    25  [ "${PKGARCH}" == "arm64" ] && GOOS=windows GOARCH=arm64 CGO_ENABLED=0 ./build
    26  
    27  # Create the postinstall script
    28  cat > updateconfig.bat << EOF
    29  if not exist %ALLUSERSPROFILE%\\Yggdrasil (
    30    mkdir %ALLUSERSPROFILE%\\Yggdrasil
    31  )
    32  if not exist %ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf (
    33    if exist yggdrasil.exe (
    34      yggdrasil.exe -genconf > %ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf
    35    )
    36  )
    37  EOF
    38  
    39  # Work out metadata for the package info
    40  PKGNAME=$(sh contrib/semver/name.sh)
    41  PKGVERSION=$(sh contrib/msi/msversion.sh --bare)
    42  PKGVERSIONMS=$(echo $PKGVERSION | tr - .)
    43  ([ "${PKGARCH}" == "x64" ] || [ "${PKGARCH}" == "arm64" ]) && \
    44    PKGGUID="77757838-1a23-40a5-a720-c3b43e0260cc" PKGINSTFOLDER="ProgramFiles64Folder" || \
    45    PKGGUID="54a3294e-a441-4322-aefb-3bb40dd022bb" PKGINSTFOLDER="ProgramFilesFolder"
    46  
    47  # Download the Wintun driver
    48  if [ ! -d wintun ];
    49  then
    50    curl -o wintun.zip https://www.wintun.net/builds/wintun-0.14.1.zip
    51    if [ `sha256sum wintun.zip | cut -f 1 -d " "` != "07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51" ];
    52    then
    53      echo "wintun package didn't match expected checksum"
    54      exit 1
    55    fi
    56    unzip wintun.zip
    57  fi
    58  if [ $PKGARCH = "x64" ]; then
    59    PKGWINTUNDLL=wintun/bin/amd64/wintun.dll
    60  elif [ $PKGARCH = "x86" ]; then
    61    PKGWINTUNDLL=wintun/bin/x86/wintun.dll
    62  elif [ $PKGARCH = "arm" ]; then
    63    PKGWINTUNDLL=wintun/bin/arm/wintun.dll
    64  elif [ $PKGARCH = "arm64" ]; then
    65    PKGWINTUNDLL=wintun/bin/arm64/wintun.dll
    66  else
    67    echo "wasn't sure which architecture to get wintun for"
    68    exit 1
    69  fi
    70  
    71  if [ $PKGNAME != "master" ]; then
    72    PKGDISPLAYNAME="Yggdrasil Network (${PKGNAME} branch)"
    73  else
    74    PKGDISPLAYNAME="Yggdrasil Network"
    75  fi
    76  
    77  # Generate the wix.xml file
    78  cat > wix.xml << EOF
    79  <?xml version="1.0" encoding="windows-1252"?>
    80  <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    81    <Product
    82      Name="${PKGDISPLAYNAME}"
    83      Id="*"
    84      UpgradeCode="${PKGGUID}"
    85      Language="1033"
    86      Codepage="1252"
    87      Version="${PKGVERSIONMS}"
    88      Manufacturer="github.com/yggdrasil-network">
    89  
    90      <Package
    91        Id="*"
    92        Keywords="Installer"
    93        Description="Yggdrasil Network Installer"
    94        Comments="Yggdrasil Network standalone router for Windows."
    95        Manufacturer="github.com/yggdrasil-network"
    96        InstallerVersion="500"
    97        InstallScope="perMachine"
    98        Languages="1033"
    99        Compressed="yes"
   100        SummaryCodepage="1252" />
   101  
   102      <MajorUpgrade
   103        AllowDowngrades="yes" />
   104  
   105      <Media
   106        Id="1"
   107        Cabinet="Media.cab"
   108        EmbedCab="yes"
   109        CompressionLevel="high" />
   110  
   111      <Directory Id="TARGETDIR" Name="SourceDir">
   112        <Directory Id="${PKGINSTFOLDER}" Name="PFiles">
   113          <Directory Id="YggdrasilInstallFolder" Name="Yggdrasil">
   114  
   115            <Component Id="MainExecutable" Guid="c2119231-2aa3-4962-867a-9759c87beb24">
   116              <File
   117                Id="Yggdrasil"
   118                Name="yggdrasil.exe"
   119                DiskId="1"
   120                Source="yggdrasil.exe"
   121                KeyPath="yes" />
   122  
   123              <File
   124                Id="Wintun"
   125                Name="wintun.dll"
   126                DiskId="1"
   127                Source="${PKGWINTUNDLL}" />
   128  
   129              <ServiceInstall
   130                Id="ServiceInstaller"
   131                Account="LocalSystem"
   132                Description="Yggdrasil Network router process"
   133                DisplayName="Yggdrasil Service"
   134                ErrorControl="normal"
   135                LoadOrderGroup="NetworkProvider"
   136                Name="Yggdrasil"
   137                Start="auto"
   138                Type="ownProcess"
   139                Arguments='-useconffile "%ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf" -logto "%ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.log"'
   140                Vital="yes" />
   141  
   142              <ServiceControl
   143                Id="ServiceControl"
   144                Name="yggdrasil"
   145                Start="install"
   146                Stop="both"
   147                Remove="uninstall" />
   148            </Component>
   149  
   150            <Component Id="CtrlExecutable" Guid="a916b730-974d-42a1-b687-d9d504cbb86a">
   151              <File
   152                Id="Yggdrasilctl"
   153                Name="yggdrasilctl.exe"
   154                DiskId="1"
   155                Source="yggdrasilctl.exe"
   156                KeyPath="yes"/>
   157            </Component>
   158  
   159            <Component Id="ConfigScript" Guid="64a3733b-c98a-4732-85f3-20cd7da1a785">
   160              <File
   161                Id="Configbat"
   162                Name="updateconfig.bat"
   163                DiskId="1"
   164                Source="updateconfig.bat"
   165                KeyPath="yes"/>
   166            </Component>
   167          </Directory>
   168        </Directory>
   169      </Directory>
   170  
   171      <Feature Id="YggdrasilFeature" Title="Yggdrasil" Level="1">
   172        <ComponentRef Id="MainExecutable" />
   173        <ComponentRef Id="CtrlExecutable" />
   174        <ComponentRef Id="ConfigScript" />
   175      </Feature>
   176  
   177      <CustomAction
   178        Id="UpdateGenerateConfig"
   179        Directory="YggdrasilInstallFolder"
   180        ExeCommand="cmd.exe /c updateconfig.bat"
   181        Execute="deferred"
   182        Return="check"
   183        Impersonate="yes" />
   184  
   185      <InstallExecuteSequence>
   186        <Custom
   187          Action="UpdateGenerateConfig"
   188          Before="StartServices">
   189            NOT Installed AND NOT REMOVE
   190        </Custom>
   191      </InstallExecuteSequence>
   192  
   193    </Product>
   194  </Wix>
   195  EOF
   196  
   197  # Generate the MSI
   198  CANDLEFLAGS="-nologo"
   199  LIGHTFLAGS="-nologo -spdb -sice:ICE71 -sice:ICE61"
   200  candle $CANDLEFLAGS -out ${PKGNAME}-${PKGVERSION}-${PKGARCH}.wixobj -arch ${PKGARCH} wix.xml && \
   201  light $LIGHTFLAGS -ext WixUtilExtension.dll -out ${PKGNAME}-${PKGVERSION}-${PKGARCH}.msi ${PKGNAME}-${PKGVERSION}-${PKGARCH}.wixobj