88 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
source ${DOTFILES}/helpers.sh
function main()
{
local scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
print_info "Setting up user homedir mounts"
makedir "${HOME}/mnt"
makedir "${HOME}/mnt/music"
makedir "${HOME}/mnt/photo"
makedir "${HOME}/mnt/video"
makedir "${HOME}/mnt/NAS"
local auto_file="auto_nas_$(whoami)"
# Make a file with settings for the NAS mounts
if [ ! -f "/etc/${auto_file}" ]; then
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)/" \
< "${scriptdir}/auto_nas" \
| sudo tee "/etc/${auto_file}" \
> /dev/null
# The file contains a password, so make sure noone can read it
sudo chmod 600 "/etc/${auto_file}"
fi
# Add reference to the new file to /etc/auto_master
if ! grep "${auto_file}" < /etc/auto_master >/dev/null; then
echo "/- ${auto_file}" \
| sudo tee -a /etc/auto_master \
> /dev/null
fi
# Install automount fixing script
# Automount is wonky under OSX and will mount directories as the
# first user who wants to use them.
# In many cases, this is root, and then noone else can access it.
# The following lines installs a script found at
# https://github.com/scotartt/shell_scripts
# which fixes this by remounting all mountpoints that have the wrong
# owner every 15 seconds.
local script="${HOME}/bin/fix_mounts.sh"
local plist="org.autonomous.fixmounts.plist"
local plistloc="/Library/LaunchDaemons/${plist}"
# Copy and set up mount-fixing script
if [ ! -f "${script}" ]; then
makedir ${HOME}/bin
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
< "${scriptdir}/fix_mounts.sh" \
> "${script}"
chmod +x "${script}"
fi
# Install a launchd service to run it every 15 seconds
if [ ! -f "${plistloc}" ]; then
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
< "${scriptdir}/${plist}" \
| sudo tee "${plistloc}" \
> /dev/null
sudo chmod 644 "${plistloc}"
sudo launchctl load "${plistloc}"
sudo autmount -vc
fi
print_ok "User homedir mounts set up"
}
main "$@"