Fix update script's failure to update netbird-ui in binary installation (#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 <mlsmaycon@gmail.com>
This commit is contained in:
Bethuel Mmbaga 2023-10-19 18:47:39 +03:00 committed by GitHub
parent a9f5fad625
commit ee6be58a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 21 deletions

View File

@ -14,9 +14,6 @@ concurrency:
jobs:
test:
strategy:
matrix:
store: ['jsonfile', 'sqlite']
runs-on: windows-latest
steps:
- name: Checkout code
@ -42,7 +39,7 @@ 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

View File

@ -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"
@ -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
@ -294,6 +289,14 @@ 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)
@ -301,7 +304,7 @@ update_netbird() {
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
@ -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
@ -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
@ -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
@ -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
;;