#!/bin/bash # ## Mount NAS backup shares die () { echo "$0:" "$@" >&2 exit 1 } # Load settings if [[ -f "/run/archiso/bootmnt/arch/arch.conf" ]]; then source "/run/archiso/bootmnt/arch/arch.conf" || \ die "ERROR: failed to load arch.conf (from /run/archiso/bootmnt/arch/)" else source "/usr/local/bin/arch.conf" || \ die "ERROR: failed to load arch.conf (from /usr/local/bin/)" fi # Connect to a network connect-to-network # Mount loop echo "Mounting NAS backup shares" for x in {1..4}; do _skip="False" # Load Backup share info eval "declare -a _backup=(\${BACKUP_$x[@]})" _name="${_backup[0]}" _ip="${_backup[1]}" _share="${_backup[2]}" _user="${_backup[3]}" _pass="${_backup[4]}" # Check backup share info if echo "$_name" | grep -Eq '^\s*$'; then _skip="True"; fi if echo "$_ip" | grep -Eq '^\s*$'; then _skip="True"; fi if echo "$_share" | grep -Eq '^\s*$'; then _skip="True"; fi if echo "$_user" | grep -Eq '^\s*$'; then _skip="True"; fi if echo "$_pass" | grep -Eq '^\s*$'; then _skip="True"; fi # Mount if [[ "$_skip" == "False" ]]; then sudo mkdir "/Backups/$_name" -p if mountpoint -q "/Backups/$_name"; then echo "$_name: (Already) mounted at /Backups/$_name ($(df -h "/Backups/$_name" | tail -1 | awk '{print $4}' | sed -r 's/([KMGT])/ \1b/') free)" else if sudo mount "//$_ip/$_share" "/Backups/$_name" -o username=$_user,password=$_pass 2>/dev/null; then echo "$_name: Mounted at /Backups/$_name ($(df -h "/Backups/$_name" | tail -1 | awk '{print $4}' | sed -r 's/([KMGT])/ \1b/') free)" else rmdir "/Backups/$_name" -p 2>/dev/null echo "$_name: Failed to mount" fi fi fi done