From 5869505d64c04c536bdcd71a197ade918c36bf1c Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 10 Aug 2014 11:19:38 +0100 Subject: init --- 256colors | 63 ++++++++++ alarm | 24 ++++ aptitude-safe-upgrade | 8 ++ backup | 5 + backup-2pac | 10 ++ backup-2pac.exclude | 11 ++ backup.exclude | 8 ++ blink | 43 +++++++ chromium | 4 + cputemp | 15 +++ ddbench | 19 +++ demoterm.source | 3 + dup | 24 ++++ ebay-template | 37 ++++++ find-by-keyword | 8 ++ fn-f7 | 11 ++ forward-ports | 8 ++ func.zsh | 5 + gallery | 44 +++++++ hddtemp | 16 +++ jpegtran-rotate-lossless | 37 ++++++ killwifi | 6 + magnet | 6 + mdstat | 7 ++ mkinitcpio | 7 ++ mount-crypt | 9 ++ net-profile | 14 +++ offlineimap-switch | 12 ++ pdf2png | 226 +++++++++++++++++++++++++++++++++++ pdflatexup | 11 ++ ratcpi | 131 ++++++++++++++++++++ remote-home | 5 + spark | 89 ++++++++++++++ stopwatch | 56 +++++++++ strip-tags | 47 ++++++++ tatort-dl | 211 +++++++++++++++++++++++++++++++++ thinkwatt | 303 +++++++++++++++++++++++++++++++++++++++++++++++ try-qlogin | 10 ++ umount-crypt | 9 ++ updatepdf | 6 + upgrade-gentoo | 23 ++++ upgrade-kernel | 25 ++++ user-agents | 50 ++++++++ xfs-raid | 48 ++++++++ yt2mp3 | 21 ++++ 45 files changed, 1735 insertions(+) create mode 100755 256colors create mode 100755 alarm create mode 100755 aptitude-safe-upgrade create mode 100755 backup create mode 100755 backup-2pac create mode 100644 backup-2pac.exclude create mode 100644 backup.exclude create mode 100755 blink create mode 100755 chromium create mode 100755 cputemp create mode 100755 ddbench create mode 100644 demoterm.source create mode 100755 dup create mode 100755 ebay-template create mode 100755 find-by-keyword create mode 100755 fn-f7 create mode 100755 forward-ports create mode 100644 func.zsh create mode 100755 gallery create mode 100755 hddtemp create mode 100755 jpegtran-rotate-lossless create mode 100755 killwifi create mode 100755 magnet create mode 100755 mdstat create mode 100755 mkinitcpio create mode 100755 mount-crypt create mode 100755 net-profile create mode 100755 offlineimap-switch create mode 100755 pdf2png create mode 100755 pdflatexup create mode 100755 ratcpi create mode 100755 remote-home create mode 100755 spark create mode 100755 stopwatch create mode 100755 strip-tags create mode 100755 tatort-dl create mode 100755 thinkwatt create mode 100755 try-qlogin create mode 100755 umount-crypt create mode 100755 updatepdf create mode 100755 upgrade-gentoo create mode 100755 upgrade-kernel create mode 100644 user-agents create mode 100755 xfs-raid create mode 100755 yt2mp3 diff --git a/256colors b/256colors new file mode 100755 index 0000000..c97c2be --- /dev/null +++ b/256colors @@ -0,0 +1,63 @@ +#!/usr/bin/perl +# Author: Todd Larason +# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $ + +# use the resources for colors 0-15 - usually more-or-less a +# reproduction of the standard ANSI colors, but possibly more +# pleasing shades + +# colors 16-231 are a 6x6x6 color cube +for ($red = 0; $red < 6; $red++) { + for ($green = 0; $green < 6; $green++) { + for ($blue = 0; $blue < 6; $blue++) { + printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", + 16 + ($red * 36) + ($green * 6) + $blue, + ($red ? ($red * 40 + 55) : 0), + ($green ? ($green * 40 + 55) : 0), + ($blue ? ($blue * 40 + 55) : 0)); + } + } +} + +# colors 232-255 are a grayscale ramp, intentionally leaving out +# black and white +for ($gray = 0; $gray < 24; $gray++) { + $level = ($gray * 10) + 8; + printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", + 232 + $gray, $level, $level, $level); +} + + +# display the colors + +# first the system ones: +print "System colors:\n"; +for ($color = 0; $color < 8; $color++) { + print "\x1b[48;5;${color}m "; +} +print "\x1b[0m\n"; +for ($color = 8; $color < 16; $color++) { + print "\x1b[48;5;${color}m "; +} +print "\x1b[0m\n\n"; + +# now the color cube +print "Color cube, 6x6x6:\n"; +for ($green = 0; $green < 6; $green++) { + for ($red = 0; $red < 6; $red++) { + for ($blue = 0; $blue < 6; $blue++) { + $color = 16 + ($red * 36) + ($green * 6) + $blue; + print "\x1b[48;5;${color}m "; + } + print "\x1b[0m "; + } + print "\n"; +} + + +# now the grayscale ramp +print "Grayscale ramp:\n"; +for ($color = 232; $color < 256; $color++) { + print "\x1b[48;5;${color}m "; +} +print "\x1b[0m\n"; diff --git a/alarm b/alarm new file mode 100755 index 0000000..0aa0381 --- /dev/null +++ b/alarm @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + + +u = ARGV[0][-1] +t = ARGV[0][0..-2].to_f + +if u == 'h' + t *= 60 + t *= 60 +elsif u == 'm' + t *= 60 +elsif u == 's' + true +else + exit +end + +t = t.round(0) + +puts "sleeping for to #{t} seconds" + +sleep t +`mplayer ~/var/alarm.mp3 &>/dev/null` + diff --git a/aptitude-safe-upgrade b/aptitude-safe-upgrade new file mode 100755 index 0000000..b5c57d9 --- /dev/null +++ b/aptitude-safe-upgrade @@ -0,0 +1,8 @@ +#!/bin/zsh + + +. /home/pks/bin/func.zsh +check_root + +aptitude update && aptitude safe-upgrade -y + diff --git a/backup b/backup new file mode 100755 index 0000000..c8d6deb --- /dev/null +++ b/backup @@ -0,0 +1,5 @@ +#!/bin/zsh + + +sudo rsync -avv --exclude-from /home/pks/bin/backup.exclude --delete / /media/dock/b + diff --git a/backup-2pac b/backup-2pac new file mode 100755 index 0000000..f0d794e --- /dev/null +++ b/backup-2pac @@ -0,0 +1,10 @@ +#!/bin/zsh + + +. /home/pks/bin/func.zsh +check_root + +logger RSYNC BACKUP START +rsync -avv --delete --exclude-from /home/pks/bin/backup-2pac.exclude / /workspace/.b &>/var/log/backup.log +logger RSYNC BACKUP END + diff --git a/backup-2pac.exclude b/backup-2pac.exclude new file mode 100644 index 0000000..6fb95fc --- /dev/null +++ b/backup-2pac.exclude @@ -0,0 +1,11 @@ +/dev +/home/remote +/media +/mnt +/proc +/run +/sys +/tmp +/toolbox +/var +/workspace diff --git a/backup.exclude b/backup.exclude new file mode 100644 index 0000000..427b5b9 --- /dev/null +++ b/backup.exclude @@ -0,0 +1,8 @@ +/dev +/media +/mnt +/proc +/run +/sys +/tmp +/swapfile diff --git a/blink b/blink new file mode 100755 index 0000000..88c252b --- /dev/null +++ b/blink @@ -0,0 +1,43 @@ +#!/bin/sh +#_______________________________________________ +# blink.sh - ThinkBlink making ThinkLight blink +# author: Pawel Kazimierowicz www.PiKeyPL.com +#_______________________________________________ +# use: sh blink.sh [how many flashes] [how long flashes] +# eg. sh blink.sh 3 1 - three flashes for one second +# eg. sh blink.sh 2 5 - two flashes for five seconds +# +# http://pikeypl.com/index.php?show=code&menu=software&language=bash&code=blink.sh + + ile=$1; # ile mrugniec, parametr skryptu + i=1; # licznik do petli + +read d < /sys/class/leds/tpacpi\:\:thinklight/brightness #load state of ThinkLight +# when state = 0 - OFF, 255 - ON +# echo $d # print state of ThinkLight - for diagnostic. + +case "$d" in +# if ThinkLight if OFF: ON->OFF + "0") + while [ $i -le $ile ]; do + echo 255 > /sys/class/leds/tpacpi\:\:thinklight/brightness ; + sleep $2; + echo 0 > /sys/class/leds/tpacpi\:\:thinklight/brightness; + sleep $2; + i=$((i+1)); + + done;; + +# if ThinkLight is ON: OFF->ON +"255") + while [ $i -le $ile ]; do + echo 0 > /sys/class/leds/tpacpi\:\:thinklight/brightness; + sleep $2; + echo 255 > /sys/class/leds/tpacpi\:\:thinklight/brightness; + sleep $2; + i=$((i+1)); + done +esac + +# EOF ThinkBlink by Pawel Kazimierowicz + diff --git a/chromium b/chromium new file mode 100755 index 0000000..c0f60ff --- /dev/null +++ b/chromium @@ -0,0 +1,4 @@ +#!/bin/zsh + +/usr/bin/chromium-browser --no-referrers --user-agent="\"$(shuf -n 1 /home/pks/bin/user-agents)\"" ${1+"$@"} 2>/dev/null & + diff --git a/cputemp b/cputemp new file mode 100755 index 0000000..965a087 --- /dev/null +++ b/cputemp @@ -0,0 +1,15 @@ +#!/bin/zsh + + +MAX_TEMP=$1 + +for i in \ + /sys/devices/pci0000:00/0000:00:18.3/temp1_input \ + /sys/devices/pci0000:00/0000:00:19.3/temp1_input \ + /sys/devices/pci0000:00/0000:00:1a.3/temp1_input \ + /sys/devices/pci0000:00/0000:00:1b.3/temp1_input; do + TEMP=$(cat $i) + if [ $TEMP -gt $MAX_TEMP ]; then + logger "Some CPU temp @$TEMP (/1000)!" + fi +done diff --git a/ddbench b/ddbench new file mode 100755 index 0000000..8889392 --- /dev/null +++ b/ddbench @@ -0,0 +1,19 @@ +#!/bin/sh + + +for i in {0..4}; do +echo "WRITE SPEED" +dd if=/dev/zero of=tempfile bs=1M count=1024 conv=fdatasync,notrunc +echo + +echo "READ SPEED" +echo 3 > /proc/sys/vm/drop_caches +dd if=tempfile of=/dev/null bs=1M count=1024 +echo + +echo "BUFFERED READ SPEED" +dd if=tempfile of=/dev/null bs=1M count=1024 + +rm tempfile +done + diff --git a/demoterm.source b/demoterm.source new file mode 100644 index 0000000..afe7570 --- /dev/null +++ b/demoterm.source @@ -0,0 +1,3 @@ +LS_COLORS='rs=0:di=00;34:ln=00;36:mh=00:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.tlz=00;31:*.txz=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.dz=00;31:*.gz=00;31:*.lz=00;31:*.xz=00;31:*.bz2=00;31:*.bz=00;31:*.tbz=00;31:*.tbz2=00;31:*.tz=00;31:*.deb=00;31:*.rpm=00;31:*.jar=00;31:*.war=00;31:*.ear=00;31:*.sar=00;31:*.rar=00;31:*.ace=00;31:*.zoo=00;31:*.cpio=00;31:*.7z=00;31:*.rz=00;31:*.jpg=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.svg=00;35:*.svgz=00;35:*.mng=00;35:*.pcx=00;35:*.mov=00;35:*.mpg=00;35:*.mpeg=00;35:*.m2v=00;35:*.mkv=00;35:*.webm=00;35:*.ogm=00;35:*.mp4=00;35:*.m4v=00;35:*.mp4v=00;35:*.vob=00;35:*.qt=00;35:*.nuv=00;35:*.wmv=00;35:*.asf=00;35:*.rm=00;35:*.rmvb=00;35:*.flc=00;35:*.avi=00;35:*.fli=00;35:*.flv=00;35:*.gl=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.yuv=00;35:*.cgm=00;35:*.emf=00;35:*.axv=00;35:*.anx=00;35:*.ogv=00;35:*.ogx=00;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'; +export LS_COLORS + diff --git a/dup b/dup new file mode 100755 index 0000000..3809c16 --- /dev/null +++ b/dup @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + + +dir = ARGV[0] +a = `find #{dir} -type f`.split "\n" + +h = {} +a.each { |fn| + md5 = `md5sum "#{fn}" | cut -d " " -f1` + if h.has_key? md5 + h[md5] << fn + else + h[md5] = [fn] + end +} + +h.each { |k,v| + if v.size > 1 + puts k + v.each { |i| puts "\t#{i}" } + puts + end +} + diff --git a/ebay-template b/ebay-template new file mode 100755 index 0000000..6c409cd --- /dev/null +++ b/ebay-template @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby + +require 'haml' + + +template = ' +%div(style="margin:2em;border:0;background:#ffffcc;font-family:Georgia") + %div(style="margin:1em") + %h1(style="border-bottom:2px solid #fff") + Name + %p(style="margin-left:5%") + Beschreibung + %div(style="margin-left:10%") + %h2 Bilder: + - picCount.times do |i| + %a(href="http://simianer.de/ebay/#{picName}#{i+1}.jpg" target="_blank") + %img(style="border:2px solid blue;float:left;margin:20px;" src="http://simianer.de/ebay/#{picName}#{i+1}t.jpg") + %div(style="clear:left") + %br + %br + %p + Bitte beachten Sie auch meine anderen Artikel!
Ersteigern Sie mehrere Artikel, so zahlen Sie nur 1x Versandkosten. + %h3(style="margin-bottom:0px") + Viel Spaß beim Bieten! :-)' + + +if __FILE__ == $0 + picName = ARGV[0] + picCount = ARGV[1] + + haml_engine = Haml::Engine.new(template) + puts haml_engine.render( + Object.new, + locals={:picName => picName, :picCount => picCount.to_i} + ) +end + diff --git a/find-by-keyword b/find-by-keyword new file mode 100755 index 0000000..adea961 --- /dev/null +++ b/find-by-keyword @@ -0,0 +1,8 @@ +#!/bin/zsh + + +for i in `find . -type f`; do + A=$(jhead $i 2>/dev/null | grep Keyword | grep $1) + if [ "$A" != "" ]; then echo $i; fi +done + diff --git a/fn-f7 b/fn-f7 new file mode 100755 index 0000000..0239c8d --- /dev/null +++ b/fn-f7 @@ -0,0 +1,11 @@ +#!/bin/sh + + +if [ -a /tmp/vgaclone ]; then + xrandr --output VGA-0 --off + rm /tmp/vgaclone +else + xrandr --output VGA-0 --mode 1024x768 + touch /tmp/vgaclone +fi + diff --git a/forward-ports b/forward-ports new file mode 100755 index 0000000..f13307a --- /dev/null +++ b/forward-ports @@ -0,0 +1,8 @@ +#!/bin/zsh + + +. /home/pks/bin/func.zsh +check_root + +iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000 + diff --git a/func.zsh b/func.zsh new file mode 100644 index 0000000..470f5db --- /dev/null +++ b/func.zsh @@ -0,0 +1,5 @@ +check_root() +{ + if [ `whoami` != root ]; then echo "Run this script as root, exiting!"; exit; fi +} + diff --git a/gallery b/gallery new file mode 100755 index 0000000..e134e23 --- /dev/null +++ b/gallery @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +gallery +make a nice little web gallery + +Patrick Simianer +2010-03-31 +""" + +import sys, os, glob, subprocess, shlex + + +def main(): + try: + path = sys.argv[1] + except IndexError: + print 'Usage: gallery.py /path/to/images/' + sys.exit(1) + path += '/' + files = glob.glob(path+'*.jpg') + if not os.path.exists(path+'thumbs'): + os.mkdir(path+'thumbs') + files.sort() + for f in files: + cmd = 'convert "'+f+'" -resize 320x320 "'+path+'thumbs/'+f.split('/')[-1]+'"' + a = shlex.split(cmd) + subprocess.Popen(a) + + print '' + print '

