Skip to content

Commit

Permalink
Fix update script's failure to update netbird-ui in binary installati…
Browse files Browse the repository at this point in the history
…on (#1218)

Resolve the problem with the update script that prevents netbird-ui from updating during binary installation.

Introduce the variable UPDATE_NETBIRD. Now we can upgrade the binary installation with

A function stop_running_netbird_ui has been added which checks if NetBird UI is currently running. If so, it stops the UI to allow the application update process to proceed smoothly. This was necessary to prevent conflicts or errors during updates if the UI was running.


---------

Co-authored-by: Maycon Santos <[email protected]>
  • Loading branch information
bcmmbaga and mlsmaycon authored Oct 19, 2023
1 parent a9f5fad commit ee6be58
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/golang-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ concurrency:

jobs:
test:
strategy:
matrix:
store: ['jsonfile', 'sqlite']
runs-on: windows-latest
steps:
- name: Checkout code
Expand All @@ -42,9 +39,9 @@ jobs:

- run: mv ${{ env.downloadPath }}/wintun/bin/amd64/wintun.dll 'C:\Windows\System32\'

- run: choco install -y sysinternals
- run: choco install -y sysinternals --ignore-checksums
- run: choco install -y mingw

- run: PsExec64 -s -w ${{ github.workspace }} C:\hostedtoolcache\windows\go\${{ steps.go.outputs.go-version }}\x64\bin\go.exe env -w GOMODCACHE=C:\Users\runneradmin\go\pkg\mod
- run: PsExec64 -s -w ${{ github.workspace }} C:\hostedtoolcache\windows\go\${{ steps.go.outputs.go-version }}\x64\bin\go.exe env -w GOCACHE=C:\Users\runneradmin\AppData\Local\go-build

Expand Down
52 changes: 36 additions & 16 deletions release_files/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ download_release_binary() {
if [ "$OS_TYPE" = "darwin" ] && [ "$1" = "$UI_APP" ]; then
INSTALL_DIR="/Applications/NetBird UI.app"

if test -d "$INSTALL_DIR" ; then
echo "removing $INSTALL_DIR"
rm -rfv "$INSTALL_DIR"
fi

# Unzip the app and move to INSTALL_DIR
unzip -q -o "$BINARY_NAME"
mv "netbird_ui_${OS_TYPE}_${ARCH}" "$INSTALL_DIR"
mv "netbird_ui_${OS_TYPE}_${ARCH}/" "$INSTALL_DIR/"
else
${SUDO} mkdir -p "$INSTALL_DIR"
tar -xzvf "$BINARY_NAME"
Expand Down Expand Up @@ -184,16 +189,6 @@ install_netbird() {
fi
fi

# Checks if SKIP_UI_APP env is set
if [ -z "$SKIP_UI_APP" ]; then
SKIP_UI_APP=false
else
if $SKIP_UI_APP; then
echo "SKIP_UI_APP has been set to true in the environment"
echo "NetBird UI installation will be omitted based on your preference"
fi
fi

# Run the installation, if a desktop environment is not detected
# only the CLI will be installed
case "$PACKAGE_MANAGER" in
Expand Down Expand Up @@ -294,14 +289,22 @@ is_bin_package_manager() {
fi
}

stop_running_netbird_ui() {
NB_UI_PROC=$(ps -ef | grep "[n]etbird-ui" | awk '{print $2}')
if [ -n "$NB_UI_PROC" ]; then
echo "NetBird UI is running with PID $NB_UI_PROC. Stopping it..."
kill -9 "$NB_UI_PROC"
fi
}

update_netbird() {
if is_bin_package_manager "$CONFIG_FILE"; then
latest_release=$(get_latest_release)
latest_version=${latest_release#v}
installed_version=$(netbird version)

if [ "$latest_version" = "$installed_version" ]; then
echo "Installed netbird version ($installed_version) is up-to-date"
echo "Installed NetBird version ($installed_version) is up-to-date"
exit 0
fi

Expand All @@ -310,8 +313,9 @@ update_netbird() {
echo ""
echo "Initiating NetBird update. This will stop the netbird service and restart it after the update"

${SUDO} netbird service stop
${SUDO} netbird service uninstall
${SUDO} netbird service stop || true
${SUDO} netbird service uninstall || true
stop_running_netbird_ui
install_native_binaries

${SUDO} netbird service install
Expand All @@ -322,6 +326,16 @@ update_netbird() {
fi
}

# Checks if SKIP_UI_APP env is set
if [ -z "$SKIP_UI_APP" ]; then
SKIP_UI_APP=false
else
if $SKIP_UI_APP; then
echo "SKIP_UI_APP has been set to true in the environment"
echo "NetBird UI installation will be omitted based on your preference"
fi
fi

# Identify OS name and default package manager
if type uname >/dev/null 2>&1; then
case "$(uname)" in
Expand All @@ -334,7 +348,7 @@ if type uname >/dev/null 2>&1; then
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "arm64" ] \
&& [ "$ARCH" != "x86_64" ];then
SKIP_UI_APP=true
echo "NetBird UI installation will be omitted as $ARCH is not a compactible architecture"
echo "NetBird UI installation will be omitted as $ARCH is not a compatible architecture"
fi

# Allow netbird UI installation for linux running desktop enviroment
Expand Down Expand Up @@ -376,7 +390,13 @@ if type uname >/dev/null 2>&1; then
esac
fi

case "$1" in
UPDATE_FLAG=$1

if [ "${UPDATE_NETBIRD}-x" = "true-x" ]; then
UPDATE_FLAG="--update"
fi

case "$UPDATE_FLAG" in
--update)
update_netbird
;;
Expand Down

0 comments on commit ee6be58

Please sign in to comment.