diff --git a/installer/tools/setup.sh b/installer/tools/setup.sh index 9230df8c..05d74f60 100644 --- a/installer/tools/setup.sh +++ b/installer/tools/setup.sh @@ -4,181 +4,266 @@ Installs the Sensing SDK. .DESCRIPTION -This script downloads and installs the Sensing SDK on Ubuntu. You can specify a particular version or the latest version will be installed by default. +This script downloads and installs the Sensing SDK components. You can specify a particular version or the latest version will be installed by default. .PARAMETER version/-v Specifies the version of the Sensing SDK to be installed. Default is 'latest'. +.PARAMETER user +It used to be the flag to switch .zip version and .msi version of the package. Deprecated as of v24.05.05. + .PARAMETER install-opencv If set, the script will also install OpenCV. This is not done by default. .PARAMETER install-path -The installation path for the Sensing SDK.Default is the /opt/sensing-dev directory - -.PARAMETER develop-test -Requires this option for non-tagged GitHub Workflow.' +The installation path for the Sensing SDK. Default is the sensing-dev-installer directory is the /opt/sensing-dev directory + +' + +installerName="sensing-dev" +repositoryName="Sensing-Dev/sensing-dev-installer" +baseUrl="https://github.com/$repositoryName/releases/download/" + +version="" +installPath="" +InstallOpenCV=false + +# Deprecated as of v24.05.05 +user="" + +# debug options +verbose=false +debugScript=false +configPath="" +archiveAravis="" +archiveAravisDep="" +archiveIonKit="" +archiveGenDCSeparator="" +archiveOpenCV="" +uninstallerPath="" + +while [[ "$#" -gt 0 ]]; do + case $1 in + -v | --version) version="$2"; shift ;; + --verbose) verbose=true ;; + --user) user="$2"; shift ;; + --installPath) installPath="$2"; shift ;; + --InstallOpenCV) InstallOpenCV=true ;; + --debugScript) debugScript=true ;; + --configPath) configPath="$2"; shift ;; + --archiveAravis) archiveAravis="$2"; shift ;; + --archiveAravisDep) archiveAravisDep="$2"; shift ;; + --archiveIonKit) archiveIonKit="$2"; shift ;; + --archiveGenDCSeparator) archiveGenDCSeparator="$2"; shift ;; + --archiveOpenCV) archiveOpenCV="$2"; shift ;; + --uninstallerPath) uninstallerPath="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done -set -eo pipefail -if [ "$EUID" -ne 0 ] - then echo "Please run as root" - exit -fi +verbose() { + if [[ $verbose == true ]]; then + echo "[verbose]" $1 + fi +} +info(){ + echo "[info] " $1 +} +error(){ + echo "[error] " $1 +} -unset ion_kit_config -declare -A ion_kit_config=( # Declare an associative array with default values - ["v24.05.04"]="v1.8.2" - ["v24.05.05"]="v1.8.2" - ["v24.05.06"]="v1.8.3" -) - -unset gendc_separator_config -declare -A gendc_separator_config=( # Declare an associative array with default values - ["v24.05.04"]="v0.2.6" - ["v24.05.05"]="v0.2.7" - ["v24.05.06"]="v0.2.8" -) - -EARLIEST_STABLE_SDK="v24.05.04" - -INSTALL_PATH=/opt/sensing-dev - -while true; do - case "$1" in - --install-opencv ) - InstallOpenCV=true; - shift ;; - -v | --version ) - Version="$2"; - shift; shift ;; - --install-path ) - INSTALL_PATH="$2"; - shift; shift ;; - --develop-test ) - NOT_DL_VERSION_INFO=true; - shift ;; - -- ) - shift; break ;; - * ) - break ;; - esac -done +debug(){ + echo "[debug] " $1 +} -# if version is not specified, get the latest ######################################################### -get_sensing-dev_latest_release() { +get_latest_version() { curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api grep '"tag_name":' | # Get tag line sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value } -if [ -z "$Version" ]; then - Repository="Sensing-Dev/sensing-dev-installer" - Version=`get_sensing-dev_latest_release $Repository` - if [[ "$Version" == "v24.01.04" ]]; then - Version="$EARLIEST_STABLE_SDK" - fi +verbose "version: $version" +verbose "user: $user" +verbose "installPath: $installPath" +verbose "verbose: $verbose" +verbose "InstallOpenCV: $InstallOpenCV" +verbose "debugScript: $debugScript" +verbose "configPath: $configPath" +# verbose "archiveAravis: $archiveAravis" +# verbose "archiveAravisDep: $archiveAravisDep" +# verbose "archiveIonKit: $archiveIonKit" $verbose +# verbose "archiveGenDCSeparator: $archiveGenDCSeparator" +# verbose "archiveOpenCV: $archiveOpenCV" + +################################################################################ +# Check Admin +################################################################################ +set -eo pipefail +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit fi -if [[ $Version =~ ^v[0-9]+\.[0-9]+\.[0-9]+-.*$ ]]; then - Alt_Version=$(echo $Version | sed 's/-.*//'); +################################################################################ +# Install Dependencies +################################################################################ +if [[ $debugScript == true ]]; then + debug "Skip install dependencies... (debugScript)" else - Alt_Version=$Version; + echo "**********" + echo "Install Dependencies" + echo "**********" + apt-get -y upgrade && apt-get update && apt-get install -y \ + curl gzip git python3-pip glib2.0 libxml2-dev \ + libgirepository1.0-dev libnotify-dev \ + libunwind-dev \ + libgstreamer1.0-dev \ + libgstreamer-plugins-base1.0-dev \ + libgtk-3-dev \ + gtk-doc-tools \ + jq + echo "**********" fi -echo "========" -echo This script will try to $Version and its same as $Alt_Version - -if [[ -z "${ion_kit_config[$Alt_Version]+_}" ]]; then - echo "Error: Version '$Alt_Version' is not found from following versions for Linux" - for v in "${!ion_kit_config[@]}"; do - echo $v - done - exit 1 +################################################################################ +# Set default installPath if not provide +################################################################################ +if [ -z "$installPath" ]; then + installPath=/opt/sensing-dev +fi +verbose "installPath = $installPath" + +################################################################################ +# Create install directory +################################################################################ +mkdir -p $installPath +if [ -d $installPath ]; then + info "Uninstall old sensing-dev" + rm -r -f $installPath/* fi +################################################################################ +# Get Version & config of components +################################################################################ +configFileName="config_Linux.json" +if [ -n "$configPath" ]; then + verbose "Found local $configFileName = $configPath" + config_content=$(cat $configPath) + version_from_config=$(echo $(echo $config_content | jq -r '.sensing_dev') | jq -r '.version') + + if [ -n "$version" ]; then + verbose "User set verion = $version" + if [ $version_from_config != $version ]; then + error "Set vertion ($version) and config version ($version_from_config) have a conflict." + exit 1 + fi + else + version=$version_from_config + fi +fi -####################################################################################################### - -ION_KIT_VERSION=${ion_kit_config["$Alt_Version"]} -GENDC_SEPARATOR_VERSION=${gendc_separator_config["$Alt_Version"]} +if [ -z "$version" ]; then + verbose "Getting the latest version..." + version=`get_latest_version $repositoryName` +fi -mkdir -p $INSTALL_PATH +info "Sensing-Dev $version will be installed." -echo "**********" -echo "Install Dependencies" -echo "**********" -apt-get -y upgrade && apt-get update && apt-get install -y curl gzip git python3-pip glib2.0 libxml2-dev \ - libgirepository1.0-dev libnotify-dev \ - libunwind-dev \ - libgstreamer1.0-dev \ - libgstreamer-plugins-base1.0-dev \ - libgtk-3-dev \ - gtk-doc-tools +if [ -z "$configPath" ]; then + info "Download SDK Component config file..." + configURL="$baseUrl$version/$configFileName" + configPath="$installPath/tmp/$configFileName" + mkdir -p "$installPath/tmp" + curl -L $configURL -o "$configPath" + config_content=$(cat $configPath) +fi +################################################################################ +# Dlownload each component to $tempWorkDir & extract to $tempExtractionPath +################################################################################ +keys=('aravis' 'ion_kit' 'gendc_separator') +for key in "${keys[@]}" +do + comp_info=$(echo $config_content | jq -r ".$key") + comp_name=$(echo $comp_info | jq -r '.name') + comp_version=$(echo $comp_info | jq -r '.version') + comp_url=$(echo $comp_info | jq -r '.pkg_url') + + echo + echo "**********" + echo "Install $comp_name=$comp_version" + echo "**********" + if [ $key == 'gendc_separator' ]; then + archive_name="gendc_separator.zip" + curl -L $comp_url -o $archive_name && unzip -o gendc_separator.zip -d $installPath/include && rm $archive_name + else + curl -L $comp_url | tar zx -C $installPath --strip-components 1 + fi +done -echo -echo "**********" -echo "Install aravis=0.8.30" -echo "**********" +if [ -n "$InstallOpenCV" ]; then + key='opencv' + comp_info=$(echo $config_content | jq -r ".$key") + comp_name=$(echo $comp_info | jq -r '.name') + comp_version=$(echo $comp_info | jq -r '.version') + comp_url=$(echo $comp_info | jq -r '.pkg_url') + echo + echo "**********" + echo "Install $comp_name=$comp_version" + echo "**********" + mkdir -p "$installPath/tmp" + curl -L https://ion-kit.s3.us-west-2.amazonaws.com/dependencies/OpenCV-4.5.2-x86_64-gcc75.sh -o "$installPath/tmp/OpenCV.sh" + sh "$installPath/tmp/OpenCV.sh" --skip-license --prefix=$installPath +fi -curl -L https://github.com/Sensing-Dev/aravis/releases/download/internal-0.8.30/aravis-internal-0.8.30-x86-64-linux.tar.gz| tar zx -C $INSTALL_PATH --strip-components 1 +################################################################################ +# Create udev rule file under rules.d +################################################################################ +info "Creating udev rule file..." mkdir -p /etc/udev/rules.d cat > /etc/udev/rules.d/80-aravis.rules << EOS SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", MODE:="0666", TAG+="uaccess", TAG+="udev-acl" EOS -echo "INFO: Aravis installed" - -# Install OpenCV if the flag is set to true -if [ "$InstallOpenCV" = true ]; then - echo - echo "**********" - echo "Install OpenCV" - echo "**********" - TMPDIR=$(mktemp -d) - curl -L https://ion-kit.s3.us-west-2.amazonaws.com/dependencies/OpenCV-4.5.2-x86_64-gcc75.sh -o ${TMPDIR}/OpenCV.sh - sh ${TMPDIR}/OpenCV.sh --skip-license --prefix=$INSTALL_PATH - echo "INFO: OpenCV installed" -fi -echo -echo "**********" -echo "Install ion-kit=${ION_KIT_VERSION/v/''}" -echo "**********" -if [ ${ION_KIT_VERSION} = v0.3.6 ]; then - curl -L https://github.com/fixstars/ion-kit/releases/download/${ION_KIT_VERSION}/ion-kit-${ION_KIT_VERSION/v/''}-Linux.tar.gz | tar xz -C $INSTALL_PATH --strip-components 1 -else - curl -L https://github.com/fixstars/ion-kit/releases/download/${ION_KIT_VERSION}/ion-kit-${ION_KIT_VERSION/v/''}-x86-64-linux.tar.gz | tar xz -C $INSTALL_PATH --strip-components 1 -fi -echo -echo "**********" -echo "Install GenDCSeparator=${GENDC_SEPARATOR_VERSION/v/''}" -echo "**********" -curl -L https://github.com/Sensing-Dev/GenDC/releases/download/${GENDC_SEPARATOR_VERSION}/gendc_separator_${GENDC_SEPARATOR_VERSION}_win64.zip -o gendc_separator.zip && unzip -o gendc_separator.zip -d $INSTALL_PATH/include && rm gendc_separator.zip - -if [ "$NOT_DL_VERSION_INFO" = true ]; then - echo - echo "**********" - echo "develop-test mode doesn't DL version_info.json" - echo "**********" -else - if [[ "$Version" == "v24.05.04" ]]; then - echo - echo "**********" - echo "This version doesn't support version_info.json" - echo "**********" - else - # DL version_info.json - echo - echo "**********" - echo "Download SDK version info... See $INSTALL_PATH/version_info.json for the detail." - echo "**********" - curl -L https://github.com/Sensing-Dev/sensing-dev-installer/releases/download/${Version}/version_info.json -o $INSTALL_PATH/version_info.json - fi +################################################################################ +# Generate version_info.json +################################################################################ +info "Generating version_info.json..." +comp_info=$(echo $config_content | jq -r ".sensing_dev") +comp_name=$(echo $comp_info | jq -r '.name') +comp_version=$(echo $comp_info | jq -r '.version') +version_info_content=$(jq -n --arg $comp_name $comp_version '$ARGS.named') + +compVersionInfo=$(jq -n '') +keys=('aravis' 'ion_kit' 'gendc_separator') +for key in "${keys[@]}" +do + comp_info=$(echo $config_content | jq -r ".$key") + comp_name=$(echo $comp_info | jq -r '.name') + comp_version=$(echo $comp_info | jq -r '.version') + compVersionInfo=$(echo $compVersionInfo | jq --arg $comp_name $comp_version '. += $ARGS.named') +done + +if [ -n "$InstallOpenCV" ]; then + key='opencv' + comp_info=$(echo $config_content | jq -r ".$key") + comp_name=$(echo $comp_info | jq -r '.name') + comp_version=$(echo $comp_info | jq -r '.version') + compVersionInfo=$(echo $compVersionInfo | jq --arg $comp_name $comp_version '. += $ARGS.named') fi -echo -echo "Successfully Finished." \ No newline at end of file +version_info_content=$(echo "$version_info_content" | jq --argjson comp "$compVersionInfo" '.["SDK components"] = $comp') + +echo $version_info_content | jq '.' --indent 4 > "$installPath/version_info.json" + +echo "Successfully Finished." +exit 0 + +