#!/bin/sh # # @file pkg_install_raspbian.sh # @brief OpenRTM-aist dependent packages install script for Debian # @author Noriaki Ando # Nobu Kawauchi # VERSION=2.0.0.04 FILENAME=pkg_install_raspbian.sh #--------------------------------------- # usage #--------------------------------------- usage() { cat < language or tool [c++|python|java|rtshell|all] all install packages of all the supported languages and tools -r install robot component runtime -d install robot component developer [default] -t OpenRTM-aist old version number -s install tool_packages for build source packages -c install tool_packages for core developer -u uninstall packages --yes force yes --help, -h print this --version print version number EOF } version() { echo ${VERSION} } #--------------------------------------- # パッケージリスト #--------------------------------------- default_reposerver="openrtm.org" reposervers="openrtm.org" reposerver="" RTM_OLD_VER=1.2.1 old_openrtm_devel="openrtm-aist-doc=$RTM_OLD_VER-0 openrtm-aist-idl=$RTM_OLD_VER-0 openrtm-aist-dev=$RTM_OLD_VER-0" old_openrtm_runtime="openrtm-aist=$RTM_OLD_VER-0 openrtm-aist-example=$RTM_OLD_VER-0" old_openrtm_py_devel="openrtm-aist-python-doc=$RTM_OLD_VER-0" old_openrtm_py_runtime="openrtm-aist-python=$RTM_OLD_VER-0 openrtm-aist-python-example=$RTM_OLD_VER-0" openrtm2_py="openrtm2-python3-doc openrtm2-python3-example openrtm2-python3" openrtm2_java="openrtm2-java-doc openrtm2-java-example openrtm2-java" #--------------------------------------- C++ autotools="autoconf libtool libtool-bin" base_tools="bc iputils-ping net-tools zip" common_devel="python3-yaml" cxx_devel="gcc g++ make $common_devel" cmake_tools="cmake doxygen" build_tools="subversion git" deb_pkg="uuid-dev libboost-filesystem-dev" pkg_tools="build-essential debhelper devscripts" omni_devel="libomniorb4-dev omniidl" omni_runtime="omniorb-nameserver" openrtm_devel="openrtm-aist-doc openrtm-aist-idl openrtm-aist-dev" openrtm_runtime="openrtm-aist openrtm-aist-example" #--------------------------------------- Python omnipy="omniidl-python3" python_runtime="python3 python3-omniorb-omg" python_devel="python3-pip $cmake_tools $base_tools $omnipy $common_devel" openrtm_py_devel="openrtm-aist-python3-doc" openrtm_py_runtime="openrtm-aist-python3 openrtm-aist-python3-example" #--------------------------------------- Java java_build="ant" openrtm_j_devel="openrtm-aist-java-doc" openrtm_j_runtime="openrtm-aist-java openrtm-aist-java-example" #--------------------------------------- # Script options, argument analysis #--------------------------------------- init_param() { OPT_RT=false OPT_DEV=false OPT_SRC=false OPT_CORE=false OPT_FLG=true OPT_OLD_RTM=false install_pkgs="" uninstall_pkgs="" arg_all=false arg_cxx=false arg_python=false arg_java=false arg_rtshell=false err_message="" } check_arg() { local arg=$1 arg_err=0 case "$arg" in all ) arg_all=true ;; c++ ) arg_cxx=true ;; python ) arg_python=true ;; java ) arg_java=true ;; rtshell ) arg_rtshell=true ;; *) arg_err=-1 ;; esac } set_old_rtm_pkgs() { local ver=$1 LF='\n' local msg tmp arg_err="" if test "x$ver" = "x$RTM_OLD_VER" ; then OPT_OLD_RTM=true if test "x$arg_cxx" = "xtrue" || test "x$arg_all" = "xtrue" ; then openrtm_devel=$old_openrtm_devel openrtm_runtime=$old_openrtm_runtime arg_cxx=true fi if test "x$arg_python" = "xtrue" || test "x$arg_all" = "xtrue" ; then omnipy="omniidl-python" python_runtime="python python-omniorb-omg" python_devel="python-pip $cmake_tools $base_tools $omnipy" openrtm_py_devel=$old_openrtm_py_devel openrtm_py_runtime=$old_openrtm_py_runtime arg_python=true fi if test "x$arg_java" = "xtrue" || test "x$arg_all" = "xtrue" ; then msg="[ERROR] Installation of older version of OpenRTM-aist-Java is not supported." echo $msg tmp="$err_message$LF$msg" err_message=$tmp arg_java=false fi if test "x$arg_rtshell" = "xtrue" || test "x$arg_all" = "xtrue" ; then msg="[ERROR] Installation of older version of rtshell is not supported." echo $msg tmp="$err_message$LF$msg" err_message=$tmp arg_rtshell=false fi else arg_err=$ver fi } get_opt() { # オプション指定が無い場合のデフォルト設定 if [ $# -eq 0 ] ; then arg_all=true OPT_DEV=true fi arg_num=$# OPT=`getopt -o l:rcsdt:hu -l help,yes,version -- $@` > /dev/null 2>&1 # return code check if [ $? -ne 0 ] ; then echo "[ERROR] Invalid option '$1'" usage exit fi # 引数1個の場合 if [ $arg_num -eq 1 ] ; then # オプション指定が -r/-s/-c のみの場合 if test "x$1" = "x-r" || test "x$1" = "x-s" || test "x$1" = "x-c" ; then echo "[ERROR] Invalid option '$1'. '-l' option is required." usage exit fi if test "x$1" = "x--yes" ; then arg_all=true OPT_DEVEL=true fi fi eval set -- $OPT while true do case "$1" in -h|--help ) usage ; exit ;; --version ) version ; exit ;; --yes ) FORCE_YES=true ;; -l ) if [ -z "$2" ] ; then echo "$1 option requires an argument." 1>&2 exit fi check_arg $2 if [ "$arg_err" = "-1" ]; then echo "[ERROR] Invalid argument '$2'" usage exit fi shift ;; -t ) if [ -z "$2" ] ; then echo "$1 option requires an argument." 1>&2 exit fi set_old_rtm_pkgs $2 if test ! "x$arg_err" = "x" ; then echo "[ERROR] Invalid argument '$2'. Only $RTM_OLD_VER supported. " exit fi shift ;; -r ) OPT_RT=true ;; -d ) OPT_DEV=true ;; -s ) OPT_SRC=true ;; -c ) OPT_CORE=true ;; -u ) OPT_FLG=false ;; -- ) shift ; break ;; * ) echo "Internal Error" 1>&2 exit ;; esac shift done # オプション指定が -u のみの場合 if [ $arg_num -eq 1 ] ; then if test "x$OPT_FLG" = "xfalse" ; then arg_all=true fi fi } #--------------------------------------- # ロケールの言語確認 #--------------------------------------- check_lang() { lang="en" locale | grep ja_JP > /dev/null && lang="jp" if test "$lang" = "jp" ;then msg1="ディストリビューションを確認してください。\nDebianかUbuntu以外のOSの可能性があります。" msg2="コードネーム :" msg3="このOSはサポートしておりません。" msg4="OpenRTM-aist のリポジトリが登録されていません。" msg5="Source.list に OpenRTM-aist のリポジトリ: " msg6="を追加します。よろしいですか?(y/n)[y] " msg7="中断します。" msg8="ルートユーザーで実行してください。" msg9="インストール中です..." msg10="完了" msg11="アンインストール中です." else msg1="This distribution may not be debian/ubuntu." msg2="The code name is : " msg3="This OS is not supported." msg4="No repository entry for OpenRTM-aist is configured in your system." msg5="repository entry for OpenRTM-aist: " msg6="Do you want to add new repository entry for OpenRTM-aist in source.list? (y/n) [y] " msg7="Abort." msg8="This script should be run as root." msg9="Now installing: " msg10="done." msg11="Now uninstalling: " fi } #--------------------------------------- # コードネーム取得 #--------------------------------------- check_codename () { codename=`sed -n /VERSION_CODENAME=/p /etc/os-release` cnames=`echo "$codename" | sed 's/VERSION_CODENAME=//'` for c in $cnames; do if test -f "/etc/apt/sources.list"; then res=`grep $c /etc/apt/sources.list` else echo $msg1 exit fi if test ! "x$res" = "x" ; then code_name=$c fi done if test ! "x$code_name" = "x"; then echo $msg2 $code_name else echo $msg3 exit fi } #---------------------------------------- # 近いリポジトリサーバを探す #---------------------------------------- check_reposerver() { minrtt=65535 nearhost='' for host in $reposervers; do rtt=`ping -c 1 $host | grep 'time=' | sed -e 's/^.*time=\([0-9\.]*\) ms.*/\1/' 2> /dev/null` if test "x$rtt" = "x"; then rtt=65535 fi if test `echo "scale=2 ; $rtt < $minrtt" | bc` -gt 0; then minrtt=$rtt nearhost=$host fi done if test "x$nearhost" = "x"; then echo "Repository servers unreachable.", $hosts echo "Check your internet connection. (or are you using proxy?)" nearhost=$default_reposerver fi reposerver=$nearhost } #--------------------------------------- # リポジトリサーバ #--------------------------------------- create_srclist () { openrtm_repo="deb http://$reposerver/pub/Linux/raspbian/ $code_name main" } #--------------------------------------- # ソースリスト更新関数の定義 #--------------------------------------- update_source_list () { rtmsite=`grep "$openrtm_repo" /etc/apt/sources.list` if test "x$rtmsite" = "x" ; then echo $msg4 echo $msg5 echo " " $openrtm_repo read -p "$msg6" kick_shell if test "x$kick_shell" = "xn" ; then echo $msg7 exit 0 else echo $openrtm_repo | sudo tee -a /etc/apt/sources.list fi fi if test "x$FORCE_YES" = "xtrue" ; then apt-get install --assume-yes --allow-unauthenticated dirmngr else apt-get install dirmngr fi  # 公開鍵登録 wget -O- --secure-protocol=TLSv1_2 --no-check-certificate https://openrtm.org/pub/openrtm.key | sudo apt-key add - } #---------------------------------------- # パッケージインストール関数 #---------------------------------------- install_packages () { for p in $*; do echo $msg9 $p echo $install_pkgs | grep -x $p > /dev/null 2>&1 if [ $? -ne 0 ]; then tmp_pkg="$install_pkgs $p" install_pkgs=$tmp_pkg fi if test "x$FORCE_YES" = "xtrue" ; then sudo apt install --assume-yes --allow-unauthenticated $p else sudo apt install $p fi if [ $? -ne 0 ]; then echo $msg7 exit fi echo $msg10 echo "" done } #------------------------------------------------------------ # リストを逆順にする #------------------------------------------------------------ reverse () { for i in $*; do echo $i done | sed '1!G;h;$!d' } #---------------------------------------- # パッケージをアンインストールする #---------------------------------------- uninstall_packages () { for p in $*; do echo $msg11 $p echo $uninstall_pkgs | grep -x $p > /dev/null 2>&1 if [ $? -ne 0 ]; then tmp_pkg="$uninstall_pkgs $p" uninstall_pkgs=$tmp_pkg fi sudo apt --purge remove $p if test "$?" != 0; then sudo apt purge $p fi echo $msg10 echo "" done } #------------------------------------------------- # If OpenRTM-aist 2.0 is installed, uninstall its. # Target: openrtm2-python3, openrtm2-java # rtshell #------------------------------------------------- uninstall_openrtm20 () { if test "x$arg_python" = "xtrue" ; then res=`dpkg -l | grep openrtm2-python3` if test ! "x$res" = "x" ; then echo "Uninstall openrtm2-python3." sudo apt --purge remove $openrtm2_py uninstall_pkgs=$openrtm2_py fi fi if test "x$arg_java" = "xtrue" ; then res=`dpkg -l | grep openrtm2-java` if test ! "x$res" = "x" ; then echo "Uninstall openrtm2-java." sudo apt --purge remove $openrtm2_java tmp_pkg="$uninstall_pkgs $openrtm2_java" uninstall_pkgs=$tmp_pkg fi fi if test "x$arg_rtshell" = "xtrue" ; then res=`pip3 list | grep rtshell` if test ! "x$res" = "x" ; then echo "Uninstall rtshell." rtshell="rtshell-aist rtctree-aist rtsprofile-aist" sudo pip3 uninstall -y $rtshell tmp_pkg="$uninstall_pkgs rtshell" uninstall_pkgs=$tmp_pkg fi fi } #--------------------------------------- # set_package_content #--------------------------------------- set_package_content() { #--------------------------------------- C++ runtime_pkgs="$omni_runtime $openrtm_runtime" u_runtime_pkgs=$openrtm_runtime src_pkgs="$cxx_devel $cmake_tools $deb_pkg $base_tools $omni_runtime $omni_devel" u_src_pkgs="$omni_runtime $omni_devel" dev_pkgs="$runtime_pkgs $src_pkgs $openrtm_devel" u_dev_pkgs="$u_runtime_pkgs $openrtm_devel" core_pkgs="$src_pkgs $build_tools $pkg_tools" u_core_pkgs="$u_src_pkgs" #--------------------------------------- Python python_runtime_pkgs="$omni_runtime $python_runtime $openrtm_py_runtime" u_python_runtime_pkgs="$openrtm_py_runtime" python_dev_pkgs="$python_runtime_pkgs $python_devel $openrtm_py_devel" u_python_dev_pkgs="$u_python_runtime_pkgs $openrtm_py_devel" python_core_pkgs="$omni_runtime $python_runtime $python_devel $build_tools $pkg_tools" u_python_core_pkgs="$omni_runtime $omnipy" #--------------------------------------- Java java_runtime_pkgs="$omni_runtime $openrtm_j_runtime" u_java_runtime_pkgs="$openrtm_j_runtime" java_dev_pkgs="$java_runtime_pkgs $cmake_tools $base_tools $openrtm_j_devel" u_java_dev_pkgs="$u_java_runtime_pkgs $openrtm_j_devel" java_core_pkgs="$omni_runtime $cmake_tools $base_tools $build_tools $java_build $pkg_tools" u_java_core_pkgs="$omni_runtime" } #--------------------------------------- # install_proc #--------------------------------------- install_proc() { if test "x$arg_cxx" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_c="[c++] install tool_packages for core developer" install_packages $core_pkgs elif test "x$OPT_SRC" = "xtrue" ; then select_opt_c="[c++] install tool_packages for source packages" install_packages $src_pkgs elif test "x$OPT_RT" = "xtrue" ; then select_opt_c="[c++] install robot component runtime" install_packages $runtime_pkgs else select_opt_c="[c++] install robot component developer" install_packages $dev_pkgs fi fi if test "x$arg_python" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_p="[python] install tool_packages for core developer" install_packages $python_core_pkgs elif test "x$OPT_RT" = "xtrue" ; then select_opt_p="[python] install robot component runtime" install_packages $python_runtime_pkgs else select_opt_p="[python] install robot component developer" install_packages $python_dev_pkgs fi fi if test "x$arg_java" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_j="[java] install tool_packages for core developer" install_packages $java_core_pkgs elif test "x$OPT_RT" = "xtrue" ; then select_opt_j="[java] install robot component runtime" install_packages $java_runtime_pkgs else select_opt_j="[java] install robot component developer" install_packages $java_dev_pkgs fi fi if test "x$arg_rtshell" = "xtrue" ; then select_opt_shl="[rtshell] install" install_packages python3-pip rtshell_ret=`sudo python3 -m pip install rtshell-aist` if test "x$rtshell_ret" != "x"; then sudo rtshell_post_install -n else msg="\n[ERROR] Failed to install rtshell-aist." tmp="$err_message$msg" err_message=$tmp fi fi } #--------------------------------------- # uninstall_proc #--------------------------------------- uninstall_proc() { if test "x$arg_cxx" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_c="[c++] uninstall tool_packages for core developer" uninstall_packages `reverse $u_core_pkgs` elif test "x$OPT_SRC" = "xtrue" ; then select_opt_c="[c++] uninstall tool_packages for source packages" uninstall_packages `reverse $u_src_pkgs` elif test "x$OPT_RT" = "xtrue" ; then select_opt_c="[c++] uninstall robot component runtime" uninstall_packages `reverse $u_runtime_pkgs` else select_opt_c="[c++] uninstall robot component developer" uninstall_packages `reverse $u_dev_pkgs` fi fi if test "x$arg_python" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_p="[python] uninstall tool_packages for core developer" uninstall_packages `reverse $u_python_core_pkgs` elif test "x$OPT_RT" = "xtrue" ; then select_opt_p="[python] uninstall robot component runtime" uninstall_packages `reverse $u_python_runtime_pkgs` else select_opt_p="[python] uninstall robot component developer" uninstall_packages `reverse $u_python_dev_pkgs` fi fi if test "x$arg_java" = "xtrue" ; then if test "x$OPT_CORE" = "xtrue" ; then select_opt_j="[java] uninstall tool_packages for core developer" uninstall_packages `reverse $u_java_core_pkgs` elif test "x$OPT_RT" = "xtrue" ; then select_opt_j="[java] uninstall robot component runtime" uninstall_packages `reverse $u_java_runtime_pkgs` else select_opt_j="[java] uninstall robot component developer" uninstall_packages `reverse $u_java_dev_pkgs` fi fi if test "x$arg_rtshell" = "xtrue" ; then select_opt_shl="[rtshell] uninstall" rtshell_ret=`sudo python3 -m pip uninstall -y rtshell-aist rtctree-aist rtsprofile-aist` if test "x$rtshell_ret" = "x"; then msg="\n[ERROR] Failed to uninstall rtshell-aist." tmp="$err_message$msg" err_message=$tmp fi fi } #--------------------------------------- # print_option #--------------------------------------- print_option() { cat <