Grouping stuff

This commit is contained in:
2017-10-15 20:50:00 +02:00
parent b90cf92fb5
commit 832fa5ee30
30 changed files with 120 additions and 37 deletions

4
network/NAS_mounts/auto_nas Executable file
View File

@@ -0,0 +1,4 @@
/Users/[[UNAME]]/mnt/music -fstype=smbfs,soft ://[[USERNAME]]:[[PASSWORD]]@nas.loven/music
/Users/[[UNAME]]/mnt/video -fstype=smbfs,soft ://[[USERNAME]]:[[PASSWORD]]@nas.loven/video
/Users/[[UNAME]]/mnt/photo -fstype=smbfs,soft ://[[USERNAME]]:[[PASSWORD]]@nas.loven/photo
/Users/[[UNAME]]/mnt/NAS -fstype=smbfs,soft ://[[USERNAME]]:[[PASSWORD]]@nas.loven/home

View 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

View 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>

86
network/NAS_mounts/setup.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/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
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 "$@"

47
network/git/gitconfig Normal file
View File

@@ -0,0 +1,47 @@
[user]
name = Thomas Lovén
email = thomasloven@gmail.com
[credential]
helper = cache
[color]
ui = auto
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow
frag = magenta
old = red
new = green
[color "status"]
added = yellow
changed = green
untracked = cyan
[push]
default = current
[core]
pager = less -F -X
[alias]
st = status
ci = commit
co = checkout
di = diff
dc = diff --cached
wd = diff --word-diff=color
amend = commit --amend
aa = add --all
b = branch
updateall = submodule foreach 'git pull'
l = !prettygit
p = "!echo $PATH"
la = !git l --all
r = !git l -30
ra = !git r --all
[merge]
tool = vimdiff

View File

@@ -0,0 +1,38 @@
*.com
*.class
*.dll
*.exe
*.o
*.so
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.log
*.sql
*.sqlite
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
#Latex files
*.aux
*.bcf
*.blg
*.fdb_latexmk
*.fls
*.out
tags

25
network/git/setup.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
source ${DOTFILES}/helpers.sh
function main()
{
local scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
print_info "Configuring git"
brewget git
if [ ! -f "${HOME}/.gitconfig" ]; then
cat << EOF > ${HOME}/.gitconfig
[include]
path = ${scriptdir}/gitconfig
[core]
excludesfile = ${scriptdir}/gitignore_global
EOF
fi
print_ok "Git configured"
}
main "$@"

16
network/setup.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
source ${DOTFILES}/helpers.sh
function main()
{
local scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
${scriptdir}/ssh/setup.sh
${scriptdir}/git/setup.sh
${scriptdir}/NAS_mounts/setup.sh
brewget arp-scan
}
main "$@"

4
network/ssh/config Normal file
View File

@@ -0,0 +1,4 @@
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/thomas_rsa

19
network/ssh/setup.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
source ${DOTFILES}/helpers.sh
function main()
{
local scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
print_info "Setting up SSH"
# copy private key to .ssh
# cp ${KEYFILE} ~/.ssh/thomas_rsa
# chmod 400 ~/.ssh/thomas_rsa
# ssh-add -K ~/.ssh/thomas_rsa
linkfile ${scriptdir}/config ${HOME}/.ssh/config
print_ok "SSH settings installed"
}
main "$@"