From 402827dce9f6e03bc70dbc46341c738247c0bee1 Mon Sep 17 00:00:00 2001 From: Pierre Quebriac Date: Thu, 1 Feb 2024 14:40:31 +0100 Subject: [PATCH] Update script for control panel --- rdm/install.sh | 94 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/rdm/install.sh b/rdm/install.sh index 75f2232..2a2f5e4 100755 --- a/rdm/install.sh +++ b/rdm/install.sh @@ -267,8 +267,9 @@ FORCE=0 WANTED_ROS="" WANTED_ARCH="" WANTED_UBUNTU="" +WITH_INTERFACE=1 -while getopts hyfr:a:v: opt; do +while getopts hyifr:a:v: opt; do case $opt in h) show_help @@ -376,10 +377,6 @@ fi # Check args validity check_values -PACKAGE_NAME="lll-rdm-${QUERY_DISTRO}" - -REGEX_QUERY="${PACKAGE_NAME}_[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+_$ARCH" - # Define variables. GH_API="https://api.github.com" GH_REPO="$GH_API/repos/3LawsRobotics/3laws" @@ -391,6 +388,9 @@ curl -o /dev/null -s $GH_REPO || { exit 1 } +PACKAGE_NAME="lll-rdm-${QUERY_DISTRO}" +REGEX_QUERY="${PACKAGE_NAME}_[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+_$ARCH" + # Read asset tags. RESPONSE=$(curl -s -H "application/vnd.github+json" $GH_TAGS) ASSET_NAME=$(echo "$RESPONSE" | grep -o "name.:.\+${REGEX_QUERY}.deb" | cut -d ":" -f2- | cut -d "\"" -f2-) @@ -446,13 +446,6 @@ if [[ -f "$ASSET_NAME" ]]; then STDLIB=libstdc++-13-dev STDLIB_INSTALLED=0 dpkg -l $STDLIB &>/dev/null && STDLIB_INSTALLED=1 - # SED_INSTALLED=0 - # dpkg -l sed &>/dev/null && SED_INSTALLED=1 - - # if [[ $STDLIB_INSTALLED == 0 || $SED_INSTALLED == 0 ]]; then - # cout "Installing dependencies..." - # $SUDO apt-get update &>/dev/null - # fi if [[ $STDLIB_INSTALLED == 0 ]]; then cout "Installing dependencies..." @@ -476,15 +469,74 @@ if [[ -f "$ASSET_NAME" ]]; then } fi - # if [[ $SED_INSTALLED == 0 ]]; then - # { - # $SUDO apt-get install -y sed &>/dev/null - # cwarn "Installed 'sed' on system!" - # } || { - # cerr "Failed to install 'sed' dependency!" - # exit 65 - # } - # fi + # Install package + $SUDO apt install -f ./"$ASSET_NAME" + cout "Success installation!" + cout "Remove artifacts" + rm "$ASSET_NAME" +else + cout "Package not found...If you encounter any issues, please contact: support@3lawsrobotics.com" +fi + +ros=ros2 +if [ $HAS_ROS1 == 1 ]; then + ros=ros1 +fi + +# Install Control Panel +PACKAGE_NAME="lll-control-panel-${ros}" +REGEX_QUERY="${PACKAGE_NAME}_[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+" + +RESPONSE=$(curl -s -H "application/vnd.github+json" $GH_TAGS) +ASSET_NAME=$(echo "$RESPONSE" | grep -o "name.:.\+${REGEX_QUERY}.deb" | cut -d ":" -f2- | cut -d "\"" -f2-) +ASSET_ID=$(echo "$RESPONSE" | grep -C3 "name.:.\+$REGEX_QUERY" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2-) + +[ "$ASSET_ID" ] || { + VALID_ASSETS=$(echo "$RESPONSE" | grep -o "name.:.\+lll-control-panel-${ros}_[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]_[a-zA-Z0-9]\+" | cut -d ":" -f2- | cut -d "\"" -f2-) + if [ -z "$VALID_ASSETS" ]; then + cerr "An error occurred, please contact support@3lawsrobotics.com" + else + echo -e "Error: Failed to get asset id, valid packages:\n$VALID_ASSETS" + fi + exit 1 +} + +GH_ASSET="$GH_REPO/releases/assets/$ASSET_ID" + +DOWNLOAD=0 +if [ -f "$ASSET_NAME" ]; then + cwarn "$ASSET_NAME already in your directory." + OVERWRITE=$(promptYesNo "Do you want to overwrite $ASSET_NAME in the current directory ?" 1) + if [ "$OVERWRITE" -eq 1 ]; then + cwarn "Removing $ASSET_NAME" + rm "$ASSET_NAME" + DOWNLOAD=1 + fi +else + DOWNLOAD=$(promptYesNo "Do you want to download $ASSET_NAME in the current directory" 1) +fi + +if [[ $DOWNLOAD == 1 ]]; then + echo "Downloading package..." >&2 + curl $CURL_ARGS -s -H 'Accept: application/octet-stream' "$GH_ASSET" + cout "Package $ASSET_NAME has been downloaded." +else + cwarn "Package not downloaded." +fi + +if [[ -f "$ASSET_NAME" ]]; then + INSTALL=$(promptYesNo "Do you want to install $ASSET_NAME ?" 1) + + if [ "$INSTALL" == 0 ]; then + cout "Package downloaded but not installed, if you choose to install manually, be sure to have libstd++13 on your system" + exit 0 + fi + + SUDO="" + if [[ "$EUID" -ne 0 && $INSTALL == 1 ]]; then + cwarn "To install the Control Panel automatically some commands must be run as sudo" + SUDO="sudo " + fi # Install package $SUDO apt install -f ./"$ASSET_NAME"