Working on cleanup

This commit is contained in:
2017-10-14 17:39:00 +02:00
parent 5749a9fc07
commit ee2a05a99a
5 changed files with 116 additions and 83 deletions

View File

@@ -1,49 +1,78 @@
#!/usr/bin/env bash
function create_directories()
function main()
{
mkdir ${HOME}/mnt
mkdir ${HOME}/mnt/music
mkdir ${HOME}/mnt/photos
mkdir ${HOME}/mnt/video
mkdir ${HOME}/mnt/NAS
}
if [ ! -d "${HOME}/mnt" ]; then
mkdir "${HOME}/mnt"
mkdir "${HOME}/mnt/music"
mkdir "${HOME}/mnt/photos"
mkdir "${HOME}/mnt/video"
mkdir "${HOME}/mnt/NAS"
fi
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
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)/" \
< "${DOTFILES}/NAS_mounts/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} -nosuid" \
| 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
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
< "${DOTFILES}/NAS_mounts/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)/" \
< "${DOTFILES}/NAS_mounts/${plist}" \
| sudo tee "${plistloc}" \
> /dev/null
sudo chmod 644 "${plistloc}"
sudo launchctl load "${plistloc}"
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
main "$@"