mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-21 19:07:18 +01:00
Add auto-update feature in netbird script for binary installation (#1106)
This pull request addresses the need to enhance the installer script by introducing a new parameter --update to trigger updates. The goal is to streamline the update process for binary installations and provide a better experience for users.
This commit is contained in:
parent
ac0b7dc8cb
commit
80d9b5fca5
89
release_files/install.sh
Normal file → Executable file
89
release_files/install.sh
Normal file → Executable file
@ -3,6 +3,9 @@
|
||||
# Source: https://github.com/physk/netbird-installer
|
||||
set -e
|
||||
|
||||
CONFIG_FOLDER="/etc/netbird"
|
||||
CONFIG_FILE="$CONFIG_FOLDER/install.conf"
|
||||
|
||||
OWNER="netbirdio"
|
||||
REPO="netbird"
|
||||
CLI_APP="netbird"
|
||||
@ -12,7 +15,7 @@ UI_APP="netbird-ui"
|
||||
OS_NAME=""
|
||||
OS_TYPE=""
|
||||
ARCH="$(uname -m)"
|
||||
PACKAGE_MANAGER=""
|
||||
PACKAGE_MANAGER="bin"
|
||||
INSTALL_DIR=""
|
||||
|
||||
get_latest_release() {
|
||||
@ -25,7 +28,7 @@ download_release_binary() {
|
||||
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/download"
|
||||
BINARY_BASE_NAME="${VERSION#v}_${OS_TYPE}_${ARCH}.tar.gz"
|
||||
|
||||
# for Darwin, download the signed Netbird-UI
|
||||
# for Darwin, download the signed NetBird-UI
|
||||
if [ "$OS_TYPE" = "darwin" ] && [ "$1" = "$UI_APP" ]; then
|
||||
BINARY_BASE_NAME="${VERSION#v}_${OS_TYPE}_${ARCH}_signed.zip"
|
||||
fi
|
||||
@ -73,8 +76,8 @@ add_apt_repo() {
|
||||
|
||||
add_rpm_repo() {
|
||||
cat <<-EOF | sudo tee /etc/yum.repos.d/netbird.repo
|
||||
[Netbird]
|
||||
name=Netbird
|
||||
[NetBird]
|
||||
name=NetBird
|
||||
baseurl=https://pkgs.netbird.io/yum/
|
||||
enabled=1
|
||||
gpgcheck=0
|
||||
@ -145,15 +148,18 @@ check_use_bin_variable() {
|
||||
}
|
||||
|
||||
install_netbird() {
|
||||
# Check if netbird CLI is installed
|
||||
if [ -x "$(command -v netbird)" ]; then
|
||||
if netbird status > /dev/null 2>&1; then
|
||||
echo "Netbird service is running, please stop it before proceeding"
|
||||
status_output=$(netbird status)
|
||||
if echo "$status_output" | grep -q 'Management: Connected' && echo "$status_output" | grep -q 'Signal: Connected'; then
|
||||
echo "NetBird service is running, please stop it before proceeding"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Netbird seems to be installed already, please remove it before proceeding"
|
||||
if [ -n "$status_output" ]; then
|
||||
echo "NetBird seems to be installed already, please remove it before proceeding"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Checks if SKIP_UI_APP env is set
|
||||
if [ -z "$SKIP_UI_APP" ]; then
|
||||
@ -161,7 +167,7 @@ install_netbird() {
|
||||
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"
|
||||
echo "NetBird UI installation will be omitted based on your preference"
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -177,13 +183,13 @@ install_netbird() {
|
||||
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 compactible architecture"
|
||||
fi
|
||||
|
||||
# Allow netbird UI installation for linux running desktop enviroment
|
||||
if [ -z "$XDG_CURRENT_DESKTOP" ];then
|
||||
SKIP_UI_APP=true
|
||||
echo "Netbird UI installation will be omitted as Linux does not run desktop environment"
|
||||
echo "NetBird UI installation will be omitted as Linux does not run desktop environment"
|
||||
fi
|
||||
|
||||
# Check the availability of a compatible package manager
|
||||
@ -271,8 +277,8 @@ install_netbird() {
|
||||
;;
|
||||
*)
|
||||
if [ "$OS_NAME" = "nixos" ];then
|
||||
echo "Please add Netbird to your NixOS configuration.nix directly:"
|
||||
echo
|
||||
echo "Please add NetBird to your NixOS configuration.nix directly:"
|
||||
echo ""
|
||||
echo "services.netbird.enable = true;"
|
||||
|
||||
if ! $SKIP_UI_APP; then
|
||||
@ -280,7 +286,7 @@ install_netbird() {
|
||||
fi
|
||||
|
||||
echo "Build and apply new configuration:"
|
||||
echo
|
||||
echo ""
|
||||
echo "sudo nixos-rebuild switch"
|
||||
exit 0
|
||||
fi
|
||||
@ -289,12 +295,16 @@ install_netbird() {
|
||||
;;
|
||||
esac
|
||||
|
||||
# Add package manager to config
|
||||
sudo mkdir -p "$CONFIG_FOLDER"
|
||||
echo "package_manager=$PACKAGE_MANAGER" | sudo tee "$CONFIG_FILE" > /dev/null
|
||||
|
||||
# Load and start netbird service
|
||||
if ! sudo netbird service install 2>&1; then
|
||||
echo "Netbird service has already been loaded"
|
||||
echo "NetBird service has already been loaded"
|
||||
fi
|
||||
if ! sudo netbird service start 2>&1; then
|
||||
echo "Netbird service has already been started"
|
||||
echo "NetBird service has already been started"
|
||||
fi
|
||||
|
||||
|
||||
@ -303,4 +313,51 @@ install_netbird() {
|
||||
echo "sudo netbird up"
|
||||
}
|
||||
|
||||
version_greater_equal() {
|
||||
printf '%s\n%s\n' "$2" "$1" | sort -V -C
|
||||
}
|
||||
|
||||
is_bin_package_manager() {
|
||||
if sudo test -f "$1" && sudo grep -q "package_manager=bin" "$1" ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
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"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if version_greater_equal "$latest_version" "$installed_version"; then
|
||||
echo "NetBird new version ($latest_version) available. Updating..."
|
||||
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
|
||||
install_native_binaries
|
||||
|
||||
sudo netbird service install
|
||||
sudo netbird service start
|
||||
fi
|
||||
else
|
||||
echo "NetBird installation was done using a package manager. Please use your system's package manager to update"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
--update)
|
||||
update_netbird
|
||||
;;
|
||||
*)
|
||||
install_netbird
|
||||
esac
|
Loading…
Reference in New Issue
Block a user