Lots of stuff. Working on refactoring
This commit is contained in:
4
NAS_mounts/auto_nas
Executable file
4
NAS_mounts/auto_nas
Executable file
@@ -0,0 +1,4 @@
|
||||
/Users/[[UNAME]]/mnt/music -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/music
|
||||
/Users/[[UNAME]]/mnt/video -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/video
|
||||
/Users/[[UNAME]]/mnt/photo -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/photo
|
||||
/Users/[[UNAME]]/mnt/NAS -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/home
|
||||
55
NAS_mounts/fix_mounts.sh
Normal file
55
NAS_mounts/fix_mounts.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# fix_mounts.sh - ensures autofs mounts are mounted by a user and not 'root'
|
||||
#
|
||||
# copyright 2016 scot.mcphee@gmail.com
|
||||
#
|
||||
# GPL 3.0 LICENCE https://www.gnu.org/licenses/gpl.txt
|
||||
#
|
||||
# This file should be run by 'root' as the 'sudo' should execute without stopping
|
||||
# to ask for your password, unless you run this manually. See the
|
||||
# org.autonomous.fixmounts.plist file which accompanies it. This plist executes
|
||||
# the script every 15 seconds. I put mine in /Library/LaunchDaemons where it will
|
||||
# be run as root whether there is a user logged in or not.
|
||||
#
|
||||
# autofsname - the name of the file in /etc/ that is specified in auto_master
|
||||
# e.g.
|
||||
# /- auto_nas -nosuid
|
||||
# then it's 'auto_nas'
|
||||
#
|
||||
# mnt_usr - the userid of the user (you) that you want the mounts for
|
||||
# mnt_pnt - the directory in the user dir where the mounts are
|
||||
# t_mnt - using $mnt_usr and $mnt_pnt; the full path to the mounts
|
||||
# mounts - space-separated list of mounts expected in $t_mnt
|
||||
|
||||
autofsname=auto_nas
|
||||
mnt_usr=[[USERNAME]]
|
||||
mnt_pnt=mnt
|
||||
t_mnt=/Users/${mnt_usr}/${mnt_pnt}
|
||||
mounts="music photo video NAS"
|
||||
|
||||
# don't change below here unless you know what you are doing with shell scripts.
|
||||
|
||||
all_mounts=`/sbin/mount | /usr/bin/grep $t_mnt | /usr/bin/grep -v "map $autofsname on $t_mnt"`
|
||||
|
||||
d=`/bin/date`
|
||||
echo "fix_mounts [$d] checking $t_mnt for $mounts"
|
||||
for mt in $mounts;
|
||||
do
|
||||
full_mount=${t_mnt}/${mt}
|
||||
if [[ $all_mounts == *"$full_mount"* ]];
|
||||
then
|
||||
# it is mounted, let us see if it mounted by the user.
|
||||
mm=`/bin/echo "$all_mounts" | /usr/bin/grep $full_mount`
|
||||
if [[ ! $mm =~ on.$full_mount.*mounted.by.$mnt_usr ]]; then
|
||||
echo "fix_mounts [$d] Remounting: $full_mount - because $mnt_usr not mounted $mm"
|
||||
/usr/bin/sudo /sbin/umount $full_mount
|
||||
# if resource is busy force unmount with diskutil DANGER
|
||||
if [ ! $? ]; then /usr/sbin/diskutil unmount force $full_mount; fi
|
||||
/usr/bin/sudo -u $mnt_usr cd $full_mount
|
||||
fi
|
||||
else
|
||||
echo "fix_mounts [$d] Not mounted: $full_mount - ignoring"
|
||||
fi
|
||||
done
|
||||
|
||||
34
NAS_mounts/org.autonomous.fixmounts.plist
Normal file
34
NAS_mounts/org.autonomous.fixmounts.plist
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>org.autonomous.fixmounts</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/Users/[[USERNAME]]/bin/fix_mounts.sh</string>
|
||||
</array>
|
||||
|
||||
<key>Nice</key>
|
||||
<integer>10</integer>
|
||||
|
||||
<key>StartInterval</key>
|
||||
<integer>15</integer>
|
||||
|
||||
<key>ThrottleInterval</key>
|
||||
<integer>15</integer>
|
||||
|
||||
<key>RunAtLoad</key>
|
||||
<false/>
|
||||
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/fixmounts.log</string>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/fixmounts.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
49
NAS_mounts/setup.sh
Executable file
49
NAS_mounts/setup.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function create_directories()
|
||||
{
|
||||
mkdir ${HOME}/mnt
|
||||
mkdir ${HOME}/mnt/music
|
||||
mkdir ${HOME}/mnt/photos
|
||||
mkdir ${HOME}/mnt/video
|
||||
mkdir ${HOME}/mnt/NAS
|
||||
}
|
||||
|
||||
function install_automount()
|
||||
{
|
||||
echo -n "Username for NAS: "
|
||||
read NAS_USERNAME
|
||||
echo -n "Password for NAS: "
|
||||
read -s NAS_PASSWORD
|
||||
echo
|
||||
sed -e "s/\[\[USERNAME\]\]/${NAS_USERNAME}/" \
|
||||
-e "s/\[\[PASSWORD\]\]/${NAS_PASSWORD}/" \
|
||||
-e "s/\[\[UNAME\]\]/$(whoami)/" \
|
||||
< "${DOTFILES}/NAS_mounts/auto_nas" \
|
||||
| sudo tee "/etc/auto_nas_$(whoami)" >/dev/null
|
||||
sudo chmod 600 "/etc/auto_nas_$(whoami)"
|
||||
if ! grep "auto_nas_$(whoami)" < /etc/auto_master >/dev/null; then
|
||||
echo "/- auto_nas_$(whoami) -nosuid" \
|
||||
| sudo tee -a /etc/auto_master
|
||||
fi
|
||||
}
|
||||
|
||||
function install_fixer()
|
||||
{
|
||||
local plist=org.autonomous.fixmounts.plist
|
||||
|
||||
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
|
||||
< "${DOTFILES}/NAS_mounts/fix_mounts.sh" \
|
||||
> ${HOME}/bin/fix_mounts.sh
|
||||
chmod +x ${HOME}/bin/fix_mounts.sh
|
||||
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
|
||||
< "${DOTFILES}/NAS_mounts/${plist}" \
|
||||
| sudo tee /Library/LaunchDaemons/${plist} \
|
||||
>/dev/null
|
||||
sudo chmod 644 /Library/LaunchDaemons/${plist}
|
||||
sudo launchctl load /Library/LaunchDaemons/${plist}
|
||||
}
|
||||
|
||||
export DOTFILES=/Users/thomas/dotfiles
|
||||
install_automount
|
||||
install_fixer
|
||||
Reference in New Issue
Block a user