Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2005-2009 Wind River Systems, Inc. |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License version 2 as |
| 7 | # published by the Free Software Foundation. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | # See the GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program; if not, write to the Free Software |
| 16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | usage() { |
| 19 | echo "Usage: $0 {start|stop|restart} <nfs-export-dir>" |
| 20 | } |
| 21 | |
| 22 | if [ $# != 2 ]; then |
| 23 | usage |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then |
| 28 | echo "Unknown command '$1'" |
| 29 | usage |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | if [ ! -d "$2" ]; then |
| 34 | echo "Error: '$2' does not exist" |
| 35 | usage |
| 36 | exit 1 |
| 37 | fi |
| 38 | # Ensure the nfs-export-dir is an absolute path |
| 39 | NFS_EXPORT_DIR=$(cd "$2" && pwd) |
| 40 | |
| 41 | SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null` |
| 42 | if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then |
| 43 | echo "Error: Unable to find the oe-find-native-sysroot script" |
| 44 | echo "Did you forget to source your build environment setup script?" |
| 45 | exit 1 |
| 46 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | . $SYSROOT_SETUP_SCRIPT meta-ide-support |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 49 | if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/bin/unfsd" ]; then |
| 50 | echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | |
| 52 | if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then |
| 53 | echo "Have you run 'bitbake meta-ide-support'?" |
| 54 | else |
| 55 | echo "This shouldn't happen - something is missing from your toolchain installation" |
| 56 | fi |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | if [ ! -d ~/.runqemu-sdk ]; then |
| 61 | mkdir -p ~/.runqemu-sdk |
| 62 | fi |
| 63 | |
| 64 | NFS_INSTANCE=${NFS_INSTANCE:=0} |
| 65 | EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE |
| 66 | RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE |
| 67 | NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid |
| 68 | MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid |
| 69 | |
| 70 | PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr" |
| 71 | PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state" |
| 72 | export PSEUDO_LOCALSTATEDIR |
| 73 | |
| 74 | if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then |
| 75 | echo "Error: $PSEUDO_LOCALSTATEDIR does not exist." |
| 76 | echo "Did you create the export directory using runqemu-extract-sdk?" |
| 77 | exit 1 |
| 78 | fi |
| 79 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 80 | # NFS server port number |
| 81 | NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | # mountd port number |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 83 | MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | |
| 85 | ## For debugging you would additionally add |
| 86 | ## --debug all |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 87 | UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -n $NFSD_PORT -m $MOUNTD_PORT" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | |
| 89 | # See how we were called. |
| 90 | case "$1" in |
| 91 | start) |
| 92 | PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep` |
| 93 | RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep` |
| 94 | if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then |
| 95 | echo "=======================================================" |
| 96 | echo "Error: neither rpcbind nor portmap appear to be running" |
| 97 | echo "Please install and start one of these services first" |
| 98 | echo "=======================================================" |
| 99 | echo "Tip: for recent Ubuntu hosts, run:" |
| 100 | echo " sudo apt-get install rpcbind" |
| 101 | echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run" |
| 102 | echo " sudo service portmap restart" |
| 103 | |
| 104 | exit 1 |
| 105 | fi |
| 106 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 107 | echo "Creating exports file..." |
| 108 | echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS |
| 109 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | echo "Starting User Mode nfsd" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 111 | echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS" |
| 112 | $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | if [ ! $? = 0 ]; then |
| 114 | echo "Error starting nfsd" |
| 115 | exit 1 |
| 116 | fi |
| 117 | # Check to make sure everything started ok. |
| 118 | if [ ! -f $NFSPID ]; then |
| 119 | echo "rpc.nfsd did not start correctly" |
| 120 | exit 1 |
| 121 | fi |
| 122 | ps -fp `cat $NFSPID` > /dev/null 2> /dev/null |
| 123 | if [ ! $? = 0 ]; then |
| 124 | echo "rpc.nfsd did not start correctly" |
| 125 | exit 1 |
| 126 | fi |
| 127 | echo " " |
| 128 | echo "On your target please remember to add the following options for NFS" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 129 | echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,udp,mountport=$MOUNTD_PORT" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | ;; |
| 131 | stop) |
| 132 | if [ -f "$NFSPID" ]; then |
| 133 | echo "Stopping rpc.nfsd" |
| 134 | kill `cat $NFSPID` |
| 135 | rm -f $NFSPID |
| 136 | else |
| 137 | echo "No PID file, not stopping rpc.nfsd" |
| 138 | fi |
| 139 | if [ -f "$EXPORTS" ]; then |
| 140 | echo "Removing exports file" |
| 141 | rm -f $EXPORTS |
| 142 | fi |
| 143 | ;; |
| 144 | restart) |
| 145 | $0 stop $NFS_EXPORT_DIR |
| 146 | $0 start $NFS_EXPORT_DIR |
| 147 | if [ ! $? = 0 ]; then |
| 148 | exit 1 |
| 149 | fi |
| 150 | ;; |
| 151 | *) |
| 152 | echo "$0 {start|stop|restart} <nfs-export-dir>" |
| 153 | ;; |
| 154 | esac |
| 155 | |
| 156 | exit 0 |