mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 09:33:24 +01:00
Enhance compatibility of install.sh for systems without sudo (#1176)
This commit modifies the install.sh script to improve compatibility with systems lacking the sudo command. A conditional check is added at the beginning of the script to see if the sudo command exists. If it does, operations in the script that previously required sudo would proceed as normal, using the sudo command. If the system does not have sudo, the shell would execute these operations without it. This change enhances the usability of this script in restricted environments where sudo is not installed or available to users.
This commit is contained in:
parent
8c5c6815e0
commit
c81b83b346
@ -1,4 +1,3 @@
|
|||||||
#!/bin/sh
|
|
||||||
# This code is based on the netbird-installer contribution by physk on GitHub.
|
# This code is based on the netbird-installer contribution by physk on GitHub.
|
||||||
# Source: https://github.com/physk/netbird-installer
|
# Source: https://github.com/physk/netbird-installer
|
||||||
set -e
|
set -e
|
||||||
@ -17,6 +16,12 @@ OS_TYPE=""
|
|||||||
ARCH="$(uname -m)"
|
ARCH="$(uname -m)"
|
||||||
PACKAGE_MANAGER="bin"
|
PACKAGE_MANAGER="bin"
|
||||||
INSTALL_DIR=""
|
INSTALL_DIR=""
|
||||||
|
SUDO=""
|
||||||
|
|
||||||
|
|
||||||
|
if command -v sudo > /dev/null && [ "$(id -u)" -ne 0 ]; then
|
||||||
|
SUDO="sudo"
|
||||||
|
fi
|
||||||
|
|
||||||
get_latest_release() {
|
get_latest_release() {
|
||||||
if [ -n "$GITHUB_TOKEN" ]; then
|
if [ -n "$GITHUB_TOKEN" ]; then
|
||||||
@ -65,18 +70,18 @@ download_release_binary() {
|
|||||||
unzip -q -o "$BINARY_NAME"
|
unzip -q -o "$BINARY_NAME"
|
||||||
mv "netbird_ui_${OS_TYPE}_${ARCH}" "$INSTALL_DIR"
|
mv "netbird_ui_${OS_TYPE}_${ARCH}" "$INSTALL_DIR"
|
||||||
else
|
else
|
||||||
sudo mkdir -p "$INSTALL_DIR"
|
${SUDO} mkdir -p "$INSTALL_DIR"
|
||||||
tar -xzvf "$BINARY_NAME"
|
tar -xzvf "$BINARY_NAME"
|
||||||
sudo mv "${1%_"${BINARY_BASE_NAME}"}" "$INSTALL_DIR/"
|
${SUDO} mv "${1%_"${BINARY_BASE_NAME}"}" "$INSTALL_DIR/"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
add_apt_repo() {
|
add_apt_repo() {
|
||||||
sudo apt-get update
|
${SUDO} apt-get update
|
||||||
sudo apt-get install ca-certificates curl gnupg -y
|
${SUDO} apt-get install ca-certificates curl gnupg -y
|
||||||
|
|
||||||
# Remove old keys and repo source files
|
# Remove old keys and repo source files
|
||||||
sudo rm -f \
|
${SUDO} rm -f \
|
||||||
/etc/apt/sources.list.d/netbird.list \
|
/etc/apt/sources.list.d/netbird.list \
|
||||||
/etc/apt/sources.list.d/wiretrustee.list \
|
/etc/apt/sources.list.d/wiretrustee.list \
|
||||||
/etc/apt/trusted.gpg.d/wiretrustee.gpg \
|
/etc/apt/trusted.gpg.d/wiretrustee.gpg \
|
||||||
@ -84,16 +89,16 @@ add_apt_repo() {
|
|||||||
/usr/share/keyrings/wiretrustee-archive-keyring.gpg
|
/usr/share/keyrings/wiretrustee-archive-keyring.gpg
|
||||||
|
|
||||||
curl -sSL https://pkgs.netbird.io/debian/public.key \
|
curl -sSL https://pkgs.netbird.io/debian/public.key \
|
||||||
| sudo gpg --dearmor -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
| ${SUDO} gpg --dearmor -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||||
|
|
||||||
echo 'deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main' \
|
echo 'deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main' \
|
||||||
| sudo tee /etc/apt/sources.list.d/netbird.list
|
| ${SUDO} tee /etc/apt/sources.list.d/netbird.list
|
||||||
|
|
||||||
sudo apt-get update
|
${SUDO} apt-get update
|
||||||
}
|
}
|
||||||
|
|
||||||
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/
|
||||||
@ -112,7 +117,7 @@ add_aur_repo() {
|
|||||||
for PKG in $INSTALL_PKGS; do
|
for PKG in $INSTALL_PKGS; do
|
||||||
if ! pacman -Q "$PKG" > /dev/null 2>&1; then
|
if ! pacman -Q "$PKG" > /dev/null 2>&1; then
|
||||||
# Install missing package(s)
|
# Install missing package(s)
|
||||||
sudo pacman -S "$PKG" --noconfirm
|
${SUDO} pacman -S "$PKG" --noconfirm
|
||||||
|
|
||||||
# Add installed package for clean up later
|
# Add installed package for clean up later
|
||||||
REMOVE_PKGS="$REMOVE_PKGS $PKG"
|
REMOVE_PKGS="$REMOVE_PKGS $PKG"
|
||||||
@ -129,7 +134,7 @@ add_aur_repo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up the installed packages
|
# Clean up the installed packages
|
||||||
sudo pacman -Rs "$REMOVE_PKGS" --noconfirm
|
${SUDO} pacman -Rs "$REMOVE_PKGS" --noconfirm
|
||||||
}
|
}
|
||||||
|
|
||||||
install_native_binaries() {
|
install_native_binaries() {
|
||||||
@ -194,31 +199,31 @@ install_netbird() {
|
|||||||
case "$PACKAGE_MANAGER" in
|
case "$PACKAGE_MANAGER" in
|
||||||
apt)
|
apt)
|
||||||
add_apt_repo
|
add_apt_repo
|
||||||
sudo apt-get install netbird -y
|
${SUDO} apt-get install netbird -y
|
||||||
|
|
||||||
if ! $SKIP_UI_APP; then
|
if ! $SKIP_UI_APP; then
|
||||||
sudo apt-get install netbird-ui -y
|
${SUDO} apt-get install netbird-ui -y
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
yum)
|
yum)
|
||||||
add_rpm_repo
|
add_rpm_repo
|
||||||
sudo yum -y install netbird
|
${SUDO} yum -y install netbird
|
||||||
if ! $SKIP_UI_APP; then
|
if ! $SKIP_UI_APP; then
|
||||||
sudo yum -y install netbird-ui
|
${SUDO} yum -y install netbird-ui
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
dnf)
|
dnf)
|
||||||
add_rpm_repo
|
add_rpm_repo
|
||||||
sudo dnf -y install dnf-plugin-config-manager
|
${SUDO} dnf -y install dnf-plugin-config-manager
|
||||||
sudo dnf config-manager --add-repo /etc/yum.repos.d/netbird.repo
|
${SUDO} dnf config-manager --add-repo /etc/yum.repos.d/netbird.repo
|
||||||
sudo dnf -y install netbird
|
${SUDO} dnf -y install netbird
|
||||||
|
|
||||||
if ! $SKIP_UI_APP; then
|
if ! $SKIP_UI_APP; then
|
||||||
sudo dnf -y install netbird-ui
|
${SUDO} dnf -y install netbird-ui
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
pacman)
|
pacman)
|
||||||
sudo pacman -Syy
|
${SUDO} pacman -Syy
|
||||||
add_aur_repo
|
add_aur_repo
|
||||||
;;
|
;;
|
||||||
brew)
|
brew)
|
||||||
@ -251,7 +256,7 @@ install_netbird() {
|
|||||||
|
|
||||||
echo "Build and apply new configuration:"
|
echo "Build and apply new configuration:"
|
||||||
echo ""
|
echo ""
|
||||||
echo "sudo nixos-rebuild switch"
|
echo "${SUDO} nixos-rebuild switch"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -260,14 +265,14 @@ install_netbird() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# Add package manager to config
|
# Add package manager to config
|
||||||
sudo mkdir -p "$CONFIG_FOLDER"
|
${SUDO} mkdir -p "$CONFIG_FOLDER"
|
||||||
echo "package_manager=$PACKAGE_MANAGER" | sudo tee "$CONFIG_FILE" > /dev/null
|
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
|
||||||
|
|
||||||
@ -282,7 +287,7 @@ version_greater_equal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is_bin_package_manager() {
|
is_bin_package_manager() {
|
||||||
if sudo test -f "$1" && sudo grep -q "package_manager=bin" "$1" ; then
|
if ${SUDO} test -f "$1" && ${SUDO} grep -q "package_manager=bin" "$1" ; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
@ -305,12 +310,12 @@ update_netbird() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Initiating NetBird update. This will stop the netbird service and restart it after the update"
|
echo "Initiating NetBird update. This will stop the netbird service and restart it after the update"
|
||||||
|
|
||||||
sudo netbird service stop
|
${SUDO} netbird service stop
|
||||||
sudo netbird service uninstall
|
${SUDO} netbird service uninstall
|
||||||
install_native_binaries
|
install_native_binaries
|
||||||
|
|
||||||
sudo netbird service install
|
${SUDO} netbird service install
|
||||||
sudo netbird service start
|
${SUDO} netbird service start
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "NetBird installation was done using a package manager. Please use your system's package manager to update"
|
echo "NetBird installation was done using a package manager. Please use your system's package manager to update"
|
||||||
|
Loading…
Reference in New Issue
Block a user