From 618aeed559e62a247f6199d1ff4106205f2f9972 Mon Sep 17 00:00:00 2001 From: ronivay Date: Tue, 2 Oct 2018 14:03:39 +0300 Subject: [PATCH] Fix setcap issues between distros --- README.md | 1 + xo-install.sh | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dc93583..d740d0d 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ CentOS: Debian/Ubuntu: - apt-transport-https - ca-certificates +- libcap2-bin - curl - yarn - nodejs (v8) diff --git a/xo-install.sh b/xo-install.sh index b94f9cc..37b871a 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -271,14 +271,19 @@ function InstallXO { echo "Adding user to systemd config" sed -i "/SyslogIdentifier=.*/a User=$XOUSER" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service - if [ $OSNAME == "CentOS" ]; then - echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/node..." - setcap 'cap_net_bind_service=+ep' /usr/bin/node >/dev/null \ - && echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port" - else - echo -n "Attempting to set cap_net_bind_service permission for /usr/bin/nodejs..." - setcap 'cap_net_bind_service=+ep' /usr/bin/nodejs >/dev/null \ - && echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port" + if [ "$PORT" -le "1024" ]; then + NODEBINARY="$(which node)" + if [[ -L "$NODEBINARY" ]]; then + NODEBINARY="$(readlink -e $NODEBINARY)" + fi + + if [[ ! -z $NODEBINARY ]]; then + echo -n "Attempting to set cap_net_bind_service permission for $NODEBINARY..." + setcap 'cap_net_bind_service=+ep' $NODEBINARY >/dev/null \ + && echo "Success" || echo "Failed. Non-privileged user might not be able to bind to <1024 port. xo-server won't start most likely" + else + echo "Can't find node executable, or it's a symlink to non existing file. Not trying to setcap. xo-server won't start most likely" + fi fi fi