#!/bin/bash # ------- # File: netmount # Description: LliureX init script to mount network shares # This script replaces old llxcfg netfstab # Author: Luis Garcia Gisbert # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e # PATH & variables PATH="/sbin:/bin:/usr/sbin:/usr/bin" # Funcs info_message(){ printf "netmount: $1" } error_message(){ echo -e "netmount: $1" >&2 } is_mounted(){ if mount |grep -q "^${1}\b" ; then return 0 fi return 1 } mount_share(){ if is_mounted "$1" ; then info_message "Skipping already mounted \"$1\"\n" return 0 fi net_fs="$1" net_mntpoint="$2" net_fstype="$3" net_mntopt="$4" info_message "Mounting \"$net_fs\" ... " if [ ! -d "$net_mntpoint" ] ; then if ! mkdir -p "$net_mntpoint" >/dev/null 2>/dev/null ; then info_message "FAILED\n" error_message "Unable to create mount point \"$net_mntpoint\"" return 1 fi fi if ! mount -s -o "$net_mntopt" -t "$net_fstype" "$net_fs" "$net_mntpoint" >/dev/null 2>/dev/null ; then info_message "FAILED.\n" error_message "Unable to mount \"$net_fstype\" filesystem in \"$net_mntpoint\"" # Requesting keytab file for the right lliurex flavor n4d-client -h server -m get_keytabs -c KrbManager -a `python /usr/share/n4d/python-plugins/LliurexVersion.py` # Done return 1 fi info_message "[OK]\n" return 0 } umount_share(){ if ! is_mounted "$1" ; then info_message "\"$1\" not mounted. Nothing to do.\n" return 0 fi info_message "Umounting \"$1\" ... " if ! umount -l -f "$1" >/dev/null 2>/dev/null ; then info_message "FAILED\n" return 1 fi info_message "[OK]\n" return 0 } net_shares(){ local ACTION ACTION="$1" REGEXP_RAMON="/^\([^[:blank:]]\+[[:blank:]]\+\)\{3\}[01]\?[0-7]\{3\}[[:blank:]]\+[^[:blank:],]\+\(,[^,]\+\)*/p" VALIDATE_REGEXP="^\([^[:blank:]#]\+[[:blank:]]\+\)\{3\}[^[:blank:]]\+" llxcfg-config dump netmount |sed -ne "/${VALIDATE_REGEXP}/p" |while read net_fs net_mntpoint net_fstype net_mntopt net_extra ; do case $ACTION in mount) initctl emit mounting TYPE="nfs4" OPTIONS="sec,krb5" export KRB5_KTNAME mount_share "$net_fs" "$net_mntpoint" "$net_fstype" "$net_mntopt" || true ;; umount) umount_share "$net_mntpoint" || true ;; *) error_message "Unknown action \"$ACTION\"" return 1 ;; esac done return 0 } # main case "$1" in start) net_shares mount ;; stop) net_shares umount ;; *) error_message "Usage: $0 {start|stop}" >&2 exit 1 ;; esac exit 0