# HG changeset patch # User John Tsiombikas # Date 1429783787 -10800 # Node ID 80fc0c4b11c075e504b23e46544cc844a0182b9d collection of shell scripts diff -r 000000000000 -r 80fc0c4b11c0 fixname --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fixname Thu Apr 23 13:09:47 2015 +0300 @@ -0,0 +1,143 @@ +#!/bin/sh +# ___________________________________________________ +# / \_ +# | fixname - cleans up filenames | \ +# | | | +# | author: John Tsiombikas | | +# | license: public domain | | +# \___________________________________________________/ | +# \___________________________________________________/ +# + +name=`basename $0` +proc_args=true +rename=false +verbose=false + + +print_usage() +{ + echo "Usage: $name [options] name1 name2 ... namen" + echo + echo 'Cleans up the names passed as arguments, and writes them out one per line' + echo 'options:' + echo ' - use stdin instead of arguments' + echo ' -- stop processing options, the rest are considered names to be fixed' + echo " -r rename it, don't just print the clean name" + echo ' -v verbose output' + echo ' -h print usage and exit' + echo 'more options will be added in the future to control exactly what fixes are performed' +} + +uscore() +{ + sed 's/ /_/g' +} + +udashu() +{ + sed 's/_-_/-/g' +} + +dupl() +{ + sed 's/__/_/g' | sed 's/--/-/g' +} + +utrail() +{ + sed 's/_$//g' | sed 's/-$//g' +} + +tolower() +{ + tr [:upper:] [:lower:] +} + +brac() +{ + sed 's/[][)(}{><]//g' +} + +diacrit() +{ + sed s/\'//g | sed 's/["`,;\\]//g' +} + +symb() +{ + sed 's/[!?@#$%^&*=]//g' +} + +transform() +{ + uscore | udashu | tolower | brac | diacrit | symb | dupl | utrail +} + +fix() +{ + fixed=`echo $1 | transform` + + if [ "$1" = "$fixed" ]; then + return + fi + + if $rename; then + if $verbose; then + echo "$1 -> $fixed" + fi + + mv "$1" "$fixed" + else + echo "$fixed" + fi +} + +fixed_any=false + +while [ $# -gt 0 ]; do + if $proc_args; then + + case $1 in + -) + shift + transform + exit 0 + ;; + + --) + proc_args=false + ;; + + -r) + rename=true + ;; + + -v) + verbose=true + ;; + + -h) + print_usage + exit 0 + ;; + + *) + fix "$1" + fixed_any=true + ;; + esac + else + fix "$1" + fixed_any=true + fi + shift +done + +if ! $fixed_any; then + for i in *; do + if [ -f "$i" ]; then + fix "$i" + fi + done +fi diff -r 000000000000 -r 80fc0c4b11c0 glext_cat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/glext_cat Thu Apr 23 13:09:47 2015 +0300 @@ -0,0 +1,2 @@ +#!/bin/sh +wget -q -O - `glext_url $1` diff -r 000000000000 -r 80fc0c4b11c0 glext_url --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/glext_url Thu Apr 23 13:09:47 2015 +0300 @@ -0,0 +1,6 @@ +#!/bin/sh + +prefix=`echo $1 | sed 's/^GL_//' | sed 's/_.*$//'` +name=`echo $1 | sed 's/^.*[A-Z]\+_//'` + +echo "http://www.opengl.org/registry/specs/$prefix/$name.txt" diff -r 000000000000 -r 80fc0c4b11c0 lsflv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lsflv Thu Apr 23 13:09:47 2015 +0300 @@ -0,0 +1,80 @@ +#!/bin/sh +# ------------------------------------------------------------------------- +# lsflv - prints a list (and optionally saves copies of) videos currently +# being played by the adobe flash player browser plugin. +# +# Written by John Tsiombikas +# This script is placed in the public domain, do whatever you want with it. +# ------------------------------------------------------------------------- + +mkcopy=no +play=no +player=${PLAYER:-mpv} +bin=`basename $0` +dir=`pwd` + +# if invoked as cpflv always make a copy (as in -c) +if [ "$bin" = cpflv ]; then + mkcopy=yes +fi + +# if invoked as playflv play the video (as in -p) +if [ "$bin" = playflv ]; then + play=yes +fi + +# process arguments +while [ $# -gt 0 ]; do + case "$1" in + -c) + mkcopy=yes + ;; + -p) + play=yes + ;; + -d) + dir=$2 + shift + ;; + -h) + echo "Usage: $bin [options]" + echo "Options:" + echo " -c make copies of the video files" + echo " -d change the directory used to copy the files to (default: cwd)" + echo " -h print usage and exit" + exit 0 + ;; + esac + shift +done + + +list=`lsof | egrep '(/tmp/Flash|/tmp/mozilla-media-cache)' | awk '{ print $2":"$4 }'` + +num=0 + +for i in $list; do + pid=`echo $i | awk -F: '{ print $1 }'` + fd=`echo $i | awk -F: '{ print $2 }' | sed 's/[a-zA-Z]*//g'` + + if [ -n "$fd" ]; then + path="/proc/$pid/fd/$fd" + + num=`echo "$num + 1" | bc` + target="$dir/vid$num" + + if [ $mkcopy = yes ]; then + echo "copy $path -> $target" + if ! cp $path $target; then + echo "failed to copy $path to $target" >&2 + exit 1 + fi + else + echo "$path" + fi + + if [ $play = yes ]; then + $player $path + fi + fi +done