diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 275ba9c0c..3c371254c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ on: pull_request: env: - SIGN_PIPE_VER: main + SIGN_PIPE_VER: "v0.0.3" jobs: release: @@ -131,7 +131,7 @@ jobs: uses: benc-uk/workflow-dispatch@v1 if: startsWith(github.ref, 'refs/tags/') with: - workflow: Sign darwin ui app + workflow: Sign darwin ui app with dispatch repo: netbirdio/sign-pipelines ref: ${{ env.SIGN_PIPE_VER }} token: ${{ secrets.SIGN_GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a0ddbb04e..36c72f38b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -147,6 +147,8 @@ nfpms: replaces: - wiretrustee + conflicts: + - wiretrustee scripts: postinstall: "release_files/post_install.sh" @@ -165,6 +167,9 @@ nfpms: replaces: - wiretrustee + conflicts: + - wiretrustee + scripts: postinstall: "release_files/post_install.sh" preremove: "release_files/pre_remove.sh" @@ -413,22 +418,25 @@ brews: homepage: https://netbird.io/ license: "BSD3" test: | - system "#{bin}/{{ .ProjectName }} -h" + system "#{bin}/{{ .ProjectName }} version" + conflicts: + - wiretrustee uploads: - name: debian ids: - - deb + - netbird-deb - netbird-ui-deb mode: archive target: https://pkgs.wiretrustee.com/debian/pool/{{ .ArtifactName }};deb.distribution=stable;deb.component=main;deb.architecture={{ if .Arm }}armhf{{ else }}{{ .Arch }}{{ end }};deb.package= username: dev@wiretrustee.com method: PUT + - name: yum ids: - - rpm + - netbird-rpm - netbird-ui-rpm mode: archive target: https://pkgs.wiretrustee.com/yum/{{ .Arch }}{{ if .Arm }}{{ .Arm }}{{ end }} username: dev@wiretrustee.com - method: PUT + method: PUT \ No newline at end of file diff --git a/README.md b/README.md index bb619d87e..16e66179e 100644 --- a/README.md +++ b/README.md @@ -137,16 +137,25 @@ Hosted version: sudo yum install netbird-ui ``` #### MACOS -**Brew install** -1. Download and install Brew at https://brew.sh/ -2. Install the client +**Homebrew install** +1. Download and install homebrew at https://brew.sh/ +2. If wiretrustee was previously installed with homebrew, you will need to run: +```shell +# Stop and uninstall daemon service: +sudo wiretrustee service stop +sudo wiretrustee service uninstall +# unlik the app +brew unlink wiretrustee +``` +> netbird will copy any existing configuration from the Wiretrustee's default configuration paths to the new Netbird's default location +3. Install the client ```shell # for CLI only brew install netbirdio/tap/netbird # for GUI package brew install --cask netbirdio/tap/netbird-ui ``` -3. As homebrew doesn't allow sudo exec, we need to install and start the client daemon: +4. If you are install CLI only, you need to install and start the client daemon service: ```shell sudo netbird service install sudo netbird service start diff --git a/client/cmd/down.go b/client/cmd/down.go index 97c484ee7..e0a9f5b2a 100644 --- a/client/cmd/down.go +++ b/client/cmd/down.go @@ -17,12 +17,9 @@ var downCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() - err := handleRebrand(cmd) - if err != nil { - return err - } + cmd.SetOut(cmd.OutOrStdout()) - err = util.InitLog(logLevel, "console") + err := util.InitLog(logLevel, "console") if err != nil { log.Errorf("failed initializing log %v", err) return err diff --git a/client/cmd/login.go b/client/cmd/login.go index e43c6a2ce..dbf778f89 100644 --- a/client/cmd/login.go +++ b/client/cmd/login.go @@ -22,12 +22,9 @@ var loginCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() - err := handleRebrand(cmd) - if err != nil { - return err - } + cmd.SetOut(cmd.OutOrStdout()) - err = util.InitLog(logLevel, "console") + err := util.InitLog(logLevel, "console") if err != nil { return fmt.Errorf("failed initializing log %v", err) } @@ -36,6 +33,11 @@ var loginCmd = &cobra.Command{ // workaround to run without service if logFile == "console" { + err = handleRebrand(cmd) + if err != nil { + return err + } + config, err := internal.GetConfig(managementURL, adminURL, configPath, preSharedKey) if err != nil { return fmt.Errorf("get config file: %v", err) diff --git a/client/cmd/service_controller.go b/client/cmd/service_controller.go index e745b480e..fea3eb39c 100644 --- a/client/cmd/service_controller.go +++ b/client/cmd/service_controller.go @@ -86,6 +86,8 @@ var runCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err @@ -118,6 +120,8 @@ var startCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err @@ -151,6 +155,8 @@ var stopCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err @@ -182,6 +188,8 @@ var restartCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err diff --git a/client/cmd/service_installer.go b/client/cmd/service_installer.go index 0d6c9ef91..86439ad17 100644 --- a/client/cmd/service_installer.go +++ b/client/cmd/service_installer.go @@ -13,6 +13,8 @@ var installCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err @@ -63,6 +65,8 @@ var uninstallCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() + cmd.SetOut(cmd.OutOrStdout()) + err := handleRebrand(cmd) if err != nil { return err diff --git a/client/cmd/status.go b/client/cmd/status.go index e6fb9db74..a0444a62d 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -18,12 +18,9 @@ var statusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() - err := handleRebrand(cmd) - if err != nil { - return err - } + cmd.SetOut(cmd.OutOrStdout()) - err = util.InitLog(logLevel, "console") + err := util.InitLog(logLevel, "console") if err != nil { return fmt.Errorf("failed initializing log %v", err) } diff --git a/client/cmd/up.go b/client/cmd/up.go index 648f14557..7ba42ea56 100644 --- a/client/cmd/up.go +++ b/client/cmd/up.go @@ -17,12 +17,9 @@ var upCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { SetFlagsFromEnvVars() - err := handleRebrand(cmd) - if err != nil { - return err - } + cmd.SetOut(cmd.OutOrStdout()) - err = util.InitLog(logLevel, "console") + err := util.InitLog(logLevel, "console") if err != nil { return fmt.Errorf("failed initializing log %v", err) } @@ -31,6 +28,11 @@ var upCmd = &cobra.Command{ // workaround to run without service if logFile == "console" { + err = handleRebrand(cmd) + if err != nil { + return err + } + config, err := internal.GetConfig(managementURL, adminURL, configPath, preSharedKey) if err != nil { return fmt.Errorf("get config file: %v", err) diff --git a/client/cmd/version.go b/client/cmd/version.go index 90cd2015a..44a059724 100644 --- a/client/cmd/version.go +++ b/client/cmd/version.go @@ -10,6 +10,7 @@ var ( Use: "version", Short: "prints Netbird version", Run: func(cmd *cobra.Command, args []string) { + cmd.SetOut(cmd.OutOrStdout()) cmd.Println(system.WiretrusteeVersion()) }, } diff --git a/client/installer.nsis b/client/installer.nsis index c5f173b6b..bb40a57c8 100644 --- a/client/installer.nsis +++ b/client/installer.nsis @@ -2,7 +2,7 @@ !define COMP_NAME "Netbird" !define WEB_SITE "Netbird.io" !define VERSION $%APPVER% -!define COPYRIGHT "Netbird Authors, 2021" +!define COPYRIGHT "Netbird Authors, 2022" !define DESCRIPTION "A WireGuard®-based mesh network that connects your devices into a single private network" !define INSTALLER_NAME "netbird-installer.exe" !define MAIN_APP_EXE "Netbird" @@ -51,10 +51,13 @@ ShowInstDetails Show !define MUI_UNICON "${ICON}" !define MUI_WELCOMEFINISHPAGE_BITMAP "${BANNER}" !define MUI_UNWELCOMEFINISHPAGE_BITMAP "${BANNER}" - +!define MUI_FINISHPAGE_RUN +!define MUI_FINISHPAGE_RUN_TEXT "Start ${UI_APP_NAME}" +!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink" ###################################################################### !include "MUI2.nsh" +!include LogicLib.nsh !define MUI_ABORTWARNING !define MUI_UNABORTWARNING @@ -79,6 +82,66 @@ ShowInstDetails Show ###################################################################### +Function GetAppFromCommand +Exch $1 +Push $2 +StrCpy $2 $1 1 0 +StrCmp $2 '"' 0 done +Push $3 +StrCpy $3 "" +loop: + IntOp $3 $3 + 1 + StrCpy $2 $1 1 $3 + StrCmp $2 '' +2 + StrCmp $2 '"' 0 loop + StrCpy $1 $1 $3 + StrCpy $1 $1 "" 1 ; Remove starting quote +Pop $3 +done: +Pop $2 +Exch $1 +FunctionEnd +!macro GetAppFromCommand in out +Push "${in}" +Call GetAppFromCommand +Pop ${out} +!macroend + +!macro UninstallPreviousNSIS UninstCommand CustomParameters +Push $0 +Push $1 +Push $2 +Push '${CustomParameters}' +Push '${UninstCommand}' +Call GetAppFromCommand ; Remove quotes and parameters from UninstCommand +Pop $0 +Pop $1 +GetFullPathName $2 "$0\.." +ExecWait '"$0" $1 _?=$2' +Delete "$0" ; Extra cleanup because we used _?= +RMDir "$2" +Pop $2 +Pop $1 +Pop $0 +!macroend + +Function .onInit + +ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Wiretrustee" "UninstallString" +${If} $R0 != "" + MessageBox MB_YESNO|MB_ICONQUESTION "Wiretrustee is installed. We must remove it before installing Netbird. Procced?" IDNO noWTUninstOld + !insertmacro UninstallPreviousNSIS $R0 "/NoMsgBox" + noWTUninstOld: +${EndIf} + +ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^NAME)" "UninstallString" +${If} $R0 != "" + MessageBox MB_YESNO|MB_ICONQUESTION "$(^NAME) is already installed. Do you want to remove the previous version?" IDNO noUninstOld + !insertmacro UninstallPreviousNSIS $R0 "/NoMsgBox" + noUninstOld: +${EndIf} +FunctionEnd +###################################################################### Section -MainProgram ${INSTALL_TYPE} SetOverwrite ifnewer @@ -101,19 +164,16 @@ WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}" WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}" WriteRegStr ${REG_ROOT} "${UI_REG_APP_PATH}" "" "$INSTDIR\${UI_APP_EXE}" -WriteRegStr ${REG_ROOT} "${UI_UNINSTALL_PATH}" "DisplayName" "${UI_APP_NAME}" -WriteRegStr ${REG_ROOT} "${UI_UNINSTALL_PATH}" "UninstallString" "$INSTDIR\netbird_uninstall.exe" -WriteRegStr ${REG_ROOT} "${UI_UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${UI_APP_EXE}" -WriteRegStr ${REG_ROOT} "${UI_UNINSTALL_PATH}" "DisplayVersion" "${VERSION}" -WriteRegStr ${REG_ROOT} "${UI_UNINSTALL_PATH}" "Publisher" "${COMP_NAME}" EnVar::SetHKLM EnVar::AddValueEx "path" "$INSTDIR" -CreateShortCut "${SMPROGRAMS}\${UI_APP_NAME}.lnk" "$INSTDIR\${UI_APP_EXE}" -CreateShortCut "${DESKTOP}\${UI_APP_NAME}.lnk" "$INSTDIR\${UI_APP_EXE}" +SetShellVarContext current +CreateShortCut "$SMPROGRAMS\${APP_NAME}.lnk" "$INSTDIR\${UI_APP_EXE}" +CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${UI_APP_EXE}" +SetShellVarContext all -Exec '"$INSTDIR\${MAIN_APP_EXE}" service install' +ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service install' Exec '"$INSTDIR\${MAIN_APP_EXE}" service start' # sleep a bit for visibility Sleep 1000 @@ -124,14 +184,29 @@ SectionEnd Section Uninstall ${INSTALL_TYPE} -Exec '"$INSTDIR\${MAIN_APP_EXE}" service stop' +ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service stop' Exec '"$INSTDIR\${MAIN_APP_EXE}" service uninstall' +# kill ui client +ExecWait `taskkill /im ${UI_APP_EXE}.exe` # wait the service uninstall take unblock the executable Sleep 3000 RmDir /r "$INSTDIR" +SetShellVarContext current +Delete "$DESKTOP\${APP_NAME}.lnk" +Delete "$SMPROGRAMS\${APP_NAME}.lnk" +SetShellVarContext all + DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}" DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}" EnVar::SetHKLM EnVar::DeleteValue "path" "$INSTDIR" SectionEnd + + +Function LaunchLink +SetShellVarContext current + SetOutPath $INSTDIR + ShellExecAsUser::ShellExecAsUser "" "$DESKTOP\${APP_NAME}.lnk" +SetShellVarContext all +FunctionEnd \ No newline at end of file diff --git a/client/ui/netbird-ui.rb.tmpl b/client/ui/netbird-ui.rb.tmpl index e612f84ee..9efddd750 100644 --- a/client/ui/netbird-ui.rb.tmpl +++ b/client/ui/netbird-ui.rb.tmpl @@ -17,6 +17,22 @@ cask "{{ $projectName }}" do depends_on formula: "netbird" + postflight do + set_permissions "/Applications/Netbird UI.app/installer.sh", '0755' + set_permissions "/Applications/Netbird UI.app/uninstaller.sh", '0755' + end + + postflight do + system_command "#{appdir}/Netbird UI.app/installer.sh", + args: ["#{version}"], + sudo: true + end + + uninstall_preflight do + system_command "#{appdir}/Netbird UI.app/uninstaller.sh", + sudo: false + end + name "Netbird UI" desc "Netbird UI Client" homepage "https://www.netbird.io/" diff --git a/release_files/darwin-ui-installer.sh b/release_files/darwin-ui-installer.sh new file mode 100644 index 000000000..520356cea --- /dev/null +++ b/release_files/darwin-ui-installer.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +export PATH=$PATH:/usr/local/bin + +# check if wiretrustee is installed +WT_BIN=$(which wiretrustee) +if [ -n "$WT_BIN" ] +then + echo "Stopping and uninstalling Wiretrustee daemon" + wiretrustee service stop || true + wiretrustee service uninstall || true +fi +# check if netbird is installed +NB_BIN=$(which netbird) +if [ -z "$NB_BIN" ] +then + echo "Netbird daemon is not installed. Please run: brew install netbirdio/tap/netbird" + exit 1 +fi +NB_UI_VERSION=$1 +NB_VERSION=$(netbird version) +if [ "X-$NB_UI_VERSION" != "X-$NB_VERSION" ] +then + echo "Netbird's daemon is running with a different version than the Netbird's UI:" + echo "Netbird UI Version: $NB_UI_VERSION" + echo "Netbird Daemon Version: $NB_VERSION" + echo "Please run: brew install netbirdio/tap/netbird" + echo "to update it" +fi +# start netbird daemon service +echo "Starting Netbird daemon" +netbird service install || true +netbird service start || true \ No newline at end of file diff --git a/release_files/darwin-ui-uninstaller.sh b/release_files/darwin-ui-uninstaller.sh new file mode 100644 index 000000000..45938dfbc --- /dev/null +++ b/release_files/darwin-ui-uninstaller.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +export PATH=$PATH:/usr/local/bin + +# check if netbird is installed +NB_BIN=$(which netbird) +if [ -z "$NB_BIN" ] +then + exit 0 +fi +# start netbird daemon service +echo "netbird daemon service still running. You can uninstall it by running: " +echo "sudo netbird service stop" +echo "sudo netbird service uninstall"