#!/bin/sh -e # Company: PowerCraft Technology # Author: Copyright Jelle de Jong # Note: Please send me an email if you enhanced this script # System: Ubuntu Linux and Debian GNU/Linux # Version: 0.1.0 # Date: 03-04-2008 / 12-06-2009 # Description: connecting auto sshfs mounts in an organized matter # Command: /etc/network/if-up.d/sshfs-storage-mount # Did the script work for you? # Yes # Yes, but with some errors # Yes, but I had to change some things # Not at all # 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 3 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 Street, Fifth Floor, Boston, # MA 02110-1301, USA. # set -x # exec 2>/var/log/sshfs-storage-mount.log [ -r /etc/default/sshfs-storage-config ] && . /etc/default/sshfs-storage-config if [ "$ENABLE" -ne "1" ]; then exit 0 fi if [ "$METHOD" = loopback ]; then exit 0 fi if [ "$IFACE" = lo ]; then exit 0 fi PATH=/sbin:/bin:/usr/sbin:/usr/bin check_location() { LOCATION="$1" USER="$2" sudo -u $USER test -d "$LOCATION" || sudo mkdir --parents --verbose "$LOCATION" sudo -u $USER test -w "$LOCATION" || sudo chown --verbose --recursive --changes $USER:$USER "$LOCATION" return 0 } check_symbolic() { LOCATION="$1" POINT=${LOCATION%/*} && POINT=${POINT%/*} USER="$2" if [ -d "$LOCATION"/home/$USER/ ]; then [ ! -h "$POINT"/prive ] && ln --verbose --symbolic "$LOCATION"/home/$USER/ "$POINT"/prive fi if [ -d "$LOCATION"/home/management/ ]; then [ ! -h "$POINT"/management ] && ln --verbose --symbolic "$LOCATION"/home/management/ "$POINT"/management fi if [ -d "$LOCATION"/home/share/projects/ ]; then [ ! -h "$POINT"/projects ] && ln --verbose --symbolic "$LOCATION"/home/share/projects/ "$POINT"/projects fi return 0 } while read line do location=$(echo "$line" | awk '/^sshfs/ {print $2}') user=$(echo "$line" | sed 's|.*uid=\([^,]*\),.*|\1|') if [ ! -z "$location" ] && [ ! -z "$user" ] then check_location "$location" "$user" sudo -u "$user" mount "$location" echo "sshfs-storage: mounting $location" if [ "$SYMBOLIC" -eq "1" ]; then check_symbolic "$location" "$user" fi fi done < /etc/fstab exit 0