1
1
Fork 0

Merge branch 'master' of git.aec.at:scripts

This commit is contained in:
David Starzengruber 2011-07-07 15:35:58 +02:00
commit 82fb3e9905
10 changed files with 323 additions and 92 deletions

View File

@ -1,22 +0,0 @@
#!/bin/bash
# this will let the message blink five times :-)
i=0
while [ $i != 5 ]; do
clear
sleep 0.5
echo
echo
echo " ####################################"
echo " ## ##"
echo " ## Attention: You are a dumbass ##"
echo " ## ##"
echo " ####################################"
echo
echo
sleep 0.5
let i++
done
clear

View File

@ -1,44 +0,0 @@
#!/bin/bash
#
# mount script for qcow2 images
# v0.1
#
# read imagename
if [ -z $1 ]; then
echo 'usage: "browseqcow2 <image.qcow2>"'
exit 1
fi
imagename=$1
# im i root
if [ $(whoami) != "root" ]; then
echo "only root can do this"
exit 1
fi
# run unmount
if [[ $1 = "--unmount" || $1 = "-u" || $1 = "--umount" ]]; then
umount /mnt/
qemu-nbd --disconnect /dev/nbd0
echo "image unmounted"
echo
exit 0
fi
# load kernel module
modprobe nbd max_part=8
# gen blockdevice
qemu-nbd --connect=/dev/nbd0 $imagename
# make the actual mount
sleep 2
mount /dev/nbd0p1 /mnt/
echo "$imagename is mounted in /mnt"
echo 'run "browseqcow2.sh --unmount" when ready'
echo

View File

@ -1,16 +0,0 @@
#!/bin/bash
if [ -z $1 ]; then
# reading the imagename
echo "what name should it have?"
read name
else
name=$1
fi
# generating the actual image
qemu-img create -f qcow2 $name.qcow2 16G
exit 0

View File

@ -8,5 +8,7 @@ wget -O cacert-root.crt "http://www.cacert.org/certs/root.crt"
wget -O cacert-class3.crt "http://www.cacert.org/certs/class3.crt"
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "CAcert.org" -i cacert-root.crt
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "CAcert.org Class 3" -i cacert-class3.crt
rm cacert-root.crt
rm cacert-class3.crt
# source: http://wiki.cacert.org/BrowserClients

9
mbots/df_bot.conf.sample Normal file
View File

@ -0,0 +1,9 @@
# **** df_bot configfile ****
# here i suggest you put the name of the machine you running this script on
hostname="somemachine.example.com"
## define disks you wanna check? (whitespace seperated)
disks="hda1 hda2 hdd1"
## here the disks thresholds
thresholds="80 90 95"

120
mbots/df_bot.sh Executable file
View File

@ -0,0 +1,120 @@
#!/bin/bash
###################################################
## ##
## disk_free monitoring bot ##
## ##
###################################################
# **** in script config section ****
version="0.3_alpha"
author="david@socialnerds.org"
logwhat="df_bot"
# **** configfile section ****
disks="sda1"
thresholds="90"
bashlibpath="/home/david/Documents/code/bashlib"
# logging
loglevel="4"
log2syslog="1"
log2file="0"
#logfile="/var/log/mbots.log"
log2stdout="1"
# **** bash trap initialisation ****
trap bashtrap INT
# **** load bashlib ****
if [ -d $bashlibpath ]; then
source $bashlibpath/main
#source $bashlibpath/update
source $bashlibpath/logengine
log debug "preflight - bashlib loaded"
else
echo "ERROR: bashlib not found"
exit 1
fi
exit 0
## timestamp for logfile
#timestamp=$(date '+%d %B %Y %H:%M')
#echo "info: starting df bot $timestamp"
## check if sendxmpp is installed
#if [ $(aptitude search sendxmpp | awk '{print $1}') = "i" ]; then
# echo "info: sendxmpp found"
#else
# if [ $(whoami) = "root" ]; then
# apt-get install sendxmpp
# else
# echo "error: permission denied"
# echo "info: install sendxmpp or run this scrip as superuser"
# exit 1
# fi
#fi
## set and load configfile
#if [ -z $1 ]; then
# configfile="/etc/mobots/df.conf"
# if [ -f $configfile ]; then
# source $configfile
# else
# echo "error: no config file $configfile"
# exit 1
# fi
#else
# configfile=$1
# if [ -f $configfile ]; then
# source $configfile
# else
# echo "error: no config file $configfile"
# exit 1
# fi
#fi
## check sendxmpp config
#if [ -f ~/.sendxmpprc ]; then
# echo "info: jabber config found in ~/.sendxmpprc"
#else
#
# if [ -z $port ]; then
# port="5222"
# else
# echo "info: using port $port"
# fi
#
# echo "$user@$server:$port $pass" > ~/.sendxmpprc
# chmod 600 ~/.sendxmpprc
# echo "info: created sendxmpp config in ~/.sendxmpprc"
#fi
## check disks
set -- $disks
i="1"
for var in "$@"
do
data=$(df -Ph | grep $var | sed -e 's/%//g' | awk '{print $5}')
datathreshold=$(echo $thresholds | awk '{print $'$i'}')
if [ $data -gt $datathreshold ]; then
echo "info: $var reached threshold with $data%, sending notification to $watchdogs"
echo "$hostname: $var is running out of space: $data%" | sendxmpp -r dfbot $watchdogs
fi
let i++
done
## exiting
#echo "info: done"
exit 0
# **** end of script ****

