integ/filesystem/filesystem-scripts/filesystem-scripts-1.0/nfs-mount
Scott Little 7763542515 Relocate filesystem-scripts to stx-integ/filesystem/filesystem-scripts
Move content from stx-utils into stx-integ or stx-update

Packages will be relocated to

stx-update:
    enable-dev-patch
    extras

stx-integ:
    config-files/
        io-scheduler

    filesystem/
        filesystem-scripts

    grub/
        grubby

    logging/
        logmgmt

    tools/
        collector
        monitor-tools

    tools/engtools/
        hostdata-collectors
        parsers

    utilities/
        build-info
        branding   (formerly wrs-branding)
        platform-util

Change-Id: I33cb6b2660f0276b4af1dd7ddd1a2652f53f8f30
Story: 2002801
Task: 22687
Signed-off-by: Scott Little <scott.little@windriver.com>
2018-08-01 12:20:04 -04:00

82 lines
1.7 KiB
Bash

#!/bin/bash
#
# Copyright (c) 2015 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# This utility is a wrapper around mount, to provide a single script
# with preferred options for NFS mounting. It takes exactly two arguments:
# - network source path
# - local destination path
#
function show_help()
{
cat >&2 << EOF
$(basename $0):
Wrapper around "mount" to provide a set of default options for NFS mounts.
This utility takes exactly two arguments:
- network source path
- local destination path
EOF
exit 1
}
function get_proto()
{
local host=$1
# Check /etc/hosts for the hostname
local ipaddr=$(cat /etc/hosts | awk -v host=$host '$2 == host {print $1}')
if [[ "$ipaddr" =~ ^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$ ]]
then
echo "udp"
return
fi
if [[ "$ipaddr" =~ ^[0-9a-z]*\:[0-9a-z\:]*$ ]]
then
echo "udp6"
return
fi
# Try the DNS query
ipaddr=$(dig +short ANY $host)
if [[ "$ipaddr" =~ ^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$ ]]
then
echo "udp"
return
fi
if [[ "$ipaddr" =~ ^[0-9a-z]*\:[0-9a-z\:]*$ ]]
then
echo "udp6"
return
fi
# Use default of udp to avoid invalid option
echo "udp"
return
}
if [[ ${BASH_ARGC[0]} != 2 ]]
then
show_help
fi
if mountpoint -q $2
then
echo "$2 is already mounted. Not mounting."
exit
fi
HOST=`echo $1|awk -F ':' '{print $1}'`
declare proto=`get_proto $HOST`
declare -i timeo=30
declare -i rw_size=1024
declare DEFAULT_OPTS="timeo=$timeo,proto=$proto,vers=3,rsize=$rw_size,wsize=$rw_size"
exec mount -t nfs -o $DEFAULT_OPTS $1 $2