|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +function usage() |
| 4 | +{ |
| 5 | + echo "Usage: $0 [-w workspace_directory] [-r rosinstall_path] [-t robot_type] [-s skip keys] [-h] [-u] [-l] |
| 6 | +
|
| 7 | +optional arguments: |
| 8 | + -h show this help |
| 9 | + -w WORKSPACE_PATH specify target workspace |
| 10 | + -r ROSINTALL_PATH rosinstall path |
| 11 | + -t ROBOT robot type |
| 12 | + -s SKIP_KEYS rosdep install skip keys |
| 13 | + -u do not run apt-get upgrade and rosdep install |
| 14 | + -l do not send a mail |
| 15 | +" |
| 16 | +} |
| 17 | + |
| 18 | +function get_full_path() |
| 19 | +{ |
| 20 | + echo "$(cd $(dirname $1) && pwd)/$(basename $1)" |
| 21 | +} |
| 22 | + |
| 23 | +ROSDEP_INSTALL=true |
| 24 | +SEND_MAIL=true |
| 25 | +WORKSPACE=$(get_full_path $HOME/ros/$ROS_DISTRO) |
| 26 | + |
| 27 | +while getopts w:r:t:s:ulh OPT |
| 28 | +do |
| 29 | + case $OPT in |
| 30 | + w) |
| 31 | + WORKSPACE=$(get_full_path $OPTARG) |
| 32 | + ;; |
| 33 | + r) |
| 34 | + ROSINSTALL=$(get_full_path $OPTARG) |
| 35 | + ;; |
| 36 | + t) |
| 37 | + ROBOT_TYPE=$OPTARG |
| 38 | + ;; |
| 39 | + s) |
| 40 | + SKIP_KEYS=$OPTARG |
| 41 | + ;; |
| 42 | + u) |
| 43 | + ROSDEP_INSTALL=false |
| 44 | + ;; |
| 45 | + l) |
| 46 | + SEND_MAIL=false |
| 47 | + ;; |
| 48 | + h) |
| 49 | + usage |
| 50 | + exit 1 |
| 51 | + ;; |
| 52 | + *) |
| 53 | + usage |
| 54 | + exit 1 |
| 55 | + ;; |
| 56 | + esac |
| 57 | +done |
| 58 | + |
| 59 | +if [ "$WORKSPACE" = "" ]; then |
| 60 | + echo "Please set valid workspace -w $WORKSPACE" |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | +if [ "$ROSINSTALL" = "" ]; then |
| 64 | + echo "Please set valid rosinstall -r $ROSINSTALL" |
| 65 | + exit 1 |
| 66 | +fi |
| 67 | +if [ "$ROBOT_TYPE" = "" ]; then |
| 68 | + echo "Please set valid robot type -t $ROBOT_TYPE" |
| 69 | + exit 1 |
| 70 | +fi |
| 71 | + |
| 72 | + |
| 73 | +. $WORKSPACE/devel/setup.bash |
| 74 | +# Filename should end with .txt to preview the contents in a web browser |
| 75 | +LOGFILE=$WORKSPACE/update_workspace.txt |
| 76 | + |
| 77 | +TMP_MAIL_BODY_FILE=/tmp/update_workspace_mailbody.txt |
| 78 | + |
| 79 | +{ |
| 80 | +set -x |
| 81 | +# Update workspace |
| 82 | + |
| 83 | +wstool foreach -t $WORKSPACE/src --git 'git stash' |
| 84 | +wstool foreach -t $WORKSPACE/src --git 'git fetch origin --prune' |
| 85 | +wstool update -t $WORKSPACE/src jsk-ros-pkg/jsk_robot --delete-changed-uris |
| 86 | +ln -sf $ROSINSTALL $WORKSPACE/src/.rosinstall |
| 87 | +wstool update -t $WORKSPACE/src --delete-changed-uris |
| 88 | +# Forcefully checkout specified branch |
| 89 | +wstool foreach -t $WORKSPACE/src --git --shell 'branchname=$(git rev-parse --abbrev-ref HEAD); if [ $branchname != "HEAD" ]; then git reset --hard HEAD; git checkout origin/$branchname; git branch -D $branchname; git checkout -b $branchname --track origin/$branchname; fi' |
| 90 | +wstool update -t $WORKSPACE/src |
| 91 | +WSTOOL_UPDATE_RESULT=$? |
| 92 | +# Rosdep Install |
| 93 | +if [ "${ROSDEP_INSTALL}" == "true" ]; then |
| 94 | + sudo apt-get update -y; |
| 95 | + rosdep update; |
| 96 | + rosdep install --from-paths $WORKSPACE/src --ignore-src -y -r --skip-keys "$SKIP_KEYS"; |
| 97 | + ROSDEP_INSTALL_RESULT=$?; |
| 98 | +else |
| 99 | + ROSDEP_INSTALL_RESULT=0; |
| 100 | +fi |
| 101 | +# Build workspace |
| 102 | +cd $WORKSPACE |
| 103 | +catkin clean aques_talk collada_urdf_jsk_patch libcmt -y |
| 104 | +catkin init |
| 105 | +catkin config -DCMAKE_BUILD_TYPE=Release |
| 106 | +catkin build --continue-on-failure |
| 107 | +CATKIN_BUILD_RESULT=$? |
| 108 | +# Send mail |
| 109 | +echo "" > $TMP_MAIL_BODY_FILE |
| 110 | +if [ $WSTOOL_UPDATE_RESULT -ne 0 ]; then |
| 111 | + echo "Please wstool update workspace manually.\n" >> $TMP_MAIL_BODY_FILE |
| 112 | +fi |
| 113 | +if [ $ROSDEP_INSTALL_RESULT -ne 0 ]; then |
| 114 | + echo "Please install dependencies manually.\n" >> $TMP_MAIL_BODY_FILE |
| 115 | +fi |
| 116 | +if [ $CATKIN_BUILD_RESULT -ne 0 ]; then |
| 117 | + echo "Please catkin build workspace manually.\n" >> $TMP_MAIL_BODY_FILE |
| 118 | +fi |
| 119 | +set +x |
| 120 | +} 2>&1 | tee $LOGFILE |
| 121 | + |
| 122 | +# MAIL_BODY variable cannot be set directly in a subshell. So it is set from temporary mail body text file. |
| 123 | +# The mail body text is put as $TMP_MAIL_BODY_FILE. |
| 124 | +# See https://github.com/jsk-ros-pkg/jsk_robot/issues/1569 |
| 125 | +MAIL_BODY=$(cat $TMP_MAIL_BODY_FILE) |
| 126 | +echo "MAIL_BODY: $MAIL_BODY" |
| 127 | + |
| 128 | +if [ -n "$MAIL_BODY" ] && [ "${SEND_MAIL}" == "true" ]; then |
| 129 | + echo "Sent a mail" |
| 130 | + rostopic pub -1 /email jsk_robot_startup/Email "header: |
| 131 | + seq: 0 |
| 132 | + stamp: {secs: 0, nsecs: 0} |
| 133 | + frame_id: '' |
| 134 | +subject: 'Daily workspace update fails' |
| 135 | +body: |
| 136 | +- {type: 'text', message: '${MAIL_BODY}', file_path: '', img_data: '', img_size: 0} |
| 137 | +sender_address: '$(hostname)@jsk.imi.i.u-tokyo.ac.jp' |
| 138 | +receiver_address: '$ROBOT_TYPE@jsk.imi.i.u-tokyo.ac.jp' |
| 139 | +smtp_server: '' |
| 140 | +smtp_port: '' |
| 141 | +attached_files: ['$LOGFILE']" |
| 142 | +fi |
0 commit comments