P32653 Shell wrapper for ** Deep Web Radio ** link reply
I found this site where I could listen to the radio over Tor so I wrote a shell wrapper so that can do it through the terminal.

http://lambdaplusjs35padjaiz4jw2fugdoeutse262phqr72uf634s2wdbqd.onion/misc/32521

I suck at bash, and have only written a few scripts before, if there's some sage around that can tell me how to improve it and cut down the lines of code I would appreciate it. Either way it works.

```
#!/bin/bash

# A script that streams various radio channels over Tor with mpv
# Source of music is ** Deep Web Radio **
# http://anonyradixhkgh5myfrkarggfnmdzzhhcgoy2v66uf7sml27to5n2tid.onion/

# Global variables
hservice="http://anonyradixhkgh5myfrkarggfnmdzzhhcgoy2v66uf7sml27to5n2tid.onion/"
wrapped="torsocks mpv"
sfx=".m3u"
rstation1="AnonyJazz"
rstation2="AnonyRadio"
rstation3="BaroqueRadio"
rstation3="DarkRet"
rstation4="DeepBanjo"
rstation5="DeepSpaceOne"
rstation6="DroneZone"
rstation7="GrooveSalad"
rstation8="Lush"
rstation9="c0vertElectr0"

# Check Dependencies
if [[ $(command -v mpv | wc -l) -ne 1 ]] ; then
echo "Error: mpv must be installed to run this script."
exit 1

elif [[ $(command -v torsocks | wc -l) -ne 1 ]] ; then
echo "Error: torsocks must be installed to run this script."
exit 1
else
:
fi


usage()
{
cat <<-EndUsage
Usage: $(basename $0) [OPTIONS]

Options:
-h --help Display this help and exit
-l --list List available stations
-s --station Radio station to stream
EndUsage
exit 0
}

list()
{
cat <<-EndStations
Available Stations:
(1) Anony JaZZ
(2) Radio Cladenstin@
(3) BaroqueRadio
(4) DarkRet
(5) DeepBanjo
(6) DeepSpaceOne
(7) DroneZone
(8) GrooveSalad
(9) Lush
(10) c0vertElectr0
EndStations
exit 0
}

station()
{
chosen_station="$1"
case "$chosen_station" in
"1")
${wrapped} ${hservice}${rstation1}${sfx}
exit;;
"2")
${wrapped} ${hservice}${rstation2}${sfx}
exit;;
"3")
${wrapped} ${hservice}${rstation3}${sfx}
exit;;
"4")
${wrapped} ${hservice}${rstation4}${sfx}
exit;;
"5")
${wrapped} ${hservice}${rstation5}${sfx}
exit;;
"6")
${wrapped} ${hservice}${rstation6}${sfx}
exit;;
"7")
${wrapped} ${hservice}${rstation7}${sfx}
exit;;
"8")
${wrapped} ${hservice}${rstation8}${sfx}
exit;;
"9")
${wrapped} ${hservice}${rstation9}${sfx}
exit;;
"10")
${wrapped} ${hservice}${rstatio410}${sfx}
exit;;
esac

}

while getopts ":hls" args; do
case $args in
h|help) # Display help and exit
usage
exit;;
l|list) # List available stations
list
exit;;
s|station) # Radio station to stream
station $2
;;
?) # Invalid argument
usage
exit;;
esac
done
```
P32654 link reply
[spoiler: lambdaplusjs needs code formatting.]
P32658 link reply
P32654
i agree [bold: see] >>P2203
P32671 12of7 link reply
P32667
No!!!
This is a Snopes proxy though if your that much of a tranny
http://sd.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/
P32674 link reply
P32668
You inspired me to try it out with the Baroque radio only to find out that it plays a different channel. I have no idea why, and there's also a 10th channel despite the site not having 10 of them. That's your problem to fix if you care enough about it, I had my fun.
P32675 link reply
>there's also a 10th channel despite the site not having 10 of them.
That was a lie, it works now, Baroque too. https://ghostbin.me/640bec7d80b0e
bash dradio.sh -s 3 for some nice classical.
12of7 P32726 link reply
>based picture
very neat
>random link with possible search browser
alrighty then, hope no CIA shit
>dig a bit and see that the site is a hosting site
neat thing, idk if it's CIA or not, idc eighterway, I don't use those lmfao (onion ones as no usage for me rn)
P32742 POSIX squad link reply
Wew.

>Not POSIX
>bash
>not set -eu
>[[ ]] instead of [ ]
>Not using command exit status and instead parsing output
>Using echo braindamage
>case in station repeats commands over and over instead of just setting a variable and having a single command at the end
>getotps doesn't support long arguments (there's getopts_long script around to support those)
>s arg requires a value so optstring should have "s:"
>exit commands all over the place
>Not quoting variables
P32769 link reply
P32742
Those are way better, thanks for improving it. I just looked things up online as I was writing it. Want to point me anywhere I can learn?

I was referencing this:
https://devmanual.gentoo.org/tools-reference/bash/index.html
https://devhints.io/bash
P32771 link reply
P32769
Those look fine for getting started, but those can also make you fall into the bashism trap [spoiler: like I once did].
I just learned writing scripts, doing a quick search:
https://www.grymoire.com/Unix/Sh.html
https://steinbaugh.com/posts/posix.html
https://drewdevault.com/2018/02/05/Introduction-to-POSIX-shell.html

More autism:
https://www.etalabs.net/sh_tricks.html
https://dwheeler.com/essays/fixing-unix-linux-filenames.html

You should always declare shebang as #!/bin/sh and you can use shellcheck to check if syntax is POSIX compliant or other mistakes. It won't warn you if you use non-POSIX arguments for some utility, though.
set -u is also highly advisable.
P32804 link reply
> Want to point me anywhere I can learn?
https://www.gnu.org/software/bash/manual/
P34261 link reply
P32742
P32771
I wrote a new script and tried to keep it POSIX compliant, shellcheck gives no warnings. Any pointers or improvements to this one?
I have more ideas but I spend most of my time learning other languages right now. [spoiler: And I'm a noob with them as well.]

[spoiler: Also I'm not the OP of the nigger thread, in case you wonder.]
P34262 link reply
That's short enough that I can't *possibly* have made any sacrilegious mistakes, but I intend to make it work with mogrify and exiftool as well later.
P34316 link reply
P32653
P32742
P32771
Just use Python instead of writing shell spaghetti.
Shell script is literally useless at this point, trust me I've spent months writing shell scripts with hundred of lines trying to keep it POSIX compatible and all of that, it was a huge waste of my time. Just use Python for small scripts.
P34318 link reply
P34316
s/Python/Perl/g
P34324 link reply
P34318
string.gsub("s/Python/Perl/g", "Python/Perl", "Perl/Lua")
P34366 POSIX compliant walltext link reply
P34261
P34262
>any sacrilegious mistakes
Depends on what flavour of autism you're willing to take.

[spoiler: OCD mode:
* Be consistent using "$var" or ${var}"
]

Easy mode:
* You are looping twice over all files instead of just once.
* Glob should be *.png *.jpg *.jpeg *.gif *.mp4 which makes the case useless and could be removed and instead simply have a mv "${i}" "${filename}.${extension}"

Gotcha mode (https://dwheeler.com/essays/filenames-in-shell.html):
* Glob should actually be ./*.png ./*.jpg ./*.jpeg ./*.gif ./*.mp4. If files start with -, they'll make mv break.
* If you want to include hidden files it gets even more annoying. It would have to be ./*.png ./.*.png ./*.jpg ./.*.jpg ./*.jpeg ./.*.jpeg ./*.gif ./.*.gif ./*.mp4 ./.*.mp4
* If one glob fails to match, you'll get a literal "./*.jpg", "./.*.jpg" and so on, so you'll need to include a if [ -e "${i}" ] inside your for loops.
* Or just use find command + exec to find files like the link above describes.

POSIX is not your friend mode:
* shuf is actually not part of POSIX (https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html), so you should add an extra check for shuf at the start of the script like you do with mat2
* date +%s is not POSIX (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html). Check "Seconds since the epoch" on https://www.etalabs.net/sh_tricks.html for an alternative.

Please make it stop mode:
* If you instead want to get rid of shuf, [spoiler: like you should], to generate integers between a given range, be prepared to suffer because there's not a good way to do it.
I've talked about this before: P8197, P8345, P8361. POSIX only guarantees /dev/null, /dev/console and /tmp to exist, so you can't use /dev/random or any other file as a source of randomness.
What I ended up doing is using awk and taking advantage of how wildly sin(1/x) oscillates near x=0:
awk 'BEGIN{cmd="echo $$"; cmd | getline seed; close(cmd); t=srand(); srand(int(2147483648*sin(1/((t+int(seed))/9223372036854775808)))); printf "%d\n",(rand()*65536)}'

Also, I hope you are aware since you have set -e, if any command fails at any moment, script will immediatelly exit, so you may or may not want to do something like:
mat2 --inplace "$i" 2> /dev/null >/dev/null || mv "${i}" ../failed
In this case it might also make sense to loop twice.

>[spoiler: Also I'm not the OP of the nigger thread, in case you wonder.]
What thread?
P34368 GNU+sudoku link reply
I forgot to include source for the /dev/null, /dev/console and /tmp thing. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap10.html
I also forgot about /dev/tty.
P34396 link reply
P34366 (dubs of autism)
wtf is even the point of following posix cuckoldry to the letter if everybody here uses gnu anyway
bsdfags are used to having to adapt everything they try to run
and temple os is a meme
P34408 link reply
P34366
A minor but relevant correction. Instead of
awk 'BEGIN{cmd="echo $$"; cmd | getline seed; close(cmd); t=srand(); srand(int(2147483648*sin(1/((t+int(seed))/9223372036854775808)))); printf "%d\n",(rand()*65536)}'
it should be
awk 'BEGIN{cmd="echo $$"; cmd | getline seed; close(cmd); srand(); t=srand(); srand(int(2147483648*sin(1/((t+int(seed))/9223372036854775808)))); printf "%d\n",(rand()*65536)}'
with the double srand call.
POSIX doesn't define what first srand will return.
awk 'BEGIN{ print srand() }' returns 1 with busybox and current timestamp with mawk.
As a bonus, I also forgot to mention that
awk 'BEGIN{ srand(); print srand() }'
is an alternate way to get the same result as date +%s

P34396
Personally I once had to resort to busybox because reasons and nothing worked. After that I began my descent into POSIX cuckdom.
P34414 link reply
P34366
P34408
Didn't read.
Install Python.
WebM unrelated.
P34418 link reply
P34414
Now, that's an animu I haven't seen in a while.
>soundless
Shamefur dispray.
P34534 link reply
P34408
>awk 'BEGIN{ srand(); print srand() }'
>is an alternate way to get the same result as date +%s

holy shit
why dont they define the less autistic way to do that
P34536 link reply
P34414 or P34418
sauce?
P34705 link reply
P34534
¯\_ (ツ)_/¯

P34536
Flip Flappers.
P34708 link reply
P32653 tin foil
x