Anklicken zum Vergrößern

' + for f in files: + print '
' + print '' + print '
' + print '
' + + + + +if __name__ == '__main__': + main() + diff --git a/hddtemp b/hddtemp new file mode 100755 index 0000000..1b37d54 --- /dev/null +++ b/hddtemp @@ -0,0 +1,16 @@ +#!/bin/zsh + + +. /home/pks/bin/func.zsh +check_root + +MAX_TEMP=$1 + +for i in `ls -1 /dev/disk/by-id/ | grep -v -P "^wwn-|\-part\d$|md-name|md-uuid"`; do + DRIVE="/dev/disk/by-id/$i" + TEMP=$(/usr/sbin/hddtemp -n $DRIVE 2>/dev/null) + if [ "$TEMP" != "" ]; then + if [ $TEMP -gt $MAX_TEMP ]; then logger "$DRIVE temp at $TEMP"; fi + fi +done + diff --git a/jpegtran-rotate-lossless b/jpegtran-rotate-lossless new file mode 100755 index 0000000..77a0949 --- /dev/null +++ b/jpegtran-rotate-lossless @@ -0,0 +1,37 @@ +#!/bin/sh + + +function usage { + echo 'Usage: jpegtran-rotate-lossless.sh <90|180|270> ' + exit 1 +} + +ROTATION=$1 +FILE=$2 + +if [ $# -ne 2 ]; then + usage +fi + +case $ROTATION in + 90|180|270) + true ;; + *) + usage ;; +esac + + +jpegtran -rotate $ROTATION -trim -copy all $FILE > $FILE-rotate +if [ $? -ne 0 ]; then + echo 'jpegtran-rotate-lossless.sh: jpegtran failed' + exit 1 +fi + +mv $FILE-rotate $FILE +if [ $? -ne 0 ]; then + 'jpegtran-rotate-lossless.sh: mv failed' + exit 1 +fi + +exit 0 + diff --git a/killwifi b/killwifi new file mode 100755 index 0000000..15b278d --- /dev/null +++ b/killwifi @@ -0,0 +1,6 @@ +#!/bin/sh + + +sudo /etc/init.d/dhcpcd stop +sudo killall wpa_supplicant + diff --git a/magnet b/magnet new file mode 100755 index 0000000..c60297d --- /dev/null +++ b/magnet @@ -0,0 +1,6 @@ +#!/bin/bash + +cd ~/z +[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit; +echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent" + diff --git a/mdstat b/mdstat new file mode 100755 index 0000000..3e4eaf1 --- /dev/null +++ b/mdstat @@ -0,0 +1,7 @@ +#!/bin/zsh + + +S=$(awk '/^md/ {printf "%s: ", $1}; /blocks/ {print $NF}' /boot/initramfs.cpio.gz + diff --git a/mount-crypt b/mount-crypt new file mode 100755 index 0000000..9c86163 --- /dev/null +++ b/mount-crypt @@ -0,0 +1,9 @@ +#!/bin/bash + + +. /home/pks/bin/func.zsh +check_root + +cryptsetup luksOpen /dev/disk/by-id/scsi-SATA_WDC_WD1002FAEX-_WD-WCAW32441082-part1 remote_backup +mount /dev/mapper/remote_backup /mnt/ + diff --git a/net-profile b/net-profile new file mode 100755 index 0000000..3234f8c --- /dev/null +++ b/net-profile @@ -0,0 +1,14 @@ +#!/bin/sh + + +setup_wifi() +{ + sudo wpa_supplicant -D wext -i wlan0 -c ~/.net_profiles/$1.conf &>/dev/null & + sudo /etc/init.d/dhcpcd start + sleep 30 + sudo rc-config start ntp-client +} + +setup_wifi $1 + + diff --git a/offlineimap-switch b/offlineimap-switch new file mode 100755 index 0000000..ef7328d --- /dev/null +++ b/offlineimap-switch @@ -0,0 +1,12 @@ +#!/bin/sh + + +case `date +"%a"` in + Sat|Sun) + offlineimap -a private + ;; + *) + offlineimap + ;; +esac + diff --git a/pdf2png b/pdf2png new file mode 100755 index 0000000..0676440 --- /dev/null +++ b/pdf2png @@ -0,0 +1,226 @@ +#!/bin/bash +############################################################################### +# # +# Martin Bruchanov, bruxy at regnet dot cz # +# # +# http://bruxy.regnet.cz/ # +# # +# Version: 1.2 (Fri Jul 20 13:17:18 CEST 2012) # +# # +############################################################################### + +## Defaults +DEFAULT_DPI=300 # default output dpi +GS_DPI=300 # gs will rasterize to this size, before resizing +UNSHARP_RADIUS=1.0 # bitmap enhancing with unsharp mask +COLORS=16777216 # default num. of colors, use 16, 256,... + +## Global variables +PAGE_START=1 +PAGE_STOP=1 +WIDTH=0 +HEIGHT=0 +PAGE=0 +ALL=0 + +## Help +print_help(){ + echo "PDF2PNG" + echo "Usage: " `basename $0` [OPTIONS] FILE + echo + echo "Options:" + echo " -h ... this help" + echo " -a ... convert all pages" + echo " -f N ... from page number N" + echo " -t N ... to page number N" + echo " -p N ... only page N (default N = 1)" + echo " -d N ... resolution in dpi (default N = $DEFAULT_DPI)" + echo " -x N ... bitmap width in pixel (if y not given, save aspect ratio)" + echo " -y N ... bitmap height in pixel (if x not given, save aspect ratio)" + echo " -u N ... unsharp radius (default N = $UNSHARP_RADIUS)" + echo " -c N ... number of colors (default N = $COLORS)" + echo +} + +# definition of color escape sequences for ANSI terminal +RED="\033[01;31m" +GREEN="\033[01;32m" + +color_echo(){ +# 1 -- color escape sequncy +# 2 -- string +# \033[0m -- reset color settings + echo -e "$1 $2 \033[0m" +} + + +test_return(){ +# 1 -- return code $? +# 2 -- description of operation +echo -e -n $2: +COL=40 +# move cursor to column $COL +echo -en "\033[${COL}G" +if [ $1 -eq 0 ] +then + color_echo $GREEN OK +else + color_echo $RED FALSE + exit 1 +fi +} + +if [ $# -lt 1 ] # print help +then + print_help + exit 1 +fi + +## Process CLI + +while getopts "af:t:d:hx:y:w:u:p:c:" name +do + case $name in + a) ALL=1 + ;; + f) PAGE_START=$OPTARG + ;; + t) PAGE_STOP=$OPTARG + ;; + p) PAGE=$OPTARG + ;; + d) DEFAULT_DPI=$OPTARG + ;; + x) WIDTH=$OPTARG + ;; + y) HEIGHT=$OPTARG + ;; + u) UNSHARP_RADIUS=$OPTARG + ;; + c) COLORS=$OPTARG + ;; + h) # help + print_help + exit 0 + ;; + \?) + echo "Invalid option!" + exit 1 + ;; + esac +done + + +shift $(($OPTIND - 1)); + +INPUT=$1 + +OUTPUT=$(basename $INPUT .pdf) + +echo "Input file: $INPUT" + +## Check all input parameters and set options + +if [ -z "$INPUT" ] +then + echo "No input file!" + exit 1 +fi + +# All pages processing + +MAX_PAGE=`pdfinfo "$INPUT" | grep Pages | awk '{ print $2}'` + +if [ -z $MAX_PAGE ]; then exit; fi + +if [ $ALL -eq 1 ] +then + PAGE_START=1 + PAGE_STOP=$MAX_PAGE +fi + +# Page range processing + +if [ $PAGE_START -gt 1 ] +then + if [ $PAGE_STOP -eq 1 ] + then + PAGE_STOP=$MAX_PAGE + fi +fi + +if [ $PAGE_STOP -gt 1 ] +then + if [ $PAGE_START -eq 1 ] + then + PAGE_START=1 + fi +fi + +if [ $PAGE -gt 0 ] +then + PAGE_START=$PAGE + PAGE_STOP=$PAGE +fi + +# Image size + +if [ $WIDTH -gt 0 ] +then + if [ $HEIGHT -gt 0 ] + then + RESIZE=${WIDTH}x${HEIGHT}\! + else + RESIZE=${WIDTH}x + fi + DEFAULT_DPI=0 +fi + +if [ $HEIGHT -gt 0 ] +then + if [ $WIDTH -gt 0 ] + then + RESIZE=${WIDTH}x${HEIGHT}\! + else + RESIZE=x${HEIGHT} + fi + DEFAULT_DPI=0 +fi + +if [ $DEFAULT_DPI -gt 0 ] +then + RESIZE=$(((DEFAULT_DPI*100)/GS_DPI))"%" +fi + +echo $RESIZE +#exit + +############################################################################## + +echo "Rasterizing pages from $PAGE_START to $PAGE_STOP." +echo "Output image size: $RESIZE" + +j=1 +N=$((PAGE_STOP-PAGE_START+1)) +for i in `seq $PAGE_START $PAGE_STOP` +do + i=`printf %04u $i` + echo "Processing page no. $i ($j/$N)" + TMP=/tmp/tmp-${i}.png + gs -q -sDEVICE=png16m -dBATCH -dNOPAUSE \ + -dFirstPage=$i -dLastPage=$i -r$GS_DPI \ + -sOutputFile=$TMP "$INPUT" > /dev/null 2>&1 + + test_return $? "GhostScript conversion" + + convert \ + -unsharp "$UNSHARP_RADIUS" \ + -resize "${RESIZE}" \ + -colors $COLORS +dither \ + $TMP png:${OUTPUT}_${i}.png + + rm -f $TMP + : $((j++)) +done + + diff --git a/pdflatexup b/pdflatexup new file mode 100755 index 0000000..19b755d --- /dev/null +++ b/pdflatexup @@ -0,0 +1,11 @@ +#!/bin/sh + + +/usr/bin/pdflatex $1 + +if [ $? -eq 0 ]; then +if [ -e .mupdf.pid ]; then + kill -1 $(cat .mupdf.pid) +fi +fi + diff --git a/ratcpi b/ratcpi new file mode 100755 index 0000000..1ce58d3 --- /dev/null +++ b/ratcpi @@ -0,0 +1,131 @@ +#!/bin/bash + +#====================================================== +# RatCPI version .10--Power management, Ratpoison style +# By Door +#====================================================== + +## Do you want to be informed of charging status? +## This is distinct from "losing power" status. +## 0=no, 1=yes +informcharged=1 + +## How long to wait before in between checks. +## Default: 2 minutes (120 seconds) +delay=120 + +## Various important variables +plugged=$(eval acpi -V|grep off-line|wc -l) +charging=$(eval acpi -V|grep charging|wc -l) +never=$(eval acpi -V|grep never|wc -l) +battlevel=$(eval acpi) + +if (($plugged==1)) +then +eval 'ratpoison -c "echo $battlevel"' + +elif (($charging==1)) +then +eval 'ratpoison -c "echo $battlevel"' + +else +echo $battlevel > /dev/null +fi + +while winsys=$(ps -e | grep ratpoison | wc -l) + [ "$winsys" != 0 ] + do + + charge=$(eval acpi -V|grep charge|wc -l) + never2=$(eval acpi -V|grep never|wc -l) + + lowbatt50=$(eval acpi|grep 50%|wc -l) + lowbatt25=$(eval acpi|grep 25%|wc -l) + lowbatt15=$(eval acpi|grep 15%|wc -l) + lowbatt10=$(eval acpi|grep 10%|wc -l) + lowbatt5=$(eval acpi|grep \ 5%|wc -l) + lowbatt3=$(eval acpi|grep \ 3%|wc -l) + lowbatt1=$(eval acpi|grep \ 1%|wc -l) + + hibat95=$(eval acpi|grep 95%|wc -l) + hibat75=$(eval acpi|grep 75%|wc -l) + +if (($charge==1)) + then + + if (($informcharged==0)) + then + continue + + elif (($never2==1)) + then + echo $lowbatt50 > /dev/null + + elif (($hibat95==1)) + then + eval 'ratpoison -c "echo Battery charged to 95%"' + + elif (($hibat75==1)) + then + eval 'ratpoison -c "echo Battery charged to 75%"' + + elif (($lowbatt50==1)) + then + eval 'ratpoison -c "echo Battery charged to 50%"' + + elif (($lowbatt25==1)) + then + eval 'ratpoison -c "echo Battery charged to 25%"' + + elif (($lowbatt10==1)) + then + eval 'ratpoison -c "echo Battery charged to 10%"' + + fi + +fi + +if (($charge==0)) + then + + if (($hibat95==1)) + then + eval 'ratpoison -c "echo Battery at 95%"' + + elif (($hibat75==1)) + then + eval 'ratpoison -c "echo Battery at 75%"' + + elif (($lowbatt50==1)) + then + eval 'ratpoison -c "echo Battery at 50%"' + + elif (($lowbatt25==1)) + then + eval 'ratpoison -c "echo Battery at 25%"' + + elif (($lowbatt15==1)) + then + eval 'ratpoison -c "echo Battery at 15%"' + + elif (($lowbatt10==1)) + then + eval 'ratpoison -c "echo Battery at 10%"' + + elif (($lowbatt5==1)) + then + eval 'ratpoison -c "echo Battery at 5%!"' + + elif (($lowbatt3==1)) + then + eval 'ratpoison -c "echo Battery at 3%!"' + + elif (($lowbatt1==1)) + then + eval 'ratpoison -c "echo The battery is at 1%! Plug it in or turn it off!"' + fi + +fi + +sleep $delay +done diff --git a/remote-home b/remote-home new file mode 100755 index 0000000..3ae11a5 --- /dev/null +++ b/remote-home @@ -0,0 +1,5 @@ +#!/bin/sh + + +sshfs simianer@diddley:/srv/nfs/home_mitarb/simianer/ /mnt -o idmap=user -o uid=1337 -o gid=100 + diff --git a/spark b/spark new file mode 100755 index 0000000..9041a12 --- /dev/null +++ b/spark @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# +# spark +# https://github.com/holman/spark +# +# Generates sparklines for a set of data. +# +# Here's a a good web-based sparkline generator that was a bit of inspiration +# for spark: +# +# https://datacollective.org/sparkblocks +# +# spark takes a comma-separated list of data and then prints a sparkline out of +# it. +# +# Examples: +# +# spark 1 5 22 13 53 +# # => ▁▁▃▂▇ +# +# spark 0 30 55 80 33 150 +# # => ▁▂▃▅▂▇ +# +# spark -h +# # => Prints the spark help text. + +# Generates sparklines. +# +# $1 - The data we'd like to graph. +spark() +{ + local n numbers= + + # find min/max values + local min=0xffffffff max=0 + + for n in ${@//,/ } + do + # on Linux (or with bash4) we could use `printf %.0f $n` here to + # round the number but that doesn't work on OS X (bash3) nor does + # `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off + n=${n%.*} + (( n < min )) && min=$n + (( n > max )) && max=$n + numbers=$numbers${numbers:+ }$n + done + + # print ticks + local ticks=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █) + + local f=$(( (($max-$min)<<8)/(${#ticks[@]}-1) )) + (( f < 1 )) && f=1 + + for n in $numbers + do + echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]} + done + echo +} + +# If we're being sourced, don't worry about such things +if [ "$BASH_SOURCE" == "$0" ]; then + # Prints the help text for spark. + help() + { + cat < $indexfile +tagspresent=`sort -u $indexfile | awk -F\): '/^<.*$/ {print $1}' \ +| uniq | awk -F\)\> '{print $1}' | awk -F\( '{print $(NF)}' \ +| awk 'BEGIN {ORS=" "} {print $0}'` + +rm $indexfile + +#Determine tags to strip: +tostrip=`echo -n $tagspresent $oktags $oktags \ +| awk 'BEGIN {RS=" "; ORS="\n"} {print $0}' | sort | uniq -u \ +| awk 'BEGIN {ORS=" "} {print $0}'` + +#Confirm action: +echo +echo The following tags have been found in the mp3s: +echo $tagspresent +echo These tags are to be stripped: +echo $tostrip +echo +echo -n Press enter to confirm, or Ctrl+C to cancel... +read dummy + +#Strip 'em +stripstring=`echo $tostrip \ +| awk 'BEGIN {FS="\n"; RS=" "} {print "--set-text-frame=" $1 ": "}'` + +# First pass copies any v1.x tags to v2.3 and strips unwanted tag data. +# Second pass removes v1.x tags, since I don't like to use them. +# Without --no-tagging-time-frame, a new unwanted tag is added. :-) + +find . -iname "*.mp3" \ +-exec eyeD3 --to-v2.3 --no-tagging-time-frame $stripstring {} \; \ +-exec eyeD3 --remove-v1 --no-tagging-time-frame {} \; + +echo "Script complete!" + diff --git a/tatort-dl b/tatort-dl new file mode 100755 index 0000000..71bd465 --- /dev/null +++ b/tatort-dl @@ -0,0 +1,211 @@ +#!/bin/bash +# tatort-dl - download movies from ARDmediathek using rtmpdump +# Copyright (C) 2010-2012 Robin Gareus +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +RTMPDUMP=${RTMPDUMP:-rtmpdump} +INTERACTIVE= +GETURLONLY= +QUIET= + +while getopts ":Vhigq" opt; do + case $opt in + V) + echo "tator-dl v2013-01-28" + echo + echo "Copyright (C) 2010-2013 Robin Gareus" + echo "This is free software; see the source for copying conditions. There is NO" + echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + exit 0 + ;; + h) + echo "tatort-dl - CLI tool for downloading films from http://www.ardmediathek.de/. " + echo + echo "Usage: tatort-dl [-i] [-g] [-q] [OutFileName] " + echo + echo "Wrapper script to parse rtmp and mp4 URLs from the ard-mediathek and launch" + echo "a download using 'rtmpdump'." + echo "The default out-file name is ./format.flv" + echo "-i option: interactive mode - ask before taking any action." + echo "-g option: get URL - just print rtmp URL and exit" + echo "-q option: quiet, inhibit usual output" + echo + echo "Environment:" + echo "RTMPDUMP=rtmpdump" + echo + echo "Example:" + echo "tatort-dl \"http://www.ardmediathek.de/ard/servlet/content/3517136?documentId=3701294\"" + echo + echo "Report bugs to ." + echo "Website http://gareus.org/wiki/tatort-dl" + exit 0 + ;; + q) + QUIET=yes + shift; + ;; + g) + GETURLONLY=yes + QUIET=yes + shift; + ;; + i) + INTERACTIVE=yes + shift; + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +URL=$(echo -e "$1" | grep "^http") +OUTFILE=$2 + +RTMPDUMPOPTS="" +#RTMPDUMPOPTS+=" --live" +#RTMPDUMPOPTS+=" --resume" +#RTMPDUMPOPTS+=" --quiet" + +if test -z "$URL" ; then + echo -e "Error: missing or invalid parameters\n\nUsage:\n $0 [out-file]\nThe deafult out-file name is ./format.f4v\n\nExample:\n $0 \"http://www.ardmediathek.de/ard/servlet/content/3517136?documentId=3701294\"\n" >&2; + exit 1 +fi + +[[ -z "$QUIET" ]] && echo -en "curl \"$URL\" .." +RTMPURLS=$(curl -s "$URL" | grep -i rtmp) + + +if test -z "$RTMPURLS" ; then + echo -e "\nError: no 'rtmp://' URLs were found on the given Page.\n" >&2 + exit 1; +fi + +COUNT=$(echo -e "$RTMPURLS" | wc -l) +[[ -z "$QUIET" ]] && echo -e " ..found $COUNT RTMP URL(s)." + +urldecode(){ + echo -e "$(sed 'y/+/ /; s/%/\\x/g')" +} + +FLASH=$(echo "$RTMPURLS" | grep flashvars | tail -n1) +if test -n "$FLASH"; then + + RTMPURL=$(echo -ne "$FLASH" \ + | sed 's/^.*streamer=\([^&]*\)&.*$/\1/g' \ + | urldecode) + PLAYPATH=$(echo -ne "$FLASH" \ + | sed 's/^.*file=\([^&]*\)&.*$/\1/g' \ + | urldecode) + #echo "RTMP: $RTMPURL" + #echo "FILE: $PLAYPATH" + +else + + # try high-qualty first + PARAM=$(echo "$RTMPURLS" | grep Web-L) + # fall-back to medium-qualty + if test -z "$PARAM"; then + PARAM=$(echo "$RTMPURLS" | grep Web-M) + fi + # 2nd fall-back: use any rtmp URL + if test -z "$PARAM"; then + PARAM=$(echo "$RTMPURLS" | tail -n 1 ) + fi + + RTMPURL=$(echo -ne "$PARAM" | sed 's/^.*"\(rtmp[t]*:[^"]*\)",.*$/\1/g') + PLAYPATH=$(echo -ne "$PARAM" | sed 's/^.*"\(mp4:[^"]*\)"[),].*$/\1/g') +fi + +test -z "$RTMPURL" && RTMPURL="rtmp://vod.daserste.de/ardfs/" + +if test -n "$GETURLONLY"; then + PLAYPATH2=$(echo -ne "$PLAYPATH" | sed 's/^mp4://g') + echo -n "$RTMPURL$PLAYPATH2" + exit +fi + +if test -z "$OUTFILE"; then + OUTFILE=$(echo -ne "$PLAYPATH" | sed 's/^mp4:.*\/\([^\/?]*\)\?.*$/\1/g') + OUTFILE=$(echo -ne "$OUTFILE" \ + | sed 's/^.*\///g' \ + | sed 's/\?.*$//g' \ + | sed 's/mp4://g' \ + | sed 's/\.f4v$//' \ + | sed 's/\.flv$//'\ + ) + OUTFILE="${OUTFILE}.flv" +fi + +if test -z "$QUIET"; then + echo + echo "Parameters:" + echo " RTMP-URL : $RTMPURL" + echo " Playpath : $PLAYPATH" + echo " Saving to: $OUTFILE" + echo -n " PWD : " + pwd + echo +fi + +if test -z "$PLAYPATH -o -z "$OUTFILE ; then + echo "Error: empty playpath or blank output filename." >&2 + exit 1 +fi + +if test -e "$OUTFILE"; then + echo "WARNING: output file "$OUTFILE" exists." >&2 + if test -n "$INTERACTIVE"; then + echo -n "[A]bort/[d]elete it/[r]esume? [A/d/r]? " + read -n 1 VAL + echo + if test "$VAL" == "d"; then + rm -i "$OUTFILE"; + elif test "$VAL" == "r"; then + RTMPDUMPOPTS+=" --resume" + else + exit; + fi + else # NON-INTERACTIVE + echo "Error: file exists. bailing out." + exit + fi +fi + +if test -n "$INTERACTIVE"; then + echo "rtmpdump command-line:" + echo " #$RTMPDUMP $RTMPDUMPOPTS -o \"$OUTFILE\" --playpath \"$PLAYPATH\" -r $RTMPURL" + echo + + echo -n " Start Download ? [Y/n] " + read -n 1 VAL + echo + if test "$VAL" == "n" -o "$VAL" == "N"; then + exit; + fi +fi + +$RTMPDUMP $RTMPDUMPOPTS -o "$OUTFILE" --playpath "$PLAYPATH" -r $RTMPURL + +if test -z "$QUIET"; then + echo + ls -l "$OUTFILE" +fi diff --git a/thinkwatt b/thinkwatt new file mode 100755 index 0000000..fbdeb94 --- /dev/null +++ b/thinkwatt @@ -0,0 +1,303 @@ +#!/bin/bash +# +# thinkwatt: +# record power consumption, calculate average and create a gnuplot graph +# +# TO-DO: +# * add more options (e.g. for specifying a different gnuplot title or png output) +# * allow time input in minutes and hours + +# utilities {{{ +message() { + cat << EOF +usage: thinkwatt -r (seconds) (-q) (-o file) + thinkwatt [ -p | -a ] (-q) file + +options: + -r, --record record power consumption and optionally create a graph from the gathered data + -p, --plot create a plot image from a specified data file + -a, --average calculate the average power consumption from a specified data file + -q, --quiet makes thinkwatt less chatty + -o, --output the output file. can be prepended by a path. + -h, --help show this help text + +examples: + thinkwatt -r (will record to a temp file until cancelled) + thinkwatt -r 300 -o /foo/bar/consumption.dat (will record for 5 minutes to the specified file) + thinkwatt -p /foo/bar/consumption.dat (will create a graph from the specified file) +EOF + exit 1 +} + +errorout() { echo "error: $*" >&2; exit 1; } + +check_ac() { + local acfile=/sys/class/power_supply/AC/online + [[ $(cat "$acfile") = 0 ]] || errorout 'please unplug the ac adapater first' +} +check_datafile() { + [[ -f "$@" ]] || errorout "$@ does not exist" + local valid_file=$(file "$@" | grep -s "^$@: ASCII text$") + [[ "$valid_file" ]] || errorout "$@ is not a valid data file" + local valid_data=$(cat "$@" | grep -s '^[0-9]*[,.]\?.*[0-9]$') + [[ "$valid_data" ]] || errorout "$@ does not contain valid data" +} +countdown() { + if [[ "$seconds" =~ ^[0-9]+$ ]];then + # count down + secs="$seconds" + while [ "$secs" -gt 0 ];do + [[ "$die" == yes ]] && return 0 + sleep 1 & + cat "$powerfile" >> "$tmpfile1" + printf "\rrecording (%02d/$seconds)" $((secs)) + secs=$(( $secs - 1 )) + wait + done + else + # count up + secs=1 + while true;do + [[ "$die" == yes ]] && return 0 + sleep 1 & + cat "$powerfile" >> "$tmpfile1" + printf "\rrecording ($secs)" + secs=$(( $secs + 1 )) + wait + done + fi + echo +} +# if we abort the recording process with ctrl+c this will give the option to plot the already recorded data +trap ctrl_c INT +function ctrl_c() { + echo + read -p "plot already recorded data before exiting? y/n " + [[ "$REPLY" = "y" ]] && die=yes || exit 0 +} +# }}} + +# default output dir and png file {{{ +# use $TDIR to have thinkwatt save files in a different directory. +# thinkwatt will save two files: +# 1) a .plt file (containing plot instructions) in case you want to reuse/modify it +# 2) a .png file (the plot graphic) +TDIR="/tmp/thinkwatt" +PLOTFILE="$TDIR"/$$.plt +# }}} + +# record {{{ +record() { + + local seconds="$1" + + #[[ "$seconds" =~ ^[0-9]+$ ]] || errorout 'please specify the time in seconds" + [[ -d "$output" ]] && errorout "$output is a directory" + [[ -d "$TDIR" ]] || mkdir -p "$TDIR" 2>/dev/null || errorout "could not create $TDIR" + + if [[ -f "$output" ]];then + read -p "overwrite $output? y/n " + [[ "$REPLY" = "y" ]] || exit 0 + elif [[ -e "$output" ]];then + errorout "$output exists and can/should not be written to" + fi + + local tmpfile1=/tmp/$$.dat + local tmpfile="$TDIR"/$$.dat + + if [[ "$output" ]];then + local dir=$(dirname "$output") + local file=$(basename "$output") + [[ -d "$dir" ]] || mkdir -p "$dir" + [[ -w "$dir" ]] || errorout "you don't have permissions to write to $dir" + + outputfile="$output" + [[ "$dir" ]] && TDIR="$dir" + PNGFILE="$TDIR"/$(basename "$file" .dat).png + #PLOTFILE="$TDIR"/$(basename "$output" .dat).plt + else + [[ -w "$(pwd)" ]] || errorout "you don't have permissions to write to $(pwd)" + local file=$(basename "$tmpfile") + outputfile="$tmpfile" + local istemp=true + fi + + SMAPI=$(lsmod | grep -s tp_smapi) + if [[ "$SMAPI" ]];then + local powerfile=/sys/devices/platform/smapi/BAT0/power_now + else + echo "for more accurate results use tp_smapi" + local powerfile=/sys/class/power_supply/BAT0/power_now + fi + + touch "$tmpfile1" || errorout "could not create $tmpfile1" + trap "rm $tmpfile1" EXIT + + # do the actual recording included in countdown() + countdown + + # file formatting + if [[ "$SMAPI" ]];then + # we strip the leading "-" from the data file + sed -i 's/-//g' "$tmpfile1" + else + # strip the trailing last 3 characters + sed -i 's/.\{3\}$//' "$tmpfile1" + fi + # and divide by 1000 to convert from mW to W + cat "$tmpfile1" | awk '{print $1/1000}' > "$tmpfile" + + [[ "$output" ]] && mv "$tmpfile" "$output" + + [[ "$quiet" ]] || echo average was $(average "$outputfile") W + + plot "$outputfile" + +} +# }}} + +# calculate average {{{ +average() { + + [[ "$@" ]] || errorout 'please specify a file to read from.' + [[ -f "$@" ]] || errorout 'file not found.' + check_datafile "$@" + + awk 'BEGIN{s=0;}{s+=($1);}END{print s/NR;}' "$@" + +} +# }}} + +# make the plot file {{{ +makeplotfile() { + + cat << EOF +# gnuplot file +# created by thinkwatt +# $DATE + +set title "$TITLE" +set xlabel "$XLABEL" +set ylabel "$YLABEL" +set terminal $TERMINAL +set output "$PNGFILE" +EOF + [[ "$YRANGE" ]] && echo "set yrange $YRANGE" + [[ "$XRANGE" ]] && echo "set yrange $YRANGE" + [[ "$GRID" == yes ]] && echo "set grid" + [[ "$YTICS" ]] && echo "set ytics $YTICS" + [[ "$MYTICS" ]] && echo "set mytics $MYTICS" + [[ "$XTICS" ]] && echo "set xtics $XTICS" + [[ "$MXTICS" ]] && echo "set mxtics $MXTICS" + [[ "$GRIDSET" ]] && echo "set grid $GRIDSET" + + echo + if [[ "$TITLE1" ]];then + echo "plot \"$datafile\" using (\$1) with lines title \"$TITLE1\" lt 2, \\" + else + echo "plot \"$datafile\" using (\$1) with lines lt 2, \\" + fi + + if [[ "$TITLE2" ]];then + if [[ "$avg" ]];then + echo "\"$datafile\" using (\$1) smooth bezier title \"$TITLE2\" lt 1, \\" + else + echo "\"$datafile\" using (\$1) smooth bezier title \"$TITLE2\" lt 1" + fi + else + if [[ "$avg" ]];then + echo "\"$datafile\" using (\$1) smooth bezier lt 1, \\" + else + echo "\"$datafile\" using (\$1) smooth bezier lt 1" + fi + fi + + [[ "$avg" ]] && echo "$avg title \"$file (average, $avg W)\"" + +} +# }}} + +# do the plotting +plot() { + + # check if we have gnuplot and $TDIR is present + have_gnuplot=$(find $(sed 's/:/ /g' <<<$PATH) 2>/dev/null | grep -is gnuplot) + [[ "$have_gnuplot" ]] || errorout 'please install gnuplot first' + [[ -d "$TDIR" ]] || mkdir -p "$TDIR" || errorout "could not create $TDIR" + + # is input file a valid data file? + local datafile="$@" + check_datafile "$datafile" + [[ "$datafile" ]] || errorout 'please specify a file to read from.' + [[ -f "$datafile" ]] || errorout 'filplotfilee not found.' + + # define some of the variables for the plot file + DATE=$(date +%Y-%m-%d,\ %T) + TITLE="power consumption of my laptop, created by thinkwatt on $DATE" + XLABEL="sec (seconds)" + YLABEL="W (Watt)" + TERMINAL="png" + GRID=yes + #TITLE1="your custom title for line1" + #TITLE2="your custom title for line2" + #TITLE3="your custom title for line3" + # some more options for gnuplot, enable and modify them here if you like + MYTICS=2 + MXTICS=2 + #YTICS=1 + #XTICS=(better leave this alone) + GRIDSET="mytics" + #YRANGE="[4000:16000]" + #XRANGE="[0:2000]" + # moar + local avg=$(average "$datafile" | cut -c1-4) + local dir=$(dirname "$datafile") + local file=$(basename "$datafile") + [[ -z "$TITLE1" ]] && local TITLE1="$file (actual)" + [[ -z "$TITLE2" ]] && local TITLE2="$file (trend)" + [[ "$PNGFILE" ]] || PNGFILE=$(basename "$datafile" .dat).png + + # now we can plot + makeplotfile > "$PLOTFILE" || errorout "could not write the plotfile (permission issue?)" + gnuplot "$PLOTFILE" || errorout "could now write graph (permission issue?)" + + [[ "$quiet" ]] || echo "graph saved as $PNGFILE" + +} + +# parse options {{{ +parse_options() { + + [[ -z "$1" ]] && message + + while [[ -n "$1" ]];do + case "$1" in + -h|--help) message ;; + -q|--quiet) quiet=true ;; + -o|--output) output="$2" ;; + -r|--record) mode='record' ;; + -p|--plot) mode='plot' ;; + -a|--average) mode='average' ;; + *) args+=( "$1" ) ;; + esac + shift + done +} +# }}} + +# main {{{ +main() { + + case "$mode" in + record) record "${args[@]}" ;; + average) average "${args[@]}" ;; + plot) plot "${args[@]}" ;; + *) errorout 'invalid mode. use -r, -p or -a.' ;; + esac + +} +# }}} + +parse_options "$@" +check_ac +main diff --git a/try-qlogin b/try-qlogin new file mode 100755 index 0000000..69c4c2e --- /dev/null +++ b/try-qlogin @@ -0,0 +1,10 @@ +#!/bin/bash + + +trap 'echo Control-C trap caught; exit 1' 2 + +while true +do + qlogin -l mem_free=$1 +done + diff --git a/umount-crypt b/umount-crypt new file mode 100755 index 0000000..1405d46 --- /dev/null +++ b/umount-crypt @@ -0,0 +1,9 @@ +#!/bin/zsh + + +. /home/pks/bin/func.zsh +check_root + +umount /mnt +cryptsetup luksClose /dev/mapper/remote_backup + diff --git a/updatepdf b/updatepdf new file mode 100755 index 0000000..fec4ef3 --- /dev/null +++ b/updatepdf @@ -0,0 +1,6 @@ +#!/bin/zsh + + +mupdf $1 & +echo $! > .mupdf.pid + diff --git a/upgrade-gentoo b/upgrade-gentoo new file mode 100755 index 0000000..1df1209 --- /dev/null +++ b/upgrade-gentoo @@ -0,0 +1,23 @@ +#!/bin/sh + + +cd /usr +rsync -avv portage/ portage_/ +umount portage +rm portage.squashfs +mv portage_ portage +perl-cleaner --reallyall +python-updater +emaint --check all +emaint --fix all +emerge --sync +emerge -avuDN --with-bdeps y --keep-going world +read p\?"press enter... " +etc-update +emerge -av --depclean +revdep-rebuild +eclean -d distfiles +localepurge +mksquashfs portage portage.squashfs -comp xz +mount portage + diff --git a/upgrade-kernel b/upgrade-kernel new file mode 100755 index 0000000..d0ecb19 --- /dev/null +++ b/upgrade-kernel @@ -0,0 +1,25 @@ +#!/bin/sh + +# +# NOTE: call from kernel source dir +# + + +V=`pwd | ruby -e "puts STDIN.gets.split('/').last.split('-').last"` +make mrproper +cp -v ../config .config +make +sudo make modules_install +sudo cp -v arch/x86/boot/bzImage /boot/kernel +sudo /sbin/lilo +sudo rm /usr/src/linux +sudo ln -s $(pwd) /usr/src/linux +cd /home/pks/src/tp_smapi/ +sudo make install KVER=$V KSRC=/home/pks/stuff/kernelbuild/linux-$V KBUILD=/home/pks/stuff/kernelbuild/linux-$V +sudo make clean +sudo chown -R pks:pks * .* /home/pks/src/tp_smapi/ /home/pks/stuff/kernelbuild/linux-* +echo "=================" +cd /lib/modules/ +pwd +ls -lah + diff --git a/user-agents b/user-agents new file mode 100644 index 0000000..dae3d28 --- /dev/null +++ b/user-agents @@ -0,0 +1,50 @@ +Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36 +Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36 +Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36 Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10 +Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36 +Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1623.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 +Mozilla/5.0 (X11; CrOS i686 4319.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1467.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1500.55 Safari/537.36 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Safari/537.36 +Mozilla/5.0 (X11; NetBSD) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 +Mozilla/5.0 (X11; CrOS i686 3912.101.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.14 (KHTML, like Gecko) Chrome/24.0.1292.0 Safari/537.14 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13 +Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1284.0 Safari/537.13 +Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.26 Safari/537.11 +Mozilla/5.0 (Windows NT 6.0) yi; AppleWebKit/345667.12221 (KHTML, like Gecko) Chrome/23.0.1271.26 Safari/453667.1221 +Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.17 Safari/537.11 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_0) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4 +Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1 +Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6 +Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6 diff --git a/xfs-raid b/xfs-raid new file mode 100755 index 0000000..29963f1 --- /dev/null +++ b/xfs-raid @@ -0,0 +1,48 @@ +#!/bin/bash +# source: http://www.mythtv.org/wiki/Optimizing_Performance#Optimizing_XFS_on_RAID_Arrays +BLOCKSIZE=512 # Make sure this is in bytes +CHUNKSIZE=128 # Make sure this is in KiB +NUMSPINDLES=3 +RAID_TYPE=5 +RAID_DEVICE_NAME="/dev/md0" # Specify device name for your RAID device +FSLABEL="stor5" # specify filesystem label for generating mkfs line here + +case "$RAID_TYPE" in +0) + RAID_DISKS=${NUMSPINDLES}; + ;; +1) + RAID_DISKS=${NUMSPINDLES}; + ;; +10) + RAID_DISKS=${NUMSPINDLES}; + ;; +5) + RAID_DISKS=`echo "${NUMSPINDLES} - 1" | bc`; + ;; +6) + RAID_DISKS=`echo "${NUMSPINDLES} - 2" | bc`; + ;; +*) + echo "Please specify RAID_TYPE as one of: 0, 1, 10, 5, or 6." + exit + ;; +esac + +SUNIT=`echo "${CHUNKSIZE} * 1024 / 512" | bc` +SWIDTH=`echo "$RAID_DISKS * ${SUNIT}" | bc` + +echo "System blocksize=${BLOCKSIZE}" +echo "Chunk Size=${CHUNKSIZE} KiB" +echo "NumSpindles=${NUMSPINDLES}" +echo "RAID Type=${RAID_TYPE}" +echo "RAID Disks (usable for data)=${RAID_DISKS}" +echo "Calculated values:" +echo "Stripe Unit=${SUNIT}" +echo -e "Stripe Width=${SWIDTH}\n" +echo "mkfs line:" +echo -e "mkfs.xfs -b size=${BLOCKSIZE} -d sunit=${SUNIT},swidth=${SWIDTH} -L ${FSLABEL} ${RAID_DEVICE_NAME}\n" +echo "mount line:" +echo -e "mount -o remount,sunit=${SUNIT},swidth=${SWIDTH}\n" +echo "Add these options to your /etc/fstab to make permanent:" +echo "sunit=${SUNIT},swidth=${SWIDTH}" diff --git a/yt2mp3 b/yt2mp3 new file mode 100755 index 0000000..4982bcf --- /dev/null +++ b/yt2mp3 @@ -0,0 +1,21 @@ +#!/bin/sh + + +usage() +{ + echo "$0 " + exit 1 +} + +if [ -z $1 ] || [ -z $2 ]; then usage; fi + +TMP_FN=/tmp/youtube-dl-$RANDOM +while [ -a $TMP_FN ]; do + TMP_FN=/tmp/youtube-dl-$RANDOM +done +echo $TMP_FN + +youtube-dl --output=$TMP_FN --format=18 "$1" +ffmpeg -i $TMP_FN -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2" +rm $TMP_FN + -- cgit v1.2.3