156
mediacontrol.sh Executable file
View File

@ -0,0 +1,156 @@
#!/bin/bash
#################################
# ##
# mediacenter control script ##
# ##
#################################
# **** config section ****
author="david@socialnerds.org"
version="0.1_alpha"
hwaddr="00:10:c6:cd:00:d4" #mc mac address
ipaddr="10.1.1.7" #mc ip address/hostname
wolserv="10.1.1.4" #remote wakeonlan host (connects via ssh)
remoteuser="media" #mc user
mediapath="/home/media/Videos" #remote basepath for mediafiles
# check for dependencies
#apt-get install wakeonlan dialog
# **** bashtrap ****
# bash trap function is executed when CTRL-C is pressed
bashtrap()
{
log 3 "bashtrap - triggered"
clear
echo "CTRL+C detected.. exiting!"
exit 1
}
navigation()
{
dialog --backtitle "Media Center Control" --title "Navigation" --no-cancel --menu "" 13 55 7 start "start mediacenter" stop "shutdown mediacenter" vnc "open vnc session" play "play mediafile" kill "kill mediaplaybak" volume "control volume" quit "leave media control" 2> /tmp/dialog
navresult=$(cat /tmp/dialog)
rm /tmp/dialog
if [ $navresult = start ]; then
startmc
elif [ $navresult = stop ]; then
stopmc
elif [ $navresult = vnc ]; then
vncconnect
elif [ $navresult = play ]; then
playmedia
elif [ $navresult = kill ]; then
killmedia
elif [ $navresult = volume ]; then
volumecontrol
elif [ $navresult = quit ]; then
exit 0
fi
}
isitup()
{
# is mediacenter up?
clear
echo "checking if mediacenter is up..."
ping -w 1 $ipaddr &> /dev/null
local pingresult=$?
return $pingresult
}
startmc()
{
# check if mediacenter is up
isitup
if [ $? = 0 ]; then
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr is already up and running" 9 55
else
ssh $wolserv wakeonlan $hwaddr &> /dev/null
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n magic package sent to mediacenter@$ipaddr" 9 55
fi
}
stopmc()
{
# is mediacenter up?
isitup
if [ $? = 0 ]; then
ssh $remoteuser@$ipaddr "sudo shutdown -h now"
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr will be shutdown" 9 55
else
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55
fi
exit 0
}
vncconnect()
{
# check if mediacenter is up
isitup
if [ $? = 0 ]; then
vncviewer $ipaddr &> /dev/null &
else
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55
fi
}
playmedia()
{
file="/home/media/Videos/series/the_big_bang_theory/season_4/BBTIV.14.avi"
# check if mediacenter is up
isitup
if [ $? = 0 ]; then
# selecting file
ssh -t $remoteuser@$ipaddr "dialog --fselect $mediapath 7 70 2> /tmp/dialog"
local file=$(ssh $remoteuser@$ipaddr "cat /tmp/dialog && rm /tmp/dialog")
ssh $remoteuser@$ipaddr "export DISPLAY=:0.0 && vlc --no-video-title-show -f $file &> /dev/null" &
else
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55
fi
}
killmedia()
{
# check if mediacenter is up
isitup
if [ $? = 0 ]; then
ssh $remoteuser@$ipaddr "killall vlc && killall rhythmbox"
else
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55
fi
}
# **** volume control ****
volumecontrol()
{
# check if mediacenter is up
isitup
if [ $? = 0 ]; then
# open up remote alsamixer
ssh -t $remoteuser@$ipaddr alsamixer
else
dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55
fi
}
# ****** start of actual script ******
# **** bash trap initialisation ****
trap bashtrap INT
# **** run navigation ****
# endless loop
while [ 1 ]; do
navigation
done
exit 0
# end of script

36
mediatool.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
#
# media lib/sorting tool
#
# **** config section ****
mediapath="/home/david/Videos"
workingdir="/home/david/Documents/code/scripts"
# **** requirements ****
#locate (for search feature)
# **** scanning mediapath ****
scan()
{
ls -RAhbl $mediapath | grep -v ^total | grep -v ^d > $workingdir/scan.txt
}
scan
exit 0
title=the_wire
cat=series
lang=en_ge
subs=en
container=avi
vcodec=h264
acodec=
nr=0401

View File

@ -1,10 +0,0 @@
#!/bin/bash
echo "starting jdownloader"
java -jar /home/david/Software/JDownloader/JDownloader.jar &> /dev/null
echo "exiting"
sleep 1
echo "byebye"
sleep 2
exit 0