scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 14fcb2796da0c88b1d647d0d6c033e5c13cdc0e8
Author: sin <sin@2f30.org>
Date:   Thu, 20 Jun 2013 12:52:52 +0100

Initial commit

Diffstat:
Aauphone | 16++++++++++++++++
Aburndisc | 10++++++++++
Adaemon | 10++++++++++
Afavsync | 34++++++++++++++++++++++++++++++++++
Aimgurup | 9+++++++++
Amksub | 26++++++++++++++++++++++++++
Amycosmos | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aphonedump | 18++++++++++++++++++
Aplayvid | 5+++++
Atopdf | 9+++++++++
Atranslate | 24++++++++++++++++++++++++
Aunpk | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azohopdf | 23+++++++++++++++++++++++
13 files changed, 304 insertions(+), 0 deletions(-)

diff --git a/auphone b/auphone @@ -0,0 +1,16 @@ +#!/bin/sh + +PROVIDER=2f30.org +if [ $1 ] +then + OTHER=$1 +else + echo "Use $O to talk with someone..." && exit 1 +fi +AUARGS="-b 1 -r 11000 -e u8" + +ssh $PROVIDER "rm -f /tmp/$USER && mkfifo /tmp/$USER" + +aucat $AUARGS -o - \ +| ssh $PROVIDER "cat > /tmp/$USER & cat /tmp/$OTHER" \ +| aucat $AUARGS -i - diff --git a/burndisc b/burndisc @@ -0,0 +1,10 @@ +#!/bin/sh + +DEV=/dev/cd0c +VOLID=$(basename $PWD)$(date +"%Y%m%d") + +echo -n $(du -shL .) $VOLID"? " && read +SIZ=$(mkisofs -J -R -f -q -print-size .) +mkisofs -J -R -f -V $VOLID . \ +| cdrecord -dev=$DEV -speed=1 -driveropts=burnfree \ + -dao -tsize=${SIZ}s -pad -eject -v - diff --git a/daemon b/daemon @@ -0,0 +1,10 @@ +#!/bin/sh + +# this script tries to emulate the behaviour of bsd daemon(3) call +# runs a job with its std streams closed and detaches from terminal + +if test -z $1; then + echo usage: $(basename $0) job; exit 1 +fi + +(exec "$@" &) > /dev/null 2>&1 diff --git a/favsync b/favsync @@ -0,0 +1,34 @@ +#!/bin/sh + +FAVS={beauty.2f30.org:,drawn:,$HOME/}.xombrero/favorites + +# collect +I=0 +for F in $FAVS +do + rsync -va $F /tmp/favorites.$I + I=$(expr $I + 1) +done + +# concat +rm -f /tmp/favorites.cat +for F in /tmp/favorites.[0-9]* +do + echo | cat $F - | grep -v '^$' >> /tmp/favorites.cat +done + +# uniq +NEWLINE='\ +' +SEP='||' +sed "$!N;s/\n/$SEP/" /tmp/favorites.cat | sort | uniq \ + | sed "s/$SEP/$NEWLINE/g" > /tmp/favorites.new + +# distribute +for F in $FAVS +do + rsync -va /tmp/favorites.new $F +done + +# clean +rm -f /tmp/favorites.* diff --git a/imgurup b/imgurup @@ -0,0 +1,9 @@ +#!/bin/sh + +if test -z "$1" +then echo Usage: $(basename $0) image && exit 1 +fi + +APIKEY=486690f872c678126a2c09a9e196ce1b + +curl -F "image=@$1" -F "key=$APIKEY" http://api.imgur.com/2/upload.xml diff --git a/mksub b/mksub @@ -0,0 +1,26 @@ +#!/bin/sh + +# rename subtitle files downloaded from addic7ed.com to match +# the specified tv series filenames in the current directory + +if test -z "$1"; then + echo "usage: $(basename $0) "'"Title.of.Show"' + exit +fi + +pp="$1" +tt=$(echo $pp | sed 's/\./ /g') + +echo $pp +for f in ${pp}.S??E??*.{avi,mp4,mkv}; do + if test "$(echo $f | grep '*')"; then continue; fi + s=$(echo $f | sed "s/.*S\(..\)E...*/\1/") + e=$(echo $f | sed "s/.*S..E\(..\).*/\1/") + x=$(echo $f | sed "s/.*\.//") + b=$(echo ~/downloads/"${tt}"*${s}x${e}*.srt) + echo -n "S${s}E${e}" + if test "$(echo $b | grep '*')"; then echo; continue; else + cp "$b" $(basename $f .$x).srt + echo " OK" + fi +done diff --git a/mycosmos b/mycosmos @@ -0,0 +1,62 @@ +#!/bin/sh + +if test -z "$4" +then + echo usage: $0 user pass target message + exit +fi + +USER=$1 +PASS=$2 +TARGET=$3 +MESSAGE="$4" + +LOGINURL='http://mail.mycosmos.gr/mycosmos/login.aspx' +SENDURL='http://mail.mycosmos.gr/mycosmos/SMS_Send.aspx' +COOKIEJAR=$(mktemp) + +# visit login page +VIEWSTATE=$(curl --cookie-jar $COOKIEJAR $LOGINURL 2> /dev/null \ + | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') +FRESH=$(grep mycosmos $COOKIEJAR \ + | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') +COOKIES=$FRESH + +# do login +curl --cookie-jar $COOKIEJAR \ + --cookie "$COOKIES" \ + --form "__VIEWSTATE=$VIEWSTATE" \ + --form "tbUsername=$USER" \ + --form "tbPassword=$PASS" \ + --form "btLogin=Log On" \ + --silent $LOGINURL > /dev/null + +FRESH=$(grep mycosmos $COOKIEJAR \ + | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') +COOKIES="$COOKIES; $FRESH" + +# clear cookies +rm $COOKIEJAR + +# visit send page +VIEWSTATE=$(curl --cookie "$COOKIES" $SENDURL 2> /dev/null \ + | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') + +# send text message +STAT=$(curl --cookie "$COOKIES" \ + --form "__VIEWSTATE=$VIEWSTATE" \ + --form "txtMobile=$TARGET" \ + --form "txtMessage=$MESSAGE" \ + --form "btnSend=Send" \ + --silent $SENDURL) + +# report status +if test "$(echo $STAT | grep 'Success=True')" + then SENT=yes + else SENT=no +fi +if test "$(echo $STAT | grep 'LimitReached=false')" + then LAST=no + else LAST=yes +fi +echo "sent=$SENT last=$LAST" diff --git a/phonedump b/phonedump @@ -0,0 +1,18 @@ +#!/bin/sh + +# dump contacts from mobile phone using infrared +# XXX: infrared does not work after suspend +# gnokiirc: +# [global] +# port = /dev/ttypv +# connection = serial +# model = AT + +TMP=$(mktemp /tmp/phone.XXXXXXXXXX) +sudo ircomm -d /dev/cua01 -y /dev/ptypv -v2 2>&1 | tee $TMP & +sleep 7 +if [ -n "$(grep discover $TMP)" ] +then gnokii --getphonebook ME 1 end --raw | tee phonebook$(date "+%Y%m%d").csv +fi +sudo pkill ircomm +rm $TMP diff --git a/playvid b/playvid @@ -0,0 +1,5 @@ +#!/bin/sh + +C="^Content-Location: " +V=$(get_flash_videos -r high -i "$1" | grep "$C" | sed "s/$C//") +mplayer -really-quiet "$V" diff --git a/topdf b/topdf @@ -0,0 +1,9 @@ +#!/bin/sh + +if test -z "$1" +then echo Usage: $(basename $0) document && exit 1 +fi + +SRV=http://www.doc2pdf.net/convert/document.pdf + +curl -F "inputDocument=@$1" $SRV > "${1%.*}.pdf" diff --git a/translate b/translate @@ -0,0 +1,24 @@ +#!/bin/sh + +if test -z "$1" +then + echo usage: $0 text + exit +fi + +TEXT=$1 +SL=auto +TL=el + +TRANSLATEURL='http://translate.google.com/' +UA='Mozilla 5.0' +NEWLINE='\ +' + +# do translate +curl --user-agent "$UA" \ + --data "sl=$SL" \ + --data "tl=$TL" \ + --data-urlencode "text=$TEXT" \ + --silent $TRANSLATEURL \ + | sed "s/<\/span>/$NEWLINE/g" | grep result_box | sed 's/.*>//' diff --git a/unpk b/unpk @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: $(basename $0) archive ..."; exit 1 +fi + +while [ -n "$1" ]; do + case "$1" in + *.tar.gz | *.tgz) + tar xzf "$1" + shift + ;; + *.tar.bz2 | *.tbz) + tar xjf "$1" + shift + ;; + *.zip) + unzip "$1" + shift + ;; + *.jar) + unzip "$1" + shift + ;; + *.war) + unzip "$1" + shift + ;; + *.ace) + unace x "$1" + shift + ;; + *.rar) + unrar x "$1" + shift + ;; + *.7z) + 7z x "$1" + shift + ;; + *.tar) + tar xf "$1" + shift + ;; + *.gz) + gunzip "$1" + shift + ;; + *.bz2) + bunzip2 "$1" + shift + ;; + *) + echo "File format not supported: $1" + shift + ;; + esac +done diff --git a/zohopdf b/zohopdf @@ -0,0 +1,23 @@ +#!/bin/sh + +# Supported files: +# * Microsoft Office: doc, docx, xls, xlsx, ppt, pptx, pps +# * OpenDocument: odt, ods, odp +# * OpenOffice: sxw, sxc, sxi +# * Other: rtf, txt, html, csv, tsv + +if [ -n "$1" ]; then FILE="$1"; else + echo "Usage: $0 document"; exit +fi +NAME=$(echo $FILE | sed "s/\.[^\.]*$//") + +MAINURL='https://viewer.zoho.com/converter' +COOKIEJAR='/tmp/zohocookie.txt' +AGENT= +curl --cookie-jar $COOKIEJAR $MAINURL > /dev/null +COOKIE=$(grep zvcsr $COOKIEJAR | awk '{ print $7 }') + +curl --referer $MAINURL \ +--form "file=@$FILE" --form "format=pdf" \ +--form "zvcsrcoo=$COOKIE" --cookie $COOKIEJAR \ +"https://viewer.zoho.com/convert.do" > "$NAME.pdf"