Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance compatibility of install.sh for systems without sudo #1176

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions release_files/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
# This code is based on the netbird-installer contribution by physk on GitHub.
# Source: https://github.com/physk/netbird-installer
set -e
Expand All @@ -17,6 +16,12 @@ OS_TYPE=""
ARCH="$(uname -m)"
PACKAGE_MANAGER="bin"
INSTALL_DIR=""
SUDO=""


if command -v sudo > /dev/null && [ "$(id -u)" -ne 0 ]; then
SUDO="sudo"
fi

get_latest_release() {
if [ -n "$GITHUB_TOKEN" ]; then
Expand Down Expand Up @@ -65,35 +70,35 @@ download_release_binary() {
unzip -q -o "$BINARY_NAME"
mv "netbird_ui_${OS_TYPE}_${ARCH}" "$INSTALL_DIR"
else
sudo mkdir -p "$INSTALL_DIR"
${SUDO} mkdir -p "$INSTALL_DIR"
tar -xzvf "$BINARY_NAME"
sudo mv "${1%_"${BINARY_BASE_NAME}"}" "$INSTALL_DIR/"
${SUDO} mv "${1%_"${BINARY_BASE_NAME}"}" "$INSTALL_DIR/"
fi
}

add_apt_repo() {
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg -y
${SUDO} apt-get update
${SUDO} apt-get install ca-certificates curl gnupg -y

# 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/wiretrustee.list \
/etc/apt/trusted.gpg.d/wiretrustee.gpg \
/usr/share/keyrings/netbird-archive-keyring.gpg \
/usr/share/keyrings/wiretrustee-archive-keyring.gpg

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' \
| 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() {
cat <<-EOF | sudo tee /etc/yum.repos.d/netbird.repo
cat <<-EOF | ${SUDO} tee /etc/yum.repos.d/netbird.repo
[NetBird]
name=NetBird
baseurl=https://pkgs.netbird.io/yum/
Expand All @@ -112,7 +117,7 @@ add_aur_repo() {
for PKG in $INSTALL_PKGS; do
if ! pacman -Q "$PKG" > /dev/null 2>&1; then
# Install missing package(s)
sudo pacman -S "$PKG" --noconfirm
${SUDO} pacman -S "$PKG" --noconfirm

# Add installed package for clean up later
REMOVE_PKGS="$REMOVE_PKGS $PKG"
Expand All @@ -129,7 +134,7 @@ add_aur_repo() {
fi

# Clean up the installed packages
sudo pacman -Rs "$REMOVE_PKGS" --noconfirm
${SUDO} pacman -Rs "$REMOVE_PKGS" --noconfirm
}

install_native_binaries() {
Expand Down Expand Up @@ -194,31 +199,31 @@ install_netbird() {
case "$PACKAGE_MANAGER" in
apt)
add_apt_repo
sudo apt-get install netbird -y
${SUDO} apt-get install netbird -y

if ! $SKIP_UI_APP; then
sudo apt-get install netbird-ui -y
${SUDO} apt-get install netbird-ui -y
fi
;;
yum)
add_rpm_repo
sudo yum -y install netbird
${SUDO} yum -y install netbird
if ! $SKIP_UI_APP; then
sudo yum -y install netbird-ui
${SUDO} yum -y install netbird-ui
fi
;;
dnf)
add_rpm_repo
sudo dnf -y install dnf-plugin-config-manager
sudo dnf config-manager --add-repo /etc/yum.repos.d/netbird.repo
sudo dnf -y install netbird
${SUDO} dnf -y install dnf-plugin-config-manager
${SUDO} dnf config-manager --add-repo /etc/yum.repos.d/netbird.repo
${SUDO} dnf -y install netbird

if ! $SKIP_UI_APP; then
sudo dnf -y install netbird-ui
${SUDO} dnf -y install netbird-ui
fi
;;
pacman)
sudo pacman -Syy
${SUDO} pacman -Syy
add_aur_repo
;;
brew)
Expand Down Expand Up @@ -251,7 +256,7 @@ install_netbird() {

echo "Build and apply new configuration:"
echo ""
echo "sudo nixos-rebuild switch"
echo "${SUDO} nixos-rebuild switch"
exit 0
fi

Expand All @@ -260,14 +265,14 @@ install_netbird() {
esac

# Add package manager to config
sudo mkdir -p "$CONFIG_FOLDER"
echo "package_manager=$PACKAGE_MANAGER" | sudo tee "$CONFIG_FILE" > /dev/null
${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
if ! ${SUDO} netbird service install 2>&1; then
echo "NetBird service has already been loaded"
fi
if ! sudo netbird service start 2>&1; then
if ! ${SUDO} netbird service start 2>&1; then
echo "NetBird service has already been started"
fi

Expand All @@ -282,7 +287,7 @@ version_greater_equal() {
}

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
else
return 1
Expand All @@ -305,12 +310,12 @@ 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
${SUDO} netbird service uninstall
install_native_binaries

sudo netbird service install
sudo netbird service start
${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"
Expand Down