Project

General

Profile

Arvswitch » History » Revision 8

Revision 7 (Peter Amstutz, 03/03/2016 06:57 PM) → Revision 8/10 (Peter Amstutz, 03/03/2016 07:00 PM)

h1. Arvswitch 

 h2. Usage 

 <pre> 
 $ arvswitch 
 Switch Arvados environment conf 
 Usage: arvswitch name 
 Available confs: ... 

 $ arvsave  
 Save current Arvados environment variables to conf file 
 Usage: arvsave name 

 $ arvrm 
 Delete Arvados environment conf 
 Usage: arvrm name 

 $ arvboxswitch  
 Switch Arvbox environment conf 
 Usage: arvboxswitch name 
 Your current container is: arvbox 
 Available confs: ... 

 $ arvopen 
 Open Arvados uuid in browser 
 Usage: arvopen uuid 
 </pre> 

 h2. Code 

 Copy this into your @.bashrc@ or create a new file called something like "arvswitch.sh" and add the line ". arvswitch.sh" to your @.bashrc@ 

 <pre> 
 HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*' 

 arvswitch() { 
     if [[ -n "$1" ]] ; then 
         if [[ -f $HOME/.config/arvados/$1.conf ]] ; then 
             unset ARVADOS_API_HOST_INSECURE 
             for a in $(cat $HOME/.config/arvados/$1.conf) ; do export $a ; done 
             echo "Switched to $1" 
         else 
             echo "$1 unknown" 
         fi 
     else 
         echo "Switch Arvados environment conf" 
         echo "Usage: arvswitch name" 
         echo "Available confs:" $((cd $HOME/.config/arvados && ls --indicator-style=none *.conf) | rev | cut -c6- | rev) 
     fi 
 } 

 arvsave() { 
     if [[ -n "$1" ]] ; then 
	 touch $HOME/.config/arvados/$1.conf 
	 chmod 0600 $HOME/.config/arvados/$1.conf 
         env | grep ARVADOS_ > $HOME/.config/arvados/$1.conf 
     else 
         echo "Save current Arvados environment variables to conf file" 
         echo "Usage: arvsave name" 
     fi 
 } 

 arvrm() { 
     if [[ -n "$1" ]] ; then 
         if [[ -f $HOME/.config/arvados/$1.conf ]] ; then 
             rm $HOME/.config/arvados/$1.conf 
         else 
             echo "$1 unknown" 
         fi 
     else 
         echo "Delete Arvados environment conf" 
         echo "Usage: arvrm name" 
     fi 
 } 

 arvboxswitch() { 
     if [[ -n "$1" ]] ; then 
         if [[ -d $HOME/.arvbox/$1 ]] ; then 
             export ARVBOX_CONTAINER=$1 
             echo "Arvbox switched to $1" 
         else 
             echo "$1 unknown" 
         fi 
     else 
         if test -z "$ARVBOX_CONTAINER" ; then 
             ARVBOX_CONTAINER=arvbox 
         fi 
         echo "Switch Arvbox environment conf" 
         echo "Usage: arvboxswitch name" 
         echo "Your current container is: $ARVBOX_CONTAINER" 
         echo "Available confs:" $(cd $HOME/.arvbox && ls --indicator-style=none) 
     fi 
 } 

 arvopen() { 
     if [[ -n "$1" ]] ; then 
         xdg-open https://curover.se/$1 
     else 
         echo "Open Arvados uuid in browser" 
         echo "Usage: arvopen uuid" 
     fi 
 } 
 </pre> 

 h2. Alternatives 

 See DJB's "envdir":http://cr.yp.to/daemontools/envdir.html