Difference between revisions of "Keep a link"

From mn/geo/geoit
Jump to: navigation, search
(Created page with "# .bash_profile for hycamp group # The purpose of this file is to enable # sshfs mounting of a directory that # contains your bash customizations so # that the directory may...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr"><div class="bash"><pre class="de1">
 
# .bash_profile for hycamp group
 
# .bash_profile for hycamp group
 
# The purpose of this file is to enable
 
# The purpose of this file is to enable
Line 15: Line 16:
  
 
bashfile=$HOME/.mnts/net/nunatak/mn/nunatak/hycamp/team/$USER/dot/bashrc
 
bashfile=$HOME/.mnts/net/nunatak/mn/nunatak/hycamp/team/$USER/dot/bashrc
 +
</pre></div></div>
  
 +
The variables `$bashfile` will be setup in this script and later 'sourced' as you log in.
 +
 +
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr"><div class="bash"><pre class="de1">
 
# generate a .display file (used as a trick for screen sessions)
 
# generate a .display file (used as a trick for screen sessions)
 
echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`
 
echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`
 +
</pre></div></div>
 +
 +
The line above is just a 'trick' that is [https://wiki.uio.no/mn/geo/geoit/index.php/WorkingOnServers/DisplayEnvironmentTricks#Another_approach_for_working_with_SSH_and_GNU_screen_.28helpful_for_Ipython.29 explained here]
 +
 +
 +
Below is the key to setting up the symlink to the mounted directory in your home area.
 +
 +
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr"><div class="bash"><pre class="de1">
  
 
# A test to see whether we've already mounted the sverdrup net
 
# A test to see whether we've already mounted the sverdrup net
 +
# /etc/mtab is a file on linux machines that keeps a record of what file mounts have been
 +
# made. We look for our directory in that file and call that 'mounted' to see if it exists already
 
net="$HOME/.mnts/net"
 
net="$HOME/.mnts/net"
 
mounted=`cat /etc/mtab | grep $net | awk '{print $2}'`
 
mounted=`cat /etc/mtab | grep $net | awk '{print $2}'`
  
 +
# if it exists, then we just say so and exit
 
if [ "$net" == "$mounted" ]; then
 
if [ "$net" == "$mounted" ]; then
 
     echo "Sverdrup mount exists"
 
     echo "Sverdrup mount exists"
 
else
 
else
 +
# if not, then we do some work to mount it with sshfs
 
     #/net
 
     #/net
 +
    # first, make sure our mountpoint (the directory where we'll create the mount) exists, if not create it
 
     if [ ! -d $net ]; then
 
     if [ ! -d $net ]; then
 
         mkdir $net
 
         mkdir $net
     fi   
+
     fi
 +
    # then mount the remote directory to your mountpoint  
 
     sshfs -o IdentityFile=~/.ssh/id_rsa $USER@sverdrup:/net $net
 
     sshfs -o IdentityFile=~/.ssh/id_rsa $USER@sverdrup:/net $net
 
fi
 
fi
 +
  
 
if [ -n "$BASH_VERSION" ]; then
 
if [ -n "$BASH_VERSION" ]; then
Line 44: Line 64:
 
     fi   
 
     fi   
 
fi
 
fi
 +
</pre></div></div>

Latest revision as of 15:43, 13 October 2015

# .bash_profile for hycamp group
# The purpose of this file is to enable
# sshfs mounting of a directory that 
# contains your bash customizations so
# that the directory may be kept consistent
# across machines in the network
#
# This file should live in your $HOME
# and assumes you have a symlink to your
# customized bashrc file as defined by
# the bashfile variable below.
#
# johnbur 15.07.03 


bashfile=$HOME/.mnts/net/nunatak/mn/nunatak/hycamp/team/$USER/dot/bashrc

The variables `$bashfile` will be setup in this script and later 'sourced' as you log in.

# generate a .display file (used as a trick for screen sessions)
echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`

The line above is just a 'trick' that is explained here


Below is the key to setting up the symlink to the mounted directory in your home area.


# A test to see whether we've already mounted the sverdrup net
# /etc/mtab is a file on linux machines that keeps a record of what file mounts have been
# made. We look for our directory in that file and call that 'mounted' to see if it exists already
net="$HOME/.mnts/net"
mounted=`cat /etc/mtab | grep $net | awk '{print $2}'`

# if it exists, then we just say so and exit
if [ "$net" == "$mounted" ]; then
    echo "Sverdrup mount exists"
else
# if not, then we do some work to mount it with sshfs
    #/net
    # first, make sure our mountpoint (the directory where we'll create the mount) exists, if not create it
    if [ ! -d $net ]; then
        mkdir $net
    fi
    # then mount the remote directory to your mountpoint  
    sshfs -o IdentityFile=~/.ssh/id_rsa $USER@sverdrup:/net $net
fi


if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    # my .bashrc file is actually sourced
    # from a file called bashrc in .dot
    # folder (which is symlinked to our
    # team network share)
    #   
    if [ -f $bashfile ]; then
    . $bashfile
    fi  
fi