tSome updates. - scripts - random scripts
 (HTM) git clone https://git.parazyd.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 933852ecce46bffbae79861a41c6213a2440105e
 (DIR) parent af0786393d19457ffe414f3f3c75315c723c96d3
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Mon, 11 May 2020 23:16:29 +0200
       
       Some updates.
       
       Diffstat:
         M autoup                              |       6 +++++-
         M chandl                              |      10 +++++++++-
         M ff                                  |       9 +++++++--
         A mladmin                             |      33 +++++++++++++++++++++++++++++++
         M radio                               |      71 ++++++++++++++-----------------
         M takeoffdir                          |       4 ++--
         A torrentwatch                        |       6 ++++++
         M update-gits                         |      23 ++++++++++++++++++++---
         D vipe                                |      74 -------------------------------
         M xkcd                                |      35 ++++++++++++++-----------------
       
       10 files changed, 131 insertions(+), 140 deletions(-)
       ---
 (DIR) diff --git a/autoup b/autoup
       t@@ -16,6 +16,10 @@ case "$1" in
                shift
                webdir=tmp/photo
                ;;
       +-t)
       +        shift
       +        webdir=tmp
       +        ;;
        esac
        
        
       t@@ -25,7 +29,7 @@ filename=$(basename $1)
        case "$filename" in
        *_scrot.*|mpv-shot*.*)
                webdir=tmp/screenshots
       -        num=$(echo $(lynx -dump https://$server/pub/tmp/screenshots \
       +        num=$(echo $(lynx -dump http://$server/pub/tmp/screenshots \
                        | tail -n1 | tr -d '[a-z]./:' | awk '{print $2}') + 1 | bc)
                if [ "$num" -lt 100 ]; then
                        num="00$num"
 (DIR) diff --git a/chandl b/chandl
       t@@ -1,7 +1,8 @@
        #!/bin/sh
        
        case "$1" in
       -*boards.4chan.org*)
       +*4chan.org*)
       +        #imgs='is2.4chan.org'
                imgs='i.4cdn.org'
                ;;
        *8ch.net*)
       t@@ -13,6 +14,12 @@ case "$1" in
        *arisuchan.jp*)
                imgs='.* https:\/\/arisuchan.jp\/.*/src\/'
                ;;
       +*enrive.org*)
       +        imgs='enrive.org\/media\/'
       +        ;;
       +*endchan.xyz*)
       +        imgs='endchan.xyz\/\.media\/'
       +        ;;
        *)
                echo 'Unsupported URL.'
                exit 1
       t@@ -20,4 +27,5 @@ case "$1" in
        esac
        
        lynx -dump "$1" | awk '/^References/,EOF' | awk '/'"$imgs"'/ {print $2}' |
       +        grep -v player | 
                sort | uniq | while read foo ; do wget -c "$foo" ; done
 (DIR) diff --git a/ff b/ff
       t@@ -1,4 +1,5 @@
        #!/bin/sh
       +
        case "$(basename $0)" in
        cb)
                xhost si:localuser:ff && \
       t@@ -6,7 +7,11 @@ cb)
                ;;
        
        ff)
       -        xhost si:localuser:ff && \
       -        exec sudo -u ff /usr/bin/firefox -no-remote -ProfileManager $@
       +        xhost si:localuser:ff
       +        if [ -z "$1" ]; then
       +                exec sudo -u ff /usr/bin/firefox --ProfileManager
       +        else
       +                sudo -u ff /usr/bin/firefox $@
       +        fi
                ;;
        esac
 (DIR) diff --git a/mladmin b/mladmin
       t@@ -0,0 +1,33 @@
       +#!/bin/sh
       +
       +mailman_url="https://mailinglists.dyne.org/cgi-bin/mailman/admin"
       +
       +listname="$1"
       +
       +if [ "$listname" = "" ]; then
       +        echo "Usage: $(basename "$0") listname"
       +        pass ls ml
       +        exit 1
       +fi
       +
       +pw="$(pass show ml/$listname)"
       +tmp="$(mktemp)"
       +
       +cat <<EOF > "$tmp"
       +<html>
       +  <head>
       +    <title>Mailman admin for $listname</title>
       +  </head>
       +  <body>
       +    <h1> Go to mailman admin: $listname</h1>
       +    <form method="POST" action="$mailman_url/$listname" name="f">
       +      <input type="password" name="adminpw" value='${pw}' size="30">
       +      <input type="submit" name="admlogin" value="Let me in..." autofocus>
       +    </form>
       +  </body>
       +</html>
       +EOF
       +
       +surf "$tmp"
       +
       +(sleep 10; rm -f "$tmp") &
 (DIR) diff --git a/radio b/radio
       t@@ -1,45 +1,40 @@
       -#!/bin/sh
       +#!/usr/bin/env python3
        
       -usage() {
       -    cat <<EOM
       -usage: $(basename $0) play [number|name]
       +from subprocess import call
       +from sys import argv, exit
        
       -list of radios:
       -    1. Radio Ondarossa
       -    2. Radio Mercadosul
       -    3. BlurFM02
       -    4. Auroville
       -    5. 2f30
       -    6. YAMMAT
       -    7. KLFM
       -    8. NOPE
       -    9. Radio Paradise
       -   10. Bitreich radio
       -   11. Radio 101
       -EOM
       -    exit 1
       +radios = {
       +    "ondarossa": "http://radio.dyne.org/ondarossa.mp3.m3u",
       +    "mercadosul": "http://radio.dyne.org/mercadosul.ogg.m3u",
       +    "blurfm": "http://radio.dyne.org/blurfm02.m3u",
       +    "auroville": "http://radio.dyne.org/auroville.mp3.m3u",
       +    "2f30": "http://radio.2f30.org:8000/live.mp3",
       +    "yammat": "https://studio20.radiolize.com/radio/8000/320kbps.mp3?1578641935",
       +    "klfm": "http://klfm.streamradio.com.hr:2199/tunein/klfm1.pls",
       +    "nope": "http://radionope.streamguys1.com/listen.pls",
       +    "paradise": "https://www.radioparadise.com/m3u/mp3-192.m3u",
       +    "bitreich": "http://bitreich.org:3232/live.m3u",
       +    "101": "http://live.radio101.hr:9531/stream",
       +    "057": "http://streaming.radio057.hr:8000/radio057.m3u",
       +    "gold": "http://live.goldfm.hr:8068",
       +    "brac": "http://s8.iqstreaming.com:8066/listen.pls?sid=1",
       +    "202": "http://138.201.33.250:8000/rts_4",
       +    "hvar": "http://5.133.182.164:12339",
       +    "student": "http://www.radiostudent.hr/AAC128.pls",
       +    "dalmacija": "http://shoutcast.pondi.hr:8000/listen.pls",
       +    "otvoreni": "http://otvoreni.hr/UserDocsImages/stream.pls",
       +    "coronavibe": "http://coronavi.be:8000/stream",
        }
        
       -play() {
       -    #/usr/bin/mpv --audio-device=alsa/hdmi:CARD=PCH,DEV=0 --no-video "$@"
       -    /usr/bin/mpv --no-video "$@"
       -}
        
       -case "$1" in
       -    1|ondarossa)  play "http://radio.dyne.org/ondarossa.mp3.m3u" ;;
       -    2|mercadosul) play "http://radio.dyne.org/mercadosul.ogg.m3u" ;;
       -    3|blurfm)     play "http://radio.dyne.org/blurfm02.m3u" ;;
       -    4|auroville)  play "http://radio.dyne.org/auroville.mp3.m3u" ;;
       -    5|2f30)       play "http://radio.2f30.org:8000/live.mp3" ;;
       -    6|yammat)     play "http://yammat.fm/yammat.pls" ;;
       -    7|klfm)       play "http://klfm.streamradio.com.hr:2199/tunein/klfm1.pls" ;;
       -    8|nope)       play "http://radionope.streamguys1.com/listen.pls" ;;
       -    9|paradise)   play "https://www.radioparadise.com/m3u/mp3-192.m3u" ;;
       -   10|bitreich)   play "http://bitreich.org:3232/live.m3u" ;;
       -   11|101|radio101)   play "http://s8.iqstreaming.com:8006/stream" ;;
       -   12|radio101rock) play "http://s8.iqstreaming.com:8018/stream" ;;
       -   13|057)        play "http://streaming.radio057.hr:8000/radio057.m3u";;
       +if len(argv) < 2:
       +    print(radios.keys())
       +    exit(1)
       +
       +radio = radios.get(argv[1])
        
       +if not radio:
       +    print(radios.keys())
       +    exit(1)
        
       -    *) usage ;;
       -esac
       +call(["/usr/bin/mpv", "--no-video", radio])
 (DIR) diff --git a/takeoffdir b/takeoffdir
       t@@ -1,10 +1,10 @@
        #!/bin/sh
        
       -TAKEOFF_DIR=/tmp/takeoff
       +TAKEOFF_DIR=/home/parazyd/tors
        
        mkdir -p $TAKEOFF_DIR
        
        # file either created or modified
        wendy -m 136 -f $TAKEOFF_DIR -v | while read ev file; do
       -    $HOME/bin/autoup "$file"
       +    scp "$file" alderaan.parazyd.org:torrents/
        done
 (DIR) diff --git a/torrentwatch b/torrentwatch
       t@@ -0,0 +1,6 @@
       +#!/bin/sh
       +
       +TAKEOFFDIR="$HOME/tors"
       +
       +exec wendy -m 136 -w "$TAKEOFFDIR" \
       +        sh -c 'scp -Bq "$WENDY_INODE" alderaan.parazyd.org:torrents/ && rm -f "$WENDY_INODE"'
 (DIR) diff --git a/update-gits b/update-gits
       t@@ -1,12 +1,29 @@
        #!/bin/sh
        
       -#[ -n "$TORIFY" ] && tor=torsocks
       +if [ -n "$1" ]; then
       +        cat <<EOF
       +usage: $(basename "$0") SKIP=foo,bar,baz
       +EOF
       +        exit 1
       +fi
       +
       +SKIP="${SKIP:-}"
       +
       +skips="$(echo "$SKIP" | tr ',' '\n')"
        
        for i in $(printf %s\\n */); do
       -        test -d "$i/.git" && {
       +        test -e "$i.git" && {
       +                for j in "$skips"; do
       +                        echo "i: $i"
       +                        echo "j: $j"
       +                        if [ "$i" = "$j/" ]; then
       +                                printf "\nskipping %s... \\n" "$j"
       +                                continue
       +                        fi
       +                done
                        cd "$i"
                        printf "\nupdating %s...\\n" "$i"
       -                ${tor} git pull origin master
       +                git pull origin master --rebase
                        cd - >/dev/null
                }
        done
 (DIR) diff --git a/vipe b/vipe
       t@@ -1,74 +0,0 @@
       -#!/usr/bin/perl
       -
       -=head1 NAME
       -
       -vipe - edit pipe
       -
       -=head1 SYNOPSIS
       -
       -command1 | vipe | command2
       -
       -=head1 DESCRIPTION
       -
       -vipe allows you to run your editor in the middle of a unix pipeline and
       -edit the data that is being piped between programs. Your editor will
       -have the full data being piped from command1 loaded into it, and when you
       -close it, that data will be piped into command2.
       -
       -=head1 ENVIRONMENT VARIABLES
       -
       -=over 4
       -
       -=item EDITOR
       -
       -Editor to use.
       -
       -=item VISUAL
       -
       -Also supported to determine what editor to use.
       -
       -=back
       -
       -=head1 AUTHOR
       -
       -Copyright 2006 by Joey Hess <id@joeyh.name>
       -
       -Licensed under the GNU GPL.
       -
       -=cut
       -
       -use warnings;
       -use strict;
       -use File::Temp q{tempfile};
       -
       -$/=undef;
       -
       -my ($fh, $tmp)=tempfile();
       -die "cannot create tempfile" unless $fh;
       -print ($fh <STDIN>) || die "write temp: $!";
       -close $fh;
       -close STDIN;
       -open(STDIN, "</dev/tty") || die "reopen stdin: $!";
       -open(OUT, ">&STDOUT") || die "save stdout: $!";
       -close STDOUT;
       -open(STDOUT, ">/dev/tty") || die "reopen stdout: $!";
       -
       -my @editor="vi";
       -if (-x "/usr/bin/editor") {
       -        @editor="/usr/bin/editor";
       -}
       -if (exists $ENV{EDITOR}) {
       -        @editor=split(' ', $ENV{EDITOR});
       -}
       -if (exists $ENV{VISUAL}) {
       -        @editor=split(' ', $ENV{VISUAL});
       -}
       -my $ret=system(@editor, $tmp);
       -if ($ret != 0) {
       -        die "@editor exited nonzero, aborting\n";
       -}
       -
       -open (IN, $tmp) || die "$0: cannot read $tmp: $!\n";
       -print (OUT <IN>) || die "write failure: $!";
       -close IN;
       -unlink($tmp);
 (DIR) diff --git a/xkcd b/xkcd
       t@@ -2,31 +2,28 @@
        #
        # grab a random xkcd comic, append title and alttext, and save to a dir
        
       +from os import environ
       +from re import search
       +from random import randrange
       +
        from PIL import Image, ImageDraw, ImageFont
        from requests import get
       -from random import randrange
       -from textwrap import wrap
       -from json import loads
       -from re import search
       -import os
        
       -download_dir = os.environ['HOME']+'/xkcd/'
       -title_fontsize = 28
       -alt_fontsize = 18
       -line_offset = 10
       +DOWNLOAD_DIR = environ['HOME']+'/xkcd/'
       +TITLE_FONTSIZE = 28
       +ALT_FONTSIZE = 18
       +LINE_OFFSET = 10
        
       -def add_text(image, title, alt, tfont=download_dir+'xkcd.ttf',
       -             afont=download_dir+'xkcd.ttf'):
       +def add_text(image, title, alt, tfont=DOWNLOAD_DIR+'xkcd.ttf',
       +             afont=DOWNLOAD_DIR+'xkcd.ttf'):
            try:
                img = Image.open(image)
            except OSError:
                return
        
       -    tfont = ImageFont.truetype(tfont, title_fontsize)
       -    afont = ImageFont.truetype(afont, alt_fontsize)
       +    tfont = ImageFont.truetype(tfont, TITLE_FONTSIZE)
       +    afont = ImageFont.truetype(afont, ALT_FONTSIZE)
        
       -    twidth, theight = tfont.getsize(title)
       -    awidth, aheight = afont.getsize(alt)
            line_padding = 5
            draw = ImageDraw.Draw(img)
            lines = text_wrap(tfont, title, img.size[0])
       t@@ -65,8 +62,8 @@ def add_text(image, title, alt, tfont=download_dir+'xkcd.ttf',
        def text_wrap(font, text, image_width, i=0):
            lines = [[]]
            text = text.split(" ")
       -    while len(text) > 0:
       -        while len(text) > 0 \
       +    while text:
       +        while text \
                    and font.getsize(" ".join(lines[i]))[0] < image_width:
                    if font.getsize(text[0]+" "+" ".join(lines[i]))[0] > image_width * 0.95:
                        if len(lines[i]) == 0:
       t@@ -107,13 +104,13 @@ def main():
        
            image = num+search("\.([a-z])+$", info['img']).group()
        
       -    with open(download_dir+image, 'wb') as image_file:
       +    with open(DOWNLOAD_DIR+image, 'wb') as image_file:
                req = get(info['img'], stream=True)
                for block in req.iter_content(1024):
                    if block:
                        image_file.write(block)
                        image_file.flush()
                if not search("\.gif", info['img']):
       -            add_text(download_dir+image, title, alt)
       +            add_text(DOWNLOAD_DIR+image, title, alt)
        
        main()