Useful scripts

Bricks and mortar

We can use shell scripts to automate recurring everyday tasks, and also we can create default workspaces, set up windows and programs for easy access. The following scripts are used on various BSDs, so I am almost sure they are portable, so they should work on your machine aswell. Some assembly required. Also no batteries included.


Mounting the NAS

SMB is overkill, so i use sshfs instead:

~> cat nas.sh
#!/bin/sh

NAS="sshfs user@NAS_IP:/../mnt/tank"
LOCAL="/mnt/nas"
KEY="-o IdentityFile=/home/user/.ssh/id_rsa"
MAP="-o idmap=user,allow_other,uid=1000,gid=1000"

$NAS/media $LOCAL/media $KEY $MAP
$NAS/storage $LOCAL/storage $KEY $MAP
$NAS/iocage/jails/blog/root $LOCAL/blog $KEY $MAP

Backup to the NAS via rsync

I have an encrypted ZFS volume on the NAS for this:

~> cat backup.sh 
#!/bin/sh

EXCLUDE="/home/user/.backup_ignore"
SOURCE="/home/user"
TARGET="user@NAS_IP:/mnt/tank/backup/obsd-laptop"

rsync -avxP --delete --exclude-from=$EXCLUDE $SOURCE $TARGET

tmux config

My default terminal-arrangement:

~> cat tmx.sh
#!/bin/sh

# Set Session Name
SESSION="Main"
SESSIONEXISTS=$(tmux list-sessions | grep $SESSION)

# Only create tmux session if it doesn't already exist
if [ "$SESSIONEXISTS" = "" ]
then
        # Start New Session with our name
        tmux new-session -d -s $SESSION

        tmux rename-window 'mail'
        tmux send-keys -t 'mail' 'neomutt' C-m

        tmux new-window -t $SESSION:1 -n 'news'
        tmux send-keys -t 'news' "newsboat" C-m

        tmux new-window -t $SESSION:2 -n 'chat'
        tmux send-keys -t 'chat' "irssi" C-m

        tmux new-window -t $SESSION:3 -n 'muggie'
        tmux send-keys -t 'muggie' "musikcube" C-m  

        tmux new-window -t $SESSION:4 -n 'file'
        tmux send-keys -t 'file' "mc" C-m  

        tmux new-window -t $SESSION:5 -n 'shell'
        tmux send-keys -t 'shell' "~/Progs/bin/clifm" C-m
fi