From: R. Steve McKown Date: Thu, 3 Dec 2009 20:45:13 +0000 (-0700) Subject: Add tinyos.sh, a utility for changing the active tree (TOSROOT). X-Git-Tag: patchset/2.1.1-4.4~24 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=c12b5fcaff502fb7454702c7a6c935c3fda62436 Add tinyos.sh, a utility for changing the active tree (TOSROOT). --- diff --git a/tinyos.sh b/tinyos.sh new file mode 100644 index 00000000..6886286b --- /dev/null +++ b/tinyos.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# +# Here we setup the environment variables needed by the tinyos make system. +# Users source this script from their shell to setup tinyos for their login, +# and may source again at any time to change which installed TinyOS source +# tree their code shall be built against. + +TOSCFG="$HOME/.tosrc" +TOSBASE=/opt/tinyos +RCFILES="$HOME/.bashrc $HOME/.shrc $HOME/.kshrc $HOME/.cshrc $ENV" + +# $1 is a directory or tos version number returns a fully rooted and valid +# TOSROOT, or nothing. +gettosroot() +{ + if [ -d "$1" -a -d "$1/tos" ]; then + echo $(cd $1 && pwd) + elif [ -d "$TOSBASE/$1" -a -d "$TOSBASE/$1/tos" ]; then + echo "$TOSBASE/$1" + fi +} + +# Update CLASSPATH by replacing the element value in $1 with the element value +# in $2. An empty $2 removes element $1, if present. An empty $1, or $1 not +# present, adds $2. +updclasspath() +{ + local jpath="support/sdk/java/tinyos.jar" + if [ -n "$1" -a -n "$2" ] && \ + echo "$CLASSPATH" | grep -q "$1/$jpath"; then + CLASSPATH=$(echo $CLASSPATH | sed -e "s|:$1/$jpath|:$2/$jpath|") + elif [ -n "$2" ]; then + CLASSPATH="$CLASSPATH:$2/$jpath" + elif [ -n "$1" ]; then + CLASSPATH=$(echo $CLASSPATH | sed -e "s|:$1/$jpath||") + fi + export CLASSPATH +} + +# Install a tinyos.sh invocation in user shell rc files. +installshrc() +{ + for rc in $RCFILES; do + if [ -f $rc ] && ! grep -q "$TOSBASE/tinyos.sh" $rc; then + echo "[ -d $TOSBASE ] && . $TOSBASE/tinyos.sh" >> $rc 2>/dev/null + fi + done +} + +# Uninstall the tinyos.sh invocation in user shell rc files. +uninstallshrc() +{ + for rc in $RCFILES; do + if [ -f $rc ] && grep -q "$TOSBASE/tinyos.sh" $rc; then + grep -v "$TOSBASE/tinyos.sh" $rc > $rc.$$ + mv -f $rc.$$ $rc + fi + done +} + +# List available TinyOS source versions +listsources() +{ + echo -n "Available sources:" + find $TOSBASE -maxdepth 2 -name tos -type d 2>/dev/null | sort | \ + while read dir; do + echo -n " $(basename -- $(dirname -- $dir))" + done + echo +} + +# MAIN + +if [ "$1" = "-t" ]; then + # Display TOS environment + if [ -z "$TOSROOT" ]; then + echo "tinyos: NOT configured" + else + echo "TOSROOT=$TOSROOT" + fi +elif [ "$1" = "-l" ]; then + listsources +elif [ "$1" = "-h" ]; then + cat < + + is the version of an installed source tree or the filesystem path to +a TinyOS source tree + +EOF1 + listsources + cat < "$TOSCFG" + installshrc + echo "tinyos: now using $newroot" + else + echo "tinyos: invalid version; try -h option" + fi + else + newroot=$(cat "$TOSCFG" 2>/dev/null) + if [ -z "$newroot" ]; then + echo "tinyos: NOT configured; try -h option" + fi + fi + + # Set TOS environment + if [ -n "$newroot" ]; then + updclasspath "$TOSROOT" "$newroot" + TOSROOT="$newroot" + TOSDIR="$TOSROOT/tos" + MAKERULES="$TOSROOT/support/make/Makerules" + fi +fi +export TOSROOT TOSDIR MAKERULES +unset TOSBASE RCFILES + +# vi: sw=4