Skip to content

Instantly share code, notes, and snippets.

@534o
Created October 13, 2017 06:08
Show Gist options
  • Save 534o/3376fa10c66095bd5837a0ef49e2a689 to your computer and use it in GitHub Desktop.
Save 534o/3376fa10c66095bd5837a0ef49e2a689 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage {
echo >&2 "usage: $0 [HOSTNAME_QNX (default:nextage)] [USERNAME_QNX (default:torkuser)]"
echo >&2 " [-h|--help] print this message"
exit 0
}
# command line parse. If the num of argument is not as expected, call usage func.
OPT=`getopt -o h -l help -- $*`
if [ $# -gt 2 ]; then
usage
fi
eval set -- $OPT
while [ -n "$1" ] ; do
case $1 in
-h|--help) usage ;;
--) shift; break;;
*) echo "Unknown option($1)"; usage;;
esac
done
set -e
set -x
HOSTNAME_QNX=$1
HOSTNAME_QNX=${HOSTNAME_QNX:="nextage"}
USERNAME_QNX=$2
USERNAME_QNX=${USERNAME_QNX:="tork"}
DATE=`date +"%Y%m%d-%H%M%S"`
TMP_FOLDER_ROOT=/tmp/HiroNXO_install
TMP_FOLDER=$TMP_FOLDER_ROOT/Suppl
NAME_LOGFILE=robot-install-qnx-suppl_${HOSTNAME_QNX}_${DATE}.log
ls -al
[ `ls -al robot-install-*-qnx-*.exe | wc -l` == 1 ] || (echo ";; found multiple robot-install-qnx-*.exe files. Please leave the one you use in the current folder, and re-run this script. Exiting for now."; exit 1;)
INSTALLER_NAME=`ls robot-install-*-qnx-*.exe`
# DESCRIPTION: Run on Ubuntu a QNX-specific binary `robot-install-qnx-%MAC_ADDR_QNX% %HOST_QNX% %USER_QNX%`
# (discussed at https://github.com/tork-a/delivery/issues/33#issuecomment-67120688).
# OUTPUT: Extracted hrpsys files under /tmp/$TMP_FOLDER-$DATE
#
# Steps taken:
## 1. Check if MAC registered in the binary matches with the QNX host this script is connecting to.
##ssh $USERNAME_QNX@$HOSTNAME_QNX export MACADDR_QNX_OBTAINED=`ifconfig en0 | awk '/address/ {print $NF}'`
##if [ MACADDR_QNX != MACADDR_QNX_OBTAINED ]
##then
## echo "MAC ADDR didn't match:\n\tInput: $MACADDR_QNX\n\t"
## exit 0
echo " * 2. Check if the installer file $INSTALLER_NAME exists and is executable."
chmod a+x $INSTALLER_NAME
test -x $INSTALLER_NAME || (echo "Installer file $INSTALLER_NAME does not exist at the current directory, or is not executable. Returning."; exit 1)
echo " * 3. Send the binary $INSTALLER_NAME into QNX under /tmp dir. This might take some time depending on the network."
sshpass -p tork scp ./$INSTALLER_NAME $USERNAME_QNX@$HOSTNAME_QNX:/home/$USERNAME_QNX
echo " * 4. On QNX under /tmp dir, extract binary file. This will yield opt/jsk folder under the temporary folder.*\nThen Move the extracted files to /opt/jsk/\${HRPSYS_VER} and make symlink from /opt/jsk to each sub folder."
commands="
source ~/.profile || { echo '.profile not found. Copying from /etc/profile.'; cp /etc/profile ~/.profile; . ~/.profile; };
env;
trap 'exit 1' ERR;
set -x;
[ -d $TMP_FOLDER ] && rm -fr $TMP_FOLDER;
mkdir -p $TMP_FOLDER && chmod 755 $TMP_FOLDER && cd $TMP_FOLDER;
chmod a+rx /home/$USERNAME_QNX/$INSTALLER_NAME;
mv /home/$USERNAME_QNX/$INSTALLER_NAME .;
[ -d ./opt/jsk ] && rm -fr ./opt/jsk;
echo \"At \"; pwd; echo \" \* Run the installer $INSTALLER_NAME \"; ./$INSTALLER_NAME;
echo \"* Extracted files under $HOSTNAME_QNX:$TMP_FOLDER: \" && { ls . || echo \"ls . failed.\"; exit 1};
HRPSYS_VER=`(cd ./opt/jsk && ls | head -1)`;
[ \"${HRPSYS_VER}\" != "" -a -e ./opt/jsk/${HRPSYS_VER} ] || (echo \"Failed to get HRPSYS VERSION\"; exit 1);
echo \"At \"; pwd; echo \" \* Move files into /opt/jsk/$HRPSYS_VER. If the folder already exists, that means we have to back up that folder and stash it aside. \";
ls -al ./opt/jsk/;
[ -e /opt/jsk/${HRPSYS_VER} ] && mv /opt/jsk/${HRPSYS_VER} /opt/jsk/${HRPSYS_VER}.`date +\"%Y%m%d-%H%M%S\"`;
ls -al /opt/jsk/;
cp -vR ./opt/jsk/${HRPSYS_VER}/ /opt/jsk/ || ( echo \"Failed to complete moving ./opt/jsk/$HSPSYS_VER into /opt/jsk/$HRPSYS_VER. However, most likely files are moved. So judgement call is made, to move forward. \".; );
ls -al /opt/jsk/;
[ -d /opt/jsk/$HRPSYS_VER ] || ( echo '** Directory /opt/jsk/$HRPSYS_VER does not exist. hrpsys is not installed properly. Make sure any error message above. Abort.'; exit 1; );
echo \"* Note: Symbolic link from folders in /opt/jsk to the ones that contain specific hrpsys version. Sym-linking didn't work from the directory. *\";
cd /opt/jsk;
ln -sf /opt/jsk/$HRPSYS_VER/* . && { echo '===== Done. /opt/jsk is now structured as follows: ====='; ls -l /opt/jsk; };
echo \"* Files now extracted under ./opt/jsk. Remove /tmp/$TMP_FOLDER in case of the future execution. \" && rm -fr /tmp/$TMP_FOLDER;
echo '*****************************';
echo '*** Operation successful. ***';
echo '*****************************';
echo '';
echo 'Next, reboot QNX. Follow QNX-hrpsys installation guide (http://wiki.ros.org/rtmros_nextage/Tutorials/Install%20or%20update%20software%20on%20ControllerBox).';
"
sshpass -p tork ssh $USERNAME_QNX@$HOSTNAME_QNX -t $commands 2>&1 | tee ${NAME_LOGFILE}
gedit ${NAME_LOGFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment