all: sync with master
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/netip"
|
||||
"os"
|
||||
"slices"
|
||||
@@ -14,7 +16,7 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/next/configmgr"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/osutil"
|
||||
)
|
||||
|
||||
// options contains all command-line options for the AdGuardHome(.exe) binary.
|
||||
@@ -87,6 +89,12 @@ type options struct {
|
||||
// TODO(a.garipov): Use.
|
||||
performUpdate bool
|
||||
|
||||
// noPermCheck, if true, instructs AdGuard Home to skip checking and
|
||||
// migrating the permissions of its security-sensitive files.
|
||||
//
|
||||
// TODO(e.burkov): Use.
|
||||
noPermCheck bool
|
||||
|
||||
// verbose, if true, instructs AdGuard Home to enable verbose logging.
|
||||
verbose bool
|
||||
|
||||
@@ -108,7 +116,8 @@ const (
|
||||
disableUpdateIdx
|
||||
glinetModeIdx
|
||||
helpIdx
|
||||
localFrontend
|
||||
localFrontendIdx
|
||||
noPermCheckIdx
|
||||
performUpdateIdx
|
||||
verboseIdx
|
||||
versionIdx
|
||||
@@ -212,7 +221,7 @@ var commandLineOptions = []*commandLineOption{
|
||||
valueType: "",
|
||||
},
|
||||
|
||||
localFrontend: {
|
||||
localFrontendIdx: {
|
||||
defaultValue: false,
|
||||
description: "Use local frontend directories.",
|
||||
long: "local-frontend",
|
||||
@@ -220,6 +229,14 @@ var commandLineOptions = []*commandLineOption{
|
||||
valueType: "",
|
||||
},
|
||||
|
||||
noPermCheckIdx: {
|
||||
defaultValue: false,
|
||||
description: "Skip checking the permissions of security-sensitive files.",
|
||||
long: "no-permcheck",
|
||||
short: "",
|
||||
valueType: "",
|
||||
},
|
||||
|
||||
performUpdateIdx: {
|
||||
defaultValue: false,
|
||||
description: "Update the current binary and restart the service in case it's installed.",
|
||||
@@ -262,7 +279,8 @@ func parseOptions(cmdName string, args []string) (opts *options, err error) {
|
||||
disableUpdateIdx: &opts.disableUpdate,
|
||||
glinetModeIdx: &opts.glinetMode,
|
||||
helpIdx: &opts.help,
|
||||
localFrontend: &opts.localFrontend,
|
||||
localFrontendIdx: &opts.localFrontend,
|
||||
noPermCheckIdx: &opts.noPermCheck,
|
||||
performUpdateIdx: &opts.performUpdate,
|
||||
verboseIdx: &opts.verbose,
|
||||
versionIdx: &opts.version,
|
||||
@@ -372,13 +390,13 @@ func processOptions(
|
||||
) (exitCode int, needExit bool) {
|
||||
if parseErr != nil {
|
||||
// Assume that usage has already been printed.
|
||||
return statusArgumentError, true
|
||||
return osutil.ExitCodeArgumentError, true
|
||||
}
|
||||
|
||||
if opts.help {
|
||||
usage(cmdName, os.Stdout)
|
||||
|
||||
return statusSuccess, true
|
||||
return osutil.ExitCodeSuccess, true
|
||||
}
|
||||
|
||||
if opts.version {
|
||||
@@ -388,7 +406,7 @@ func processOptions(
|
||||
fmt.Printf("AdGuard Home %s\n", version.Version())
|
||||
}
|
||||
|
||||
return statusSuccess, true
|
||||
return osutil.ExitCodeSuccess, true
|
||||
}
|
||||
|
||||
if opts.checkConfig {
|
||||
@@ -396,21 +414,26 @@ func processOptions(
|
||||
if err != nil {
|
||||
_, _ = io.WriteString(os.Stdout, err.Error()+"\n")
|
||||
|
||||
return statusError, true
|
||||
return osutil.ExitCodeFailure, true
|
||||
}
|
||||
|
||||
return statusSuccess, true
|
||||
return osutil.ExitCodeSuccess, true
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// frontendFromOpts returns the frontend to use based on the options.
|
||||
func frontendFromOpts(opts *options, embeddedFrontend fs.FS) (frontend fs.FS, err error) {
|
||||
func frontendFromOpts(
|
||||
ctx context.Context,
|
||||
logger *slog.Logger,
|
||||
opts *options,
|
||||
embeddedFrontend fs.FS,
|
||||
) (frontend fs.FS, err error) {
|
||||
const frontendSubdir = "build/static"
|
||||
|
||||
if opts.localFrontend {
|
||||
log.Info("warning: using local frontend files")
|
||||
logger.WarnContext(ctx, "using local frontend files")
|
||||
|
||||
return os.DirFS(frontendSubdir), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user