2019-10-15 23:47:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# check whether we're running as sudo
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "Please run as root"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# declare variables
|
2021-02-03 17:09:38 +01:00
|
|
|
MY_SERVER_LOCATION="//10.10.1.11"
|
2019-10-15 23:47:10 +02:00
|
|
|
MOUNT_PREFIX="/mnt"
|
|
|
|
|
|
|
|
# check whether array contains a key
|
|
|
|
containsElement() {
|
|
|
|
local e match="$1"
|
|
|
|
shift
|
|
|
|
for e; do [[ "$e" == "$match" ]] && return 0; done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# trickery to add objects into bash array
|
|
|
|
# all associative arrays are named NAME{X} where {X} is a number
|
|
|
|
declare -A MOUNTS0=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='Rick'
|
|
|
|
[mount]='rick'
|
|
|
|
)
|
|
|
|
declare -A MOUNTS1=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='Series'
|
|
|
|
[mount]='series'
|
|
|
|
)
|
|
|
|
declare -A MOUNTS2=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='Movies'
|
|
|
|
[mount]='movies'
|
|
|
|
)
|
|
|
|
declare -A MOUNTS3=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='appdata'
|
|
|
|
[mount]='appdata'
|
|
|
|
)
|
2019-12-01 16:51:23 +01:00
|
|
|
declare -A MOUNTS4=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='isos'
|
|
|
|
[mount]='isos'
|
|
|
|
)
|
2020-09-28 13:04:26 +02:00
|
|
|
declare -A MOUNTS5=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='books'
|
|
|
|
[mount]='books'
|
|
|
|
)
|
|
|
|
declare -A MOUNTS6=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='pictures'
|
|
|
|
[mount]='pictures'
|
|
|
|
)
|
2021-10-19 11:05:34 +02:00
|
|
|
declare -A MOUNTS7=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]='nvme1'
|
|
|
|
[mount]='nvme1'
|
|
|
|
)
|
2022-03-07 14:00:00 +01:00
|
|
|
declare -A MOUNTS8=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="downloads"
|
|
|
|
[mount]="downloads"
|
|
|
|
)
|
|
|
|
declare -A MOUNTS9=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="emulation"
|
|
|
|
[mount]="emulation"
|
|
|
|
)
|
2022-11-05 20:27:14 +01:00
|
|
|
declare -A MOUNTS10=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="audiobooks"
|
|
|
|
[mount]="audiobooks"
|
|
|
|
)
|
2023-06-09 10:44:00 +02:00
|
|
|
declare -A MOUNTS11=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="games"
|
|
|
|
[mount]="games"
|
|
|
|
)
|
2023-12-10 00:02:08 +01:00
|
|
|
declare -A MOUNTS12=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="data"
|
|
|
|
[mount]="data"
|
|
|
|
)
|
2024-12-07 15:43:05 +01:00
|
|
|
declare -A MOUNTS13=(
|
|
|
|
[server]="$MY_SERVER_LOCATION"
|
|
|
|
[share]="vault"
|
|
|
|
[mount]="vault"
|
|
|
|
)
|
2019-10-15 23:47:10 +02:00
|
|
|
# declare array with "objects"
|
|
|
|
declare -n MOUNTS
|
|
|
|
|
|
|
|
# Show mountpoints and ask user which ones to mount
|
|
|
|
COUNTER=1
|
|
|
|
echo "Enter a list of numbers to mount (default = all):"
|
|
|
|
for MOUNTS in ${!MOUNTS@}; do
|
|
|
|
echo "$COUNTER. $MY_SERVER_LOCATION/${MOUNTS[share]} => $MOUNT_PREFIX/${MOUNTS[mount]}"
|
|
|
|
((COUNTER++))
|
|
|
|
done
|
|
|
|
|
|
|
|
# unset and redeclare
|
|
|
|
unset -n MOUNTS && declare -n MOUNTS
|
|
|
|
|
|
|
|
# read user input and add to array of shares to mount
|
|
|
|
read USER_INPUT
|
|
|
|
SHARES_TO_MOUNT=()
|
|
|
|
MOUNT_ALL=false
|
|
|
|
for number in $USER_INPUT; do
|
|
|
|
SHARES_TO_MOUNT+=("$number")
|
|
|
|
done
|
|
|
|
|
|
|
|
# if input is empty -> mount all
|
|
|
|
if [ "${#SHARES_TO_MOUNT[@]}" == 0 ]; then
|
|
|
|
MOUNT_ALL=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run through mounts and execute mounting logic
|
|
|
|
MOUNTCOUNTER=0
|
|
|
|
for MOUNTS in ${!MOUNTS@}; do
|
|
|
|
((MOUNTCOUNTER++))
|
|
|
|
|
|
|
|
if [ "$MOUNT_ALL" = true ] || containsElement "$MOUNTCOUNTER" "${SHARES_TO_MOUNT[@]}"; then
|
|
|
|
# creating directory
|
|
|
|
CURRENT_DIRECTORY="$MOUNT_PREFIX/${MOUNTS[mount]}"
|
|
|
|
if [ ! -d "$CURRENT_DIRECTORY" ]; then
|
|
|
|
|
|
|
|
echo -e "\nDirectory '$CURRENT_DIRECTORY' doesn't exist... \nCreating '$CURRENT_DIRECTORY'..."
|
|
|
|
mkdir -p "$CURRENT_DIRECTORY"
|
|
|
|
echo -e "Created '$CURRENT_DIRECTORY'...\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if directories are mounted already
|
|
|
|
if grep -qs "$CURRENT_DIRECTORY " /proc/mounts; then
|
|
|
|
echo "$CURRENT_DIRECTORY already mounted"
|
|
|
|
else
|
|
|
|
# mounting
|
|
|
|
SERVER_LOCATION="$MY_SERVER_LOCATION/${MOUNTS[share]}"
|
|
|
|
MOUNT_LOCATION="$MOUNT_PREFIX/${MOUNTS[mount]}"
|
|
|
|
|
2022-07-26 11:47:00 +02:00
|
|
|
mount.cifs "$SERVER_LOCATION" "$MOUNT_LOCATION" -o user=mastermindzh,noperm,rw,vers=2.0
|
2019-10-15 23:47:10 +02:00
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
2024-12-07 15:43:05 +01:00
|
|
|
echo "Successfully mounted $MOUNT_LOCATION"
|
2019-10-15 23:47:10 +02:00
|
|
|
else
|
|
|
|
echo "Failed mounting $SERVER_LOCATION on $MOUNT_LOCATION"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|