Files
network-mount/old_scripts/mnt-share.sh

90 lines
2.8 KiB
Bash
Raw Normal View History

2014-11-28 17:02:20 +01:00
#!/bin/bash
########################################################################
# Copyright (C) 2013 Max Mehl <mail@mehl.mx>
########################################################################
#
# 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, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# This is a script to mount Windows/SMB shared drives via the CLI
# It is very basic and was used for a special environment.
# It requires pcmanfm and smbfs/cifs-utils to be installed.
#
########################################################################
2014-11-28 17:02:20 +01:00
cd "$(dirname "$(readlink -f "$0")")"
# Test if config.cfg exists and set needed variables
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
source config.cfg
## FUNKTIONEN
# Überprüft, ob Root-Rechte am Start sind
function rootcheck {
if [ $EUID -ne 0 ]; then
echo "Dieses Script benötigt Root-Rechte. Rechte erlangen mit \"su\" oder \"sudo -i\"."
exit 1
fi
}
# Möglichkeit, Variablen zu ändern
function varcheck {
echo "Folgende Parameter sind vorgegeben:"
echo "Adresse des Zielortes: $NASDIR auf $NASIP"
echo "User für Zielort, falls nötig (sonst leer): $NASUSER"
echo "Passwort für Zielort, falls nötig (sonst leer): $NASPASS"
read -p "Sollen diese so übernommen werden? [y/n]: " YN
if [ "$YN" = "y" ]; then
echo "Daten wurden akzeptiert. Fahre fort..."
elif [ "$YN" = "n" ]; then
echo "Nun gewünschte Daten für Zielort eingeben:"
read -p "Adresse des Zielortes: " NASPATH
read -p "User für Zielort, falls nötig (sonst leer): " NASUSER
read -p "Passwort für Zielort, falls nötig (sonst leer): " NASPASS
echo "Daten wurden übernommen. Fahre fort..."
else
echo "Ungültige Eingabe. Script wird beendet."
exit 1
fi
unset YN
}
# Mounte Zielverzeichnis
function nasmount {
if ! ([ "$NASUSER" = "" ] && [ "$NASPASS" = "" ]); then
OPT="-o user=$NASUSER,password=$NASPASS"
fi
if [ ! -e $LOCALMOUNTDIR/$NASDIR ]; then
mkdir -p $LOCALMOUNTDIR/$NASDIR
fi
mount -t cifs //$NASIP/$NASDIR $LOCALMOUNTDIR/$NASDIR $OPT
}
## START DES PROGRAMMS
#rootcheck
if [ "$1" = "unmount" ]; then
umount /mnt/nas /mnt/dev/*
echo "/mnt/nas und /mnt/dev/* wurden ausgehängt. Beende."
exit 1
fi
varcheck
nasmount