#!/bin/bash
 
# topology
topo="fritz.box"
domain=iq42.de
 
# mount
mp=/media/crypt
cm=media
 
#path
PATH=/bin:/usr/bin:/sbin:/usr/sbin

if ! mountpoint "$mp"; then
# local topology, find host
    t="$(hostname)"
    for h in $topo; do
        while ! ping -c 1 -w 1 $h >/dev/null 2>/dev/null; do
            echo waiting for $h ...
            sleep 2
        done
        t="$t $(arp -a $h | awk '{print $4}')"
    done
    t64="$(echo "$t" | openssl base64 | tr -d '\n')"
# waiting for internet
    while ! ping -c 1 -w 1 8.8.8.8; do
        echo wating for internet ...
        sleep 2
    done
# getting password
    pw64="$(dig +short txt "$t64.$domain" "@$(dig +short ns "$domain" | head -n 1)" | sed 's/\\\\/\\/g')"
    pw="$(echo -e "${pw64:1:-1}" | openssl base64 -d)"
# trying to mount
    echo "$pw" | cryptmount -w 0 "$cm"
fi
 
if mountpoint "$mp"; then
# killing everything is something is still running
    cat /media/crypt/dl/run/* | xargs kill
# removing pids
    rm /media/crypt/dl/run/*
# starting tools
    ionice -c 2 -n 0 "$mp/dl/minidlna/sbin/minidlnad" -f "$mp/dl/minidlna/minidlna.conf" -P "$mp/dl/run/minidlna.pid" -L
    ionice -c 2 -n 2 python "$mp/dl/SABnzbd/SABnzbd.py" -f "$mp/dl/sab/sabnzbd.ini" --pid "$mp/dl/run" -d
    ionice -c 2 -n 3 python "$mp/dl/Sick-Beard/SickBeard.py" -d --pidfile="$mp/dl/run/sickbeard.pid"
    "$mp/dl/scripts/sigstop.sh"
    sudo service netatalk start
fi

Add a code snippet to your website: www.paste.org