mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-23 03:48:46 +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
113
release_files/install.sh
Normal file → Executable file
113
release_files/install.sh
Normal file → Executable file
@ -3,6 +3,9 @@
|
|||||||
# Source: https://github.com/physk/netbird-installer
|
# Source: https://github.com/physk/netbird-installer
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
CONFIG_FOLDER="/etc/netbird"
|
||||||
|
CONFIG_FILE="$CONFIG_FOLDER/install.conf"
|
||||||
|
|
||||||
OWNER="netbirdio"
|
OWNER="netbirdio"
|
||||||
REPO="netbird"
|
REPO="netbird"
|
||||||
CLI_APP="netbird"
|
CLI_APP="netbird"
|
||||||
@ -12,7 +15,7 @@ UI_APP="netbird-ui"
|
|||||||
OS_NAME=""
|
OS_NAME=""
|
||||||
OS_TYPE=""
|
OS_TYPE=""
|
||||||
ARCH="$(uname -m)"
|
ARCH="$(uname -m)"
|
||||||
PACKAGE_MANAGER=""
|
PACKAGE_MANAGER="bin"
|
||||||
INSTALL_DIR=""
|
INSTALL_DIR=""
|
||||||
|
|
||||||
get_latest_release() {
|
get_latest_release() {
|
||||||
@ -25,7 +28,7 @@ download_release_binary() {
|
|||||||
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/download"
|
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/download"
|
||||||
BINARY_BASE_NAME="${VERSION#v}_${OS_TYPE}_${ARCH}.tar.gz"
|
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
|
if [ "$OS_TYPE" = "darwin" ] && [ "$1" = "$UI_APP" ]; then
|
||||||
BINARY_BASE_NAME="${VERSION#v}_${OS_TYPE}_${ARCH}_signed.zip"
|
BINARY_BASE_NAME="${VERSION#v}_${OS_TYPE}_${ARCH}_signed.zip"
|
||||||
fi
|
fi
|
||||||
@ -73,8 +76,8 @@ add_apt_repo() {
|
|||||||
|
|
||||||
add_rpm_repo() {
|
add_rpm_repo() {
|
||||||
cat <<-EOF | sudo tee /etc/yum.repos.d/netbird.repo
|
cat <<-EOF | sudo tee /etc/yum.repos.d/netbird.repo
|
||||||
[Netbird]
|
[NetBird]
|
||||||
name=Netbird
|
name=NetBird
|
||||||
baseurl=https://pkgs.netbird.io/yum/
|
baseurl=https://pkgs.netbird.io/yum/
|
||||||
enabled=1
|
enabled=1
|
||||||
gpgcheck=0
|
gpgcheck=0
|
||||||
@ -145,14 +148,17 @@ check_use_bin_variable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install_netbird() {
|
install_netbird() {
|
||||||
# Check if netbird CLI is installed
|
|
||||||
if [ -x "$(command -v netbird)" ]; then
|
if [ -x "$(command -v netbird)" ]; then
|
||||||
if netbird status > /dev/null 2>&1; then
|
status_output=$(netbird status)
|
||||||
echo "Netbird service is running, please stop it before proceeding"
|
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
|
fi
|
||||||
|
|
||||||
echo "Netbird seems to be installed already, please remove it before proceeding"
|
if [ -n "$status_output" ]; then
|
||||||
exit 1
|
echo "NetBird seems to be installed already, please remove it before proceeding"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Checks if SKIP_UI_APP env is set
|
# Checks if SKIP_UI_APP env is set
|
||||||
@ -161,7 +167,7 @@ install_netbird() {
|
|||||||
else
|
else
|
||||||
if $SKIP_UI_APP; then
|
if $SKIP_UI_APP; then
|
||||||
echo "SKIP_UI_APP has been set to true in the environment"
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -177,13 +183,13 @@ install_netbird() {
|
|||||||
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "arm64" ] \
|
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "arm64" ] \
|
||||||
&& [ "$ARCH" != "x86_64" ];then
|
&& [ "$ARCH" != "x86_64" ];then
|
||||||
SKIP_UI_APP=true
|
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
|
fi
|
||||||
|
|
||||||
# Allow netbird UI installation for linux running desktop enviroment
|
# Allow netbird UI installation for linux running desktop enviroment
|
||||||
if [ -z "$XDG_CURRENT_DESKTOP" ];then
|
if [ -z "$XDG_CURRENT_DESKTOP" ];then
|
||||||
SKIP_UI_APP=true
|
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
|
fi
|
||||||
|
|
||||||
# Check the availability of a compatible package manager
|
# Check the availability of a compatible package manager
|
||||||
@ -270,31 +276,35 @@ install_netbird() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ "$OS_NAME" = "nixos" ];then
|
if [ "$OS_NAME" = "nixos" ];then
|
||||||
echo "Please add Netbird to your NixOS configuration.nix directly:"
|
echo "Please add NetBird to your NixOS configuration.nix directly:"
|
||||||
echo
|
echo ""
|
||||||
echo "services.netbird.enable = true;"
|
echo "services.netbird.enable = true;"
|
||||||
|
|
||||||
if ! $SKIP_UI_APP; then
|
if ! $SKIP_UI_APP; then
|
||||||
echo "environment.systemPackages = [ pkgs.netbird-ui ];"
|
echo "environment.systemPackages = [ pkgs.netbird-ui ];"
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Build and apply new configuration:"
|
|
||||||
echo
|
|
||||||
echo "sudo nixos-rebuild switch"
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Build and apply new configuration:"
|
||||||
|
echo ""
|
||||||
|
echo "sudo nixos-rebuild switch"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
install_native_binaries
|
install_native_binaries
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
# Load and start netbird service
|
||||||
if ! sudo netbird service install 2>&1; then
|
if ! sudo netbird service install 2>&1; then
|
||||||
echo "Netbird service has already been loaded"
|
echo "NetBird service has already been loaded"
|
||||||
fi
|
fi
|
||||||
if ! sudo netbird service start 2>&1; then
|
if ! sudo netbird service start 2>&1; then
|
||||||
echo "Netbird service has already been started"
|
echo "NetBird service has already been started"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -303,4 +313,51 @@ install_netbird() {
|
|||||||
echo "sudo netbird up"
|
echo "sudo netbird up"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_netbird
|
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