#!/bin/bash ## Created by Amdac @ www.amdac.net ## ## If using this script, you'll need to: ## 1. Fill in the NAS variables below ## 2. Replace your local and NAS usernames in the mountpoints (currently 'dave') ## 3. Create the local password files in your home directory. (recommend setting owner to root) ## 4. If 'doas' is not installed, replace each instance with 'sudo'. ## FORMAT VARIABLES ## nas1name="nas1" ### Hostname for NAS 1, all lowercase nas1ip="10.0.0.1" ### IP address of first NAS nas2name="nas2" ### Hostname for NAS 2, all lowercase nas2ip="10.0.0.2" ### IP address of second NAS bold=$(tput bold) norm=$(tput sgr0) color="\e[1;30m" ## FUNCTIONS ## nas1up() { doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas1name}passwd,rw //${nas1ip}/dave /home/dave/network/${nas1name}-dave/ doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas1name}passwd,rw //${nas1ip}/media /home/dave/network/${nas1name}-media/ doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas1name}passwd,rw //${nas1ip}/shared /home/dave/network/${nas1name}-shared/ echo -e "\n${bold}${color}[+]${norm} ${nas1name^} has been mounted.\n" } nas1down() { doas umount /home/dave/network/${nas1name}* && echo -e "\n${bold}${color}[ ]${norm} ${nas1name^} has been unmounted.\n" || echo -e "\n${bold}${color}Whoops, something went wrong.${norm}\n" } nas2up() { doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas2name}passwd,rw //${nas2ip}/dave /home/dave/network/${nas2name}-dave/ doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas2name}passwd,rw //${nas2ip}/media /home/dave/network/${nas2name}-media/ doas mount -t cifs -o uid=dave,credentials=/home/dave/network/.${nas2name}passwd,rw //${nas2ip}/shared /home/dave/network/${nas2name}-shared/ echo -e "\n${bold}${color}[+]${norm} ${nas2name^} has been mounted.\n" } nas2down() { doas umount /home/dave/network/${nas2name}* && echo -e "\n${bold}${color}[ ]${norm} ${nas2name^} has been unmounted.\n" || echo -e "\n${bold}${color}Whoops, something went wrong.${norm}\n" } status() { num=$(mount -l | grep $nas1name | wc -l) && [[ $num != 0 ]] && echo -e "\n${bold}${color}[+]${norm} ${nas1name^} has ${bold}${num}${norm} share(s) currently mounted." || echo -e "\n${bold}${color}[ ]${norm} ${nas1name^} is not mounted." num=$(mount -l | grep $nas2name | wc -l) && [[ $num != 0 ]] && echo -e "${bold}${color}[+]${norm} ${nas2name^} has ${bold}${num}${norm} share(s) currently mounted.\n" || echo -e "${bold}${color}[ ]${norm} ${nas2name^} is not mounted.\n" } ## SCRIPT ## if [ "$1" == "$nas1name" ]; then case $2 in up) nas1up ;; down) nas1down ;; esac elif [ "$1" == "$nas2name" ]; then case $2 in up) nas2up ;; down) nas2down ;; esac else status fi