From 482a09f99530102d38fae4758eed36519dae0d8a Mon Sep 17 00:00:00 2001 From: Joe Dong Date: Thu, 23 Feb 2023 09:33:09 +0800 Subject: [PATCH] rewrite install rules script --- orbbec_camera/scripts/install.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/orbbec_camera/scripts/install.sh b/orbbec_camera/scripts/install.sh index 802e11e6..4552be83 100755 --- a/orbbec_camera/scripts/install.sh +++ b/orbbec_camera/scripts/install.sh @@ -1,19 +1,18 @@ #!/bin/sh -# Check if user is root/running with sudo -if [ `whoami` != root ]; then - echo Please run this script with sudo - exit +set -e + +# Check if script is running as root or with sudo +if [ "$(id -u)" -ne 0 ]; then + echo "Please run this script with sudo" + exit 1 fi -ORIG_PATH=`pwd` -cd `dirname $0` -SCRIPT_PATH=`pwd` -cd $ORIG_PATH - -if [ "`uname -s`" != "Darwin" ]; then +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +if [ "$(uname -s)" != "Darwin" ]; then # Install UDEV rules for USB device - cp ${SCRIPT_PATH}/99-obsensor-libusb.rules /etc/udev/rules.d/99-obsensor-libusb.rules - echo "usb rules file install at /etc/udev/rules.d/99-obsensor-libusb.rules" + cp "$SCRIPT_DIR/99-obsensor-libusb.rules" /etc/udev/rules.d/99-obsensor-libusb.rules + echo "USB rules file installed at /etc/udev/rules.d/99-obsensor-libusb.rules" fi -echo "exit" \ No newline at end of file + +echo "Done"