Files
network-mount/old_scripts/mnt-part-to-nas.sh

120 lines
3.5 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's a bit more advanced than mnt-share.sh but still 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: $NASPATH"
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 /mnt/nas ]; then
mkdir -p /mnt/nas
fi
mount -t cifs //$NASPATH /mnt/nas $OPT
}
# Fragt Namen des Kunden ab und erstellt Verzeichnis wenn nötig
function destcheck {
read -p "Name des Kunden: " NAME
if [ ! -e /mnt/nas/$NAME ]; then
mkdir /mnt/nas/$NAME
fi
}
# Frage zu sichernde Partition ab
function partmount {
fdisk -l
YN="y"
while [ "$YN" = "y" ]; do
read -p "Welche NTFS-Partition soll gemountet werden? [z.B /dev/sda1]: " PART
if [ ! -e $PART ]; then
echo "Partition nicht vorhanden, bitte zu mountende Partition auswählen!"
else
if [ ! -e /mnt$PART ]; then
mkdir -p /mnt$PART
fi
mount -t ntfs-3g $PART /mnt$PART -o force
pcmanfm /mnt$PART /mnt/nas/$KUNDE &
fi
read -p "Noch eine Partition mounten? y für Ja, beliebige Taste zum Abbrechen: " YN
done
unset YN
}
## 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
destcheck
partmount