2023-02-24 14:19:13 -08:00
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
2023-02-24 13:22:21 -08:00
// The dist command builds Tailscale release packages for distribution.
package main
import (
2025-04-15 11:50:39 -05:00
"cmp"
2023-02-24 13:22:21 -08:00
"context"
"errors"
"flag"
"log"
"os"
2025-04-15 11:50:39 -05:00
"slices"
2023-02-24 13:22:21 -08:00
"tailscale.com/release/dist"
2023-02-24 14:15:35 -08:00
"tailscale.com/release/dist/cli"
2024-04-22 16:42:01 -04:00
"tailscale.com/release/dist/qnap"
2023-05-26 12:42:05 -07:00
"tailscale.com/release/dist/synology"
2023-02-24 13:22:21 -08:00
"tailscale.com/release/dist/unixpkgs"
)
2024-04-22 16:42:01 -04:00
var (
2025-04-15 11:50:39 -05:00
synologyPackageCenter bool
gcloudCredentialsBase64 string
gcloudProject string
gcloudKeyring string
qnapKeyName string
qnapCertificateBase64 string
2024-04-22 16:42:01 -04:00
)
2023-05-26 12:42:05 -07:00
2023-08-24 15:36:47 -06:00
func getTargets ( ) ( [ ] dist . Target , error ) {
2023-05-26 12:42:05 -07:00
var ret [ ] dist . Target
2023-08-24 15:36:47 -06:00
ret = append ( ret , unixpkgs . Targets ( unixpkgs . Signers { } ) ... )
2023-05-26 12:42:05 -07:00
// Synology packages can be built either for sideloading, or for
// distribution by Synology in their package center. When
// distributed through the package center, apps can request
// additional permissions to use a tuntap interface and control
// the NAS's network stack, rather than be forced to run in
// userspace mode.
//
// Since only we can provide packages to Synology for
// distribution, we default to building the "sideload" variant of
// packages that we distribute on pkgs.tailscale.com.
2024-02-08 14:01:23 -05:00
//
// To build for package center, run
// ./tool/go run ./cmd/dist build --synology-package-center synology
2023-08-24 15:36:47 -06:00
ret = append ( ret , synology . Targets ( synologyPackageCenter , nil ) ... )
2025-04-15 11:50:39 -05:00
qnapSigningArgs := [ ] string { gcloudCredentialsBase64 , gcloudProject , gcloudKeyring , qnapKeyName , qnapCertificateBase64 }
if cmp . Or ( qnapSigningArgs ... ) != "" && slices . Contains ( qnapSigningArgs , "" ) {
return nil , errors . New ( "all of --gcloud-credentials, --gcloud-project, --gcloud-keyring, --qnap-key-name and --qnap-certificate must be set" )
2024-04-22 16:42:01 -04:00
}
2025-04-15 11:50:39 -05:00
ret = append ( ret , qnap . Targets ( gcloudCredentialsBase64 , gcloudProject , gcloudKeyring , qnapKeyName , qnapCertificateBase64 ) ... )
2023-05-26 12:42:05 -07:00
return ret , nil
2023-02-24 13:22:21 -08:00
}
2023-02-24 14:15:35 -08:00
func main ( ) {
cmd := cli . CLI ( getTargets )
2023-05-26 12:42:05 -07:00
for _ , subcmd := range cmd . Subcommands {
if subcmd . Name == "build" {
subcmd . FlagSet . BoolVar ( & synologyPackageCenter , "synology-package-center" , false , "build synology packages with extra metadata for the official package center" )
2025-04-15 11:50:39 -05:00
subcmd . FlagSet . StringVar ( & gcloudCredentialsBase64 , "gcloud-credentials" , "" , "base64 encoded GCP credentials (used when signing QNAP builds)" )
subcmd . FlagSet . StringVar ( & gcloudProject , "gcloud-project" , "" , "name of project in GCP KMS (used when signing QNAP builds)" )
subcmd . FlagSet . StringVar ( & gcloudKeyring , "gcloud-keyring" , "" , "path to keyring in GCP KMS (used when signing QNAP builds)" )
subcmd . FlagSet . StringVar ( & qnapKeyName , "qnap-key-name" , "" , "name of GCP key to use when signing QNAP builds" )
subcmd . FlagSet . StringVar ( & qnapCertificateBase64 , "qnap-certificate" , "" , "base64 encoded certificate to use when signing QNAP builds" )
2023-05-26 12:42:05 -07:00
}
}
2023-02-24 14:15:35 -08:00
if err := cmd . ParseAndRun ( context . Background ( ) , os . Args [ 1 : ] ) ; err != nil && ! errors . Is ( err , flag . ErrHelp ) {
log . Fatal ( err )
2023-02-24 13:22:21 -08:00
}
}