Initial commit.

This commit is contained in:
Mid Favila 2021-06-30 00:22:57 -03:00
parent 6267082189
commit 473494565f
13 changed files with 305 additions and 2 deletions

View File

@ -1,6 +1,6 @@
MIT No Attribution
Copyright <YEAR> <COPYRIGHT HOLDER>
Copyright 2021, Mid Favila
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software

8
Links Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
export CONFIG_DIR=".config"
if [ ! -e /tmp/Links.xid ]
then /usr/bin/tabbed -t '#000000' -T '#FFFFFF' -u '#C0C0C0' -U '#000000' -c /usr/bin/links "$@" -g -w > /tmp/Links.xid ; rm /tmp/Links.xid
else /usr/bin/links "$@" -g -w "$(cat /tmp/Links.xid)"
fi

View File

@ -1,3 +1,15 @@
# POSIX_Scripts
A set of POSIX* shell scripts designed for personal use. No guarantees when it comes to quality, as these are also used for various minor experiments of mine.
A set of POSIX* shell scripts designed for personal use. No guarantees when it comes to quality, as these are also used for various minor experiments of mine.
Links - wrapper script for managing links2 and tabbed
fpm - wrapper for using ffplay to manage music
fpv - the above, but video
gasutc - "Get and Set UTC" over HTTPS using ncat
gcl - one-liner to g(it)cl(one)
iview - simple wrapper for sxiv; auto-sizes based on image dimensions
ls - one-liner to pipe ls through cols
man - short script to auto-resize mandoc output
modem-manager - used to manage laptop PCIe WAN modems. rather dense
netsh - an old experiment that serves as a simple TUI for managing network interfaces... and an example of how not to use AWK
plumber - one of my more sophisticated scripts; plumber creates pipes between programs based on what sort of input it receives, and handles errors (somewhat) intelligently

38
fpm Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
# Grab a number that is greater than zero but no greater than the number of
# files in our directory
rand_file()
{
x=$(($(/usr/bin/dd bs=2 count=1 if=/dev/random of=/dev/stdout| /usr/bin/od -|\
/usr/bin/sed 's/ */ /'|/usr/bin/cut -d ' ' -f2|/usr/bin/sed 1!d)%$((1+$(/usr/bin/ls|\
/usr/bin/wc -l)))))
/usr/bin/echo "${x}"
}
if [ $# = 0 ]
then /usr/bin/printf "FPM provides a convenient way to use ffplay for audio playback.\nIt accepts the following arguments:\n\n-s: Shuffle songs in the directory randomly.\n\n-l: Play on repeat.\n\n"
else
case "$@" in
-s)
file=$(x=$(rand_file);if [ "${x}" = 0 ];then x=1;fi;/usr/bin/ls|sed "${x}"!d)
/usr/bin/ffplay -autoexit -nodisp "${file}"
sleep 1 # Prevent fpm from continuously respawning on kill
;;
-l)
while true
do /usr/bin/ffplay -autoexit -nodisp "$1"
done
;;
*)
/usr/bin/ffplay -autoexit -nodisp "$1"
;;
esac
fi
exit

10
fpv Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -e
case "$1" in
*)
/usr/bin/ffplay -autoexit "$1"
;;
esac
exit

38
gasutc Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh -e
# Retrieve a header from somewhere. Don't care where.
echo "GET HTTP/1.1" | ncat --ssl 205.166.94.16 443 | grep Date > /tmp/date.jnk
# Month lookup table. Horrible, but I don't know a better method...
# Please forgive me for this sin, Patriarch Bourne.
month=`cut -d ' ' -f 4 /tmp/date.jnk`
case "$month" in
Jan) month=01 ;;
Feb) month=02 ;;
Mar) month=03 ;;
Apr) month=04 ;;
May) month=05 ;;
Jun) month=06 ;;
Jul) month=07 ;;
Aug) month=08 ;;
Sep) month=09 ;;
Oct) month=10 ;;
Nov) month=11 ;;
Dec) month=12 ;;
esac
x=1
for each in day year time
do
export $each=`cat /tmp/date.jnk | tr ' ' '\n' | grep -E [0-9] | sed s/\://g | tr '\n' ' ' | cut -d ' ' -f $x`
x=$(($x+1))
done
printf "The current time is as follows.\nYear: $year\nMonth: $month\nDay: $day\nTime: $time\n"
time=`echo $time | cut -b 1,2,3,4`
year=`echo $year | cut -b 3,4`
printf "Your date-compatible string for today is: $month$day$time$year\nHere it is again, on its own line:\n$month$day$time$year\n"
/bin/ssu -- date -u $month$day$time$year
rm /tmp/date.jnk
exit

3
gcl Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/git clone --recurse-submodules "$@"
exit

22
iview Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh -e
type=$(file --mime-type "${1}" | cut -f 2 -d ' ')
case "${type}" in
*image/png*)
x=$(/bin/file "${1}" | /bin/grep -o "[0-9]* x [0-9]*" | sed 's/ x /x/')
;;
*image/jpeg*)
x=$(/bin/file "${1}" | /bin/grep -o "[0-9]*x[0-9]*" | sed "2!d")
;;
*)
x=$(/bin/file "${1}" | /bin/grep -o "[0-9]* x [0-9]*" | sed 's/ x /x/')
;;
esac
/bin/sxiv -bg "${x}" "${1}"
exit

4
ls Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
/usr/bin/ls "$@" | /usr/bin/cols
exit

4
man Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
x=$(/usr/bin/tput cols)
/usr/bin/man -O width=$((x-2)) "${@}"
exit

64
modem-manager Executable file
View File

@ -0,0 +1,64 @@
#!/bin/sh
# We need root to configure interface properties.
if [ "${USER}" != root ]
then printf "We need root!\n"
exit
else
# Has the interface even been initialized? If not, do so.
while [ ! -e /dev/cdc-wdm0 ]
do printf "3\n" >> /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3/bConfigurationValue
done
# Get the name of our interface.
wif=$(ifconfig -l | tr ' ' '\n' | grep ww)
# Establish a link, but only if one is not already available.
if [ -e /tmp/mbim-network-state-cdc-wdm0 ]
then printf "Connection already established.\nBringing down...\n"
printf "Closing netlink...\n"
mbim-network /dev/cdc-wdm0 stop >> /dev/null
printf "Bringing down interface...\n\n"
ifconfig "${wif}" down >> /dev/null
exit
else printf "Turning on radio...\n"
mbimcli --device=/dev/cdc-wdm0 --device-open-proxy --set-radio-state=on >> /dev/null
printf "Bringing up interface...\n"
ifconfig "${wif}" up >> /dev/null
printf "Opening netlink...\n\n"
mbim-network /dev/cdc-wdm0 start >> /dev/null
fi
# Store the result of the query so that we don't have to call it constantly
printf "Querying for network info...\n"
mbimcli -d /dev/cdc-wdm0 -p --query-ip-configuration > /tmp/qic.tmp
# Get our IPv4.
ip=$(sed -ne "s/IP \[0\]\: '\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\/[0-9][0-9]\)'/\1/p" /tmp/qic.tmp | sed 's/ //g' | cut -d '/' -f 1)
# Get our CIDR netmask and convert to decimal.
nm=255.255.255.$(((0xFFFFFFFF >> $(sed -ne "s/IP \[0\]\: '\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\/[0-9][0-9]\)'/\1/p" /tmp/qic.tmp | sed 's/ //g' | cut -d '/' -f 2)) ^ 0xFF))
# Get our gateway.
gw=$(sed -ne "s/Gateway: '\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)'/\1/p" /tmp/qic.tmp|sed 's/ //g')
# Get our MTU.
mtu=$(sed 7!d /tmp/qic.tmp | sed -ne "s/MTU: '\([0-9]*\)'/\1/p" | sed -ne 's/ //gp')
printf "IP is %s\nNM is %s\nGW is %s\nMTU is %s\n\n" "${ip}" "${nm}" "${gw}" "${mtu}"
# Actually set up the connection.
printf "Assigning interface details...\n"
ifconfig "${wif}" "${ip}" netmask "${nm}"
printf "Routing through cellular gateway...\n"
route add default gw "${gw}"
# Test connection.
printf "Testing interface.\n\n"
ping -c 4 sdf.org
printf "\n"
rm /tmp/qic.tmp
fi
exit

59
netsh Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env sh
#This is a poorly-written script and should be ignored.
printf "\nWhat do you want to do?\n1. Configure\n2. Scan\n3. View\n>: "
read choice
case $choice in
1)
printf "Not ready yet.\n"
;;
2)
printf "\nScan with which interface?\n"
ifconfig -l | tr ' ' '\n' | grep wl | nl | awk '{printf $1 ". " $2 "\n"}'
printf ">: "
read choice
dev=`ifconfig -l | tr ' ' '\n' | grep wl | sed $choice!d`
iw dev $dev scan | grep SSID | $PAGER
;;
3)
printf "\nView what?\n1. Interface information\n2. Routing table\n>: "
read choice
case $choice in
1)
x=1
i=$((`ifconfig -l | tr ' ' '\n' | wc -l`+1))
printf "\nWhich interface?\n"
while [ $x -lt $i ]
do ifconfig -l | tr ' ' '\n' | nl | sed $x!d | awk '{printf $1 ". " $2 "\n"}'
x=$(($x+1))
done
printf ">: "
read choice
printf "\n" ; ifconfig -l | tr ' ' '\n' | sed $choice!d | awk '{printf "ifconfig " $1 "\n"}' | sh -e --
;;
2)
printf "\n" ; route ; printf "\n"
;;
*)
printf "Illegal input. Aborting.\n"
;;
esac
;;
*)
printf "Illegal input. Aborting.\n"
;;
esac
exit

41
plumber Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh -e
rand_inst() # Choose a random invidious instance to distribute load.
# Good digital citizenship is important, you know.
{
case $(($(dd bs=2 count=1 if=/dev/random of=/dev/stdout | od - | \
sed -ne 's/ */ /gp' | cut -d ' ' -f2) % 3)) in
0) printf "vid.puffyan.us" ;;
1) printf "ytprivate.com" ;;
2) printf "yewtu.be" ;;
esac
}
if [ "$(printf "%s" "${1}"|cut -b 1,2,3,4)" = "http" ]
then
case "${1}" in
*youtu*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/\(http.*:\/\/\).*\(\/.*\)/\1$(rand_inst)\2/p")" & ;;
*reddit*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/\(http.*:\/\/\).*\(\/.*\/\)/\1libredd.it\2/p")" & ;;
https://4chan.org*) exec Links "$(printf "%s" "${1}"|sed -ne \
"s/4chan/4channel/p")" ;;
*) exec Links "${1}" & ;;
esac
else
mime=$(file --mime-type -b "${1}")
case ${mime} in
*html*) exec Links "${1}" & ;;
text*) exec xless "${1}" & ;;
video*) exec fpv "${1}" & ;;
audio*) exec fpm "${1}" & ;;
image*) exec iview "${1}" & ;;
*pdf) exec gv "${1}" & ;;
*) printf "Plumber ran into an edge case with the following string/mime\n%s"\
"${1}"|xmessage -file - & ;;
esac
fi
exit