From f4bd641e36418bc2a43bc31d8ac0bf57b1c51953 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 9 Dec 2018 03:58:58 -0500 Subject: new commands --- dot/local/bin/datel | 3 + dot/local/bin/linlaunch | 58 +++++++++++++++++++ dot/local/bin/safeunrar | 90 ++++++++++++++++++++++++++++++ dot/local/bin/screeny | 31 ++++++++++ dot/local/bin/selfstream | 49 ++++++++++++++++ dot/local/bin/soundy | 32 +++++++++++ dot/local/bin/webbie | 47 ++++++++++++++++ dot/local/bin/xtermessage | 4 ++ dot/local/bin/zukertort | 2 + dot/local/share/applications/mimeapps.list | 3 + 10 files changed, 319 insertions(+) create mode 100755 dot/local/bin/datel create mode 100755 dot/local/bin/linlaunch create mode 100755 dot/local/bin/safeunrar create mode 100755 dot/local/bin/screeny create mode 100755 dot/local/bin/selfstream create mode 100755 dot/local/bin/soundy create mode 100755 dot/local/bin/webbie create mode 100755 dot/local/bin/xtermessage create mode 100755 dot/local/bin/zukertort create mode 100644 dot/local/share/applications/mimeapps.list (limited to 'dot/local') diff --git a/dot/local/bin/datel b/dot/local/bin/datel new file mode 100755 index 0000000..4375b4f --- /dev/null +++ b/dot/local/bin/datel @@ -0,0 +1,3 @@ +#!/bin/bash +date=$(date "$@") +printf '%s\n' "$date" "${date//?/-}" diff --git a/dot/local/bin/linlaunch b/dot/local/bin/linlaunch new file mode 100755 index 0000000..20ebc7a --- /dev/null +++ b/dot/local/bin/linlaunch @@ -0,0 +1,58 @@ +#!/bin/sh + +linphone_socket=/tmp/linphonec-$(id -u) + +warn() { printf '%s\n' "$0" "${*:-something is wrong.}" >&2; } +die() { warn "$@"; exit 1; } + +init() +{ + out=$(linphonecsh init -CD 2>&1) + [ -z "$out" ] && return + case "$out" in + *'running linphonec has been found'*) + printf '%s\n' "$out" >&2 + return 1 ;; + '') + return 0 ;; + *) + die "Error: unexpected output from linphonecsh: $out" ;; + esac +} + +wait_for_linphone_socket() +{ + for n in $(seq 1 50); do + test -e ${linphone_socket} && break + sleep 0.1 + done +} + +getip() +{ + upnpc -s|sed -ne 's/^ExternalIPAddress = //p' +} + +generic() +{ + linphonecsh generic "$*" +} + +atexit() +{ + if [ "$kill_linphonec" ]; then + linphonecsh exit + fi +} + +init +trap atexit EXIT + +wait_for_linphone_socket + +if ip=$(getip); then + generic nat $ip + generic firewall nat +fi + +generic friend list diff --git a/dot/local/bin/safeunrar b/dot/local/bin/safeunrar new file mode 100755 index 0000000..506145b --- /dev/null +++ b/dot/local/bin/safeunrar @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w +######################################################################## +# safeunrar, safeunzip, safeuntar -- Extract archives, ensuring that # +# all files in each archive remain in a single subdirectory, without # +# overwriting anything. # +######################################################################## +# The decompression program is called once for each argument. The # +# program to use is guessed, first by extension, and failing that # +# by the name of this program (which, in that case, must be one of # +# safeunrar, safeunzip, safeuntar). # +######################################################################## +use File::Temp qw(tempdir); +use File::Basename; +use Cwd; + +my %extension_map = ( + '(tar\.gz|tgz|taz)' => 'tar -zxf', + '(tar\.Z|taZ)' => 'tar -Zxf', + '(tar\.bz2|tz2|tbz2|tbz)' => 'tar -jxf', + '(tar\.lzma|tlz)' => 'tar --use-compress-program=lzma -xf', + '(zip|xpi|jar)' => 'unzip', + 'rar' => 'unrar x', + 'tar' => 'tar -xf', +); + +$cwd = getcwd or die "getcwd error: $!"; +for $archive (@ARGV) { + chdir $cwd or die "chdir error: $!"; + + my ($base, @cmd); + keys %extension_map; # resets "each" + while (($rx, $cmd) = each %extension_map) { + $_ = basename $archive; + if (m/^(.*)\.$rx$/) { + @cmd = split / /, $cmd; + $base = $1; + last; + } + } + unless (@cmd) { + for (basename $0) { + $_ eq 'safeunzip' && (@cmd = qw'unzip') + || $_ eq 'safeunrar' && (@cmd = qw'unrar x') +# don't use this because the current gnu tar's --auto-compress is +# guaranteed to fail if the current %extension_map failed. +# || $_ eq 'safeuntar' && (@cmd = qw'tar --auto-compress -xf') + || $_ eq 'safeuntar' && (@cmd = qw'tar -zxf') + || die; + } + ($base = basename $archive) =~ s/\..{2,4}$//; + } + + $tempdir = tempdir("$base.XXXXXX", DIR => ".") + or warn("tempdir error: $!; skipping $archive"), next; + chmod 0777 & ~ umask, $tempdir; + + $ltd = "leaving temporary directory '$tempdir'"; + + # extract the files + chdir $tempdir + or warn("chdir error: $!; $ltd"), next; + $archive =~ s#^(?!/)#../#; + system(@cmd, $archive) == 0 + or warn("$cmd[0] error: $?/$!; $ltd"), next; + + # count the files + opendir(DIR, '.') + or warn("opendir error: $!; $ltd"), next; + @f = readdir(DIR) + or warn("readdir error: $!; $ltd"), next; + closedir(DIR) + or warn("closedir error: $!; ignoring"); + + # if only one file, delete the dir + @f = grep { ! m/^\.\.?$/ } @f; + if (1 == @f) { + ! -e "$cwd/$f[0]" + or warn("not overwriting $f[0]; $ltd"), next; + rename $f[0], "$cwd/$f[0]" + or warn("rename error: $!; $ltd"), next; + chdir $cwd + or warn("chdir error: $!; $ltd"), next; + rmdir $tempdir + or warn("rmdir error: $!; $ltd"), next; + # if multiple files, rename the dir + } else { + rename "$cwd/$tempdir", "$cwd/$base" + or warn("rename error: $!; $ltd"), next; + } +} diff --git a/dot/local/bin/screeny b/dot/local/bin/screeny new file mode 100755 index 0000000..8ecf2d0 --- /dev/null +++ b/dot/local/bin/screeny @@ -0,0 +1,31 @@ +#!/bin/bash +die() { printf '%s: Error: %s\n' "$0" "$*" >&2; exit 1; } +[ "$DISPLAY" ] || die 'no $DISPLAY set. Try launching from a new xterm.' + +AUDIO_DEVICE=pulse + +NOW=$(date -Iseconds) + +OUTPUT=screen-capture.${NOW//[:T]/.}.avi +OUTPUT_LINK=screen-capture.latest.avi + +# ffmpeg -f x11grab -framerate 25 -video_size cif -i :0.0 out.mpg + +record() +{ + local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" + ffmpeg -hide_banner -loglevel error -stats \ + $timeout -f x11grab -framerate 25 -video_size 1280x800 -i "$DISPLAY" \ + $timeout -f "$AUDIO_DEVICE" -i default \ + -c:a mp3 \ + -c:v libxvid -qscale:v 3 \ + "$1" +} + +silently() { "$@" >/dev/null 2>&1; } + +silently amixer-enable-mic +banish +record "$OUTPUT" + +[ -h "$OUTPUT_LINK" -o ! -e "$OUTPUT_LINK" ] && ln -sf "$OUTPUT" "$OUTPUT_LINK" diff --git a/dot/local/bin/selfstream b/dot/local/bin/selfstream new file mode 100755 index 0000000..85b8a8f --- /dev/null +++ b/dot/local/bin/selfstream @@ -0,0 +1,49 @@ +#!/bin/bash + +AUDIO_DEVICE=pulse +VIDEO_DEVICE=/dev/video0 + +case $(hostname) in + fifty) outhost=blackbird ;; + blackbird) outhost=fifty; AUDIO_DEVICE=alsa ;; + *) outhost=$1 +esac + +MAX_RECORDING_TIME=00:05:00 + +# https://trac.ffmpeg.org/wiki/StreamingGuide#Pointtopointstreaming + +VIDEO_OPTS='-framerate 30 -video_size 640x480' +VIDEO_OPTS='-framerate 30 -video_size 320x240' +# VIDEO_OPTS='-input_format mjpeg -framerate 30 -video_size 800x600' + +record() +{ + local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" + ffmpeg -hide_banner -loglevel error -stats \ + $timeout -f video4linux2 ${VIDEO_OPTS} -i "$VIDEO_DEVICE" \ + $timeout -f "$AUDIO_DEVICE" -i default \ + -c:v rawvideo -pix_fmt yuv420p -f xv win \ + -c:a mp3 \ + -c:v libxvid \ + -f mpegts \ + "$1" +} + +# ffmpeg -i input -f rtsp -rtsp_transport tcp rtsp://localhost:8888/live.sdp +# ffplay -rtsp_flags listen rtsp://localhost:8888/live.sdp?tcp + +#OUTPUT=${1:-udp://blackbird:55555} +#INPUT=${2:-ffmpeg://udp://localhost:55555?listen} + + +OUTPUT=udp://blackbird:55555 + +silently() { "$@" >/dev/null 2>&1; } + +silently amixer-enable-mic +banish + +record "$OUTPUT" +# mpv "$INPUT" + diff --git a/dot/local/bin/soundy b/dot/local/bin/soundy new file mode 100755 index 0000000..5ec812b --- /dev/null +++ b/dot/local/bin/soundy @@ -0,0 +1,32 @@ +#!/bin/bash +die() { printf '%s: Error: %s\n' "$0" "$*" >&2; exit 1; } +[ "$DISPLAY" ] || die 'no $DISPLAY set. Try launching from a new xterm.' + +AUDIO_DEVICE=pulse +AUDIO_INPUT=jack_out.monitor + +NOW=$(date -Iseconds) + +OUTPUT=screen-capture.${NOW//[:T]/.}.avi +OUTPUT_LINK=screen-capture.latest.avi + +# ffmpeg -f x11grab -framerate 25 -video_size cif -i :0.0 out.mpg + +record() +{ + local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" + ffmpeg -hide_banner -loglevel error -stats \ + $timeout -f x11grab -framerate 25 -video_size 1280x800 -i "$DISPLAY" \ + $timeout -f "$AUDIO_DEVICE" -i "$AUDIO_INPUT" \ + -c:a mp3 \ + -c:v libxvid -qscale:v 3 \ + "$1" +} + +silently() { "$@" >/dev/null 2>&1; } + +silently amixer-enable-mic +banish +record "$OUTPUT" + +[ -h "$OUTPUT_LINK" -o ! -e "$OUTPUT_LINK" ] && ln -sf "$OUTPUT" "$OUTPUT_LINK" diff --git a/dot/local/bin/webbie b/dot/local/bin/webbie new file mode 100755 index 0000000..02fa3dd --- /dev/null +++ b/dot/local/bin/webbie @@ -0,0 +1,47 @@ +#!/bin/bash + +AUDIO_DEVICE=pulse +VIDEO_DEVICE=/dev/video0 + +# Why does OUTPUT_CODECS have to specify -pix_fmt ? Answered: +# https://stackoverflow.com/questions/37967120/ffmpeg-convert-from-h-264-high-444-profile-to-h-264-main-profile + +# Why aac and libx264? Browser support: +# https://gist.github.com/Vestride/278e13915894821e1d6f + +# Explanation of -profile and -level: +# https://trac.ffmpeg.org/wiki/Encode/H.264 + +OUTPUT_CODECS='-c:a aac -c:v libx264 -pix_fmt yuv420p -profile:v high -level 4.1 -movflags +faststart' +# OUTPUT_CODECS='-c:a aac -c:v libx264' +OUTPUT_EXTENSION=mp4 + +MAX_RECORDING_TIME=00:05:00 + +NOW=$(date -Iseconds) + +OUTPUT=recording.${NOW//[:T]/.}.${OUTPUT_EXTENSION} +OUTPUT_LINK=recording.latest.${OUTPUT_EXTENSION} + +VIDEO_OPTS='-framerate 30 -video_size 640x480' +VIDEO_OPTS='-input_format mjpeg -framerate 30 -video_size 800x600' +# VIDEO_OPTS='-input_format mjpeg -framerate 15 -video_size 1600x1200' + +record() +{ + local timeout="${MAX_RECORDING_TIME+-t $MAX_RECORDING_TIME}" + ffmpeg -hide_banner -loglevel error -stats \ + $timeout -f video4linux2 ${VIDEO_OPTS} -i "$VIDEO_DEVICE" \ + $timeout -f "$AUDIO_DEVICE" -i default \ + -c:v rawvideo -pix_fmt yuv420p -f xv win \ + ${OUTPUT_CODECS} \ + "$1" +} + +silently() { "$@" >/dev/null 2>&1; } + +silently amixer-enable-mic +banish +record "$OUTPUT" + +[ -h "$OUTPUT_LINK" -o ! -e "$OUTPUT_LINK" ] && ln -sf "$OUTPUT" "$OUTPUT_LINK" diff --git a/dot/local/bin/xtermessage b/dot/local/bin/xtermessage new file mode 100755 index 0000000..8e64b3a --- /dev/null +++ b/dot/local/bin/xtermessage @@ -0,0 +1,4 @@ +#!/bin/sh +literal=$(printf "%s\n" "$@") +export literal +xterm -cr white -fs 90 -e 'tput civis; printf %s "$literal"; read -n1' diff --git a/dot/local/bin/zukertort b/dot/local/bin/zukertort new file mode 100755 index 0000000..5bbaf8b --- /dev/null +++ b/dot/local/bin/zukertort @@ -0,0 +1,2 @@ +#!/bin/sh +exec x11-ssh-host zukertort.childrenofmay.org diff --git a/dot/local/share/applications/mimeapps.list b/dot/local/share/applications/mimeapps.list new file mode 100644 index 0000000..3a146e3 --- /dev/null +++ b/dot/local/share/applications/mimeapps.list @@ -0,0 +1,3 @@ +[Default Applications] +application/pdf=evince.desktop +image/png=geeqie.desktop -- cgit v1.2.3