Scripts To Rice Your Setup Pt.2


(¯\_(ツ)_/¯) #1

Scripts To Rice Your Setup


Hey *,
after some positive feedback about my last part and some time, here is the second one. This time we are working with sound…

Author Assigned Level: Hacker

Community Assigned Level:

  • Newbie
  • Wannabe
  • Hacker
  • Wizard
  • Guru

0 voters

Required Skills

  • Linux basics
  • Bash basics


I already had the idea to my second script years ago. Some time after playing the Portal games.
Back then I was mainly using Windows, for some reason o_O.

But now to the idea. I really like the sounds the turrets are making.

I am talking about those cute fuckers. :smiling_imp:

But why not use those sounds and let my pc play them for me? There surely is a time where it fits.
But first I need the sounds, so I googled and found the wiki page which provides all the sound files of the turrets. And even better I found in a forum a zip with all sounds included.

First Implementation

So, under Windows, it was obvious to open up the controls and just change the sounds to the ones I just downloaded and extracted. And we are done.

Now some years later, I came up with this idea again. But this time while using Linux. The problem: in most distros there, are no default sounds or even a control panel for it,
especially not in Arch, which is what I am running.
The solution: we simply script it, because it is Linux we are talking about :wink:

I installed mplayer, although every other via console usable player should be right.
Then I looked through the sounds available and picked the ones out, I want to use. And I renamed them, so I could use them via bash. My selection can be found here (I hope this file hoster is okay to use).
And then I wrote myself a (very) little bash script:


RAND=$[ $RANDOM % 20 ]
mplayer /home/lukas/scripts/error/error_$RAND.wav >/dev/null 2>&1 &

So shebang of course, to say with what we want to run our program.
Then to make things random and not the same every time, a random number in range of the available files.

And then I call mplayer (or whatever you want to use) with the file name according to the use case, so in this case for error sounds. And then I redirect the terminal output to /dev/null to not get it in my console every time our script is called. This would be very annoying.
And we want this all to run in the background. So we can continue while our sound is being played and we don’t have to wait. Therefore we put an & at the end so bash will run it “parallel” in the background.

So my events when a sound should be played:
  • on start up
  • before shutdown
  • on error in terminal
  • while find/locate
  • while pacman
  • while whoami
  • before lockscreen (if you got one)

The principal of the scripts and the call of them is not every time the same.

So I guess we start easy with the lock screen. Although not all of you will have one. But I got one, and I am using i3lock.
So for me I got a script which works with some images and gives them then to i3lock and make a fancy looking lock screen.
I did not came up with this code, I just modified it and riced it a bit and used it.



RAND1=$[ $RANDOM % 9 ]
while [ $RAND1 -eq $RAND2 ] || [ $RAND2 -eq -1 ];
	RAND2=$[ $RANDOM % 9 ]


scrot /tmp/screen.png

convert $TMPBG -blur 5x10 -quality 01 $TMPBG

convert $TMPBG $ICON1 -geometry +705+290 -quality 01 -composite -matte $TMPBG
convert $TMPBG $ICON2 -geometry +2300+260 -quality 01 -composite -matte $TMPBG

i3lock -u -i $TMPBG
rm /tmp/screen.png

and notice the call of our script at the beginning:


We don’t want to wait for the sound to finish playing, it is already taking long enough to lock the screen.
And the looks like this:


RAND=$[ $RANDOM % 4 ]
mplayer /home/lukas/scripts/screensaver/screensaver_$RAND.wav >/dev/null 2>&1 &

The matching files have to be called screensaver_[index].wav or the code has to be change accordingly. So has the number of sounds available where we make our random number.

Next up our error sound script.

The code looks almost the same.


RAND=$[ $RANDOM % 20 ]
mplayer /home/lukas/scripts/error/error_$RAND.wav >/dev/null 2>&1 &

But now to the call.

As you see, my prompt is making a little smiley [^_^]. And that’s because of my configuration of my .bashrc where I set my prompt according to the success of a command. If I get a positive response ^_^ in green (it isn’t possible to make anything in color with the markdown, is there?), on a failure 0_0 in red.
(disclaimer: also this code is not created by me, I also just used it for my rice)

The code for this looks like this:
PS1='$(if [[ $? == 0 ]]; then echo "\n┌[\e[0;32m^_^"; else echo "\n┌[\e[1;31m0_0"; fi)\e[0m]-[\h]-[\e[0;32;49m\w\[\e[0m]\n└>'
But you might already can guess where this is going.

So this is the code to set the PS1 alias the prompt. And then after echoing 0_0, we simply call our script to make a matching sound:

PS1='$(if [[ $? == 0 ]]; then echo "\n┌[\e[0;32m^_^"; else echo "\n┌[\e[1;31m0_0"; /home/lukas/scripts/ & fi)\e[0m]-[\h]-[\e[0;32;49m\w\[\e[0m] \n└>'

And like this, every time we enter a command the PS1 gets set and we are right there. We will get back to the .bashrc later.

### startup

Now, startup should be really easy. And I took the easiest way available. I used the XFCE session and startup tool, which either is pre-installed with XFCE or comes with the utils package. So if you use a different desktop environment you can go for their program doing this kind of stuff. An other option would be to create a .desktop file by hand or create a daemon or a service which calls our script on startup. Be sure to active the daemon so it will work.
I’m not going into each option, there are tutorials which tell you how to set this up.

That’s how XFCE makes it:

[Desktop Entry]


RAND=$[ $RANDOM % 10 ]
mplayer /home/lukas/scripts/startup/startup_$RAND.wav >/dev/null 2>&1 &

### shutdown But now for the shutdown sound, we need to create a service. All other possibilities that I tried didn't work. Either did the system already hang out my drive or the sound drivers aren't working anymore, or the system does not wait for the sound to finish playing. That was probably the hardest sound to play. But I got it working now, and it's really awesome.

Laying in /etc/systemd/system/shutdown.service:

Description=Shutdown Sound




RAND=$[ $RANDOM % 16 ]
mplayer /home/lukas/scripts/shutdown/shutdown_$RAND.wav >/dev/null 2>&1

!!!Pay attention that we don't want to put an `&` at the end, because then Linux won't wait with shutting down until the sound is completely played!!!

Now the rest and they all work the same way. We got our scripts:



RAND=$[ $RANDOM % 2 ]
mplayer /home/lukas/scripts/install/install_$RAND.wav >/dev/null 2>&1 &



RAND=$[ $RANDOM % 3 ]
mplayer /home/lukas/scripts/whoami/whoami_$RAND.wav >/dev/null 2>&1 &



RAND=$[ $RANDOM % 2 ]
mplayer /home/lukas/scripts/locate/locate_$RAND.wav >/dev/null 2>&1 &

And we write us an alias function in our `.bashrc` or wherever you have your aliases.
alias whoami=whoami_sound
	/usr/bin/locate "[email protected]"
alias "locate"=locate_sound
	/usr/bin/find "[email protected]"
alias "find"=find_sound
	sudo /usr/bin/pacman "[email protected]"
alias pacman=install_sound

Every time we call for example whoami, we instead call our function which calls our script and then the command we were calling in the first place. But important, don’t just write the command down, write the full path. Otherwise we create and endless loop, because apparently this counts as normal call.
On command which take parameters we have to give them to our real call too.


So that’s it. You may want to add a flag to regulate the volume or the output device.
I was thinking about making it a real program, like Iron Mans J.A.R.V.I.S for example, but I haven’t had an idea about how I can get all those different events into a single program. Maybe you got a idea and leave a hint in the comments. :wink:

I really hope you liked it, and stay tuned there will another part follow, maybe with some hardware included :thinking:.

``` # .bashrc

Source global definitions

if [ -f /etc/bashrc ]; then
. /etc/bashrc


RAND=$[ $RANDOM % 70]

os=(“Alpine Linux” “Antergos” “Arch Linux” “Arch Linux - Old” “BLAG” “BunsenLabs” “CentOS” “Chakra” “Chapeau” “Chrome OS” “CrunchBang” “CRUX” “Debian” “Deepin” “LinuxDeepin” “Devuan” “elementary OS” “Exherbo” “Fedora” “Frugalware” “Fuduntu” “Funtoo” “Fux” “Gentoo” “gNewSense” “Jiyuu Linux” “Kali Linux” “KaOS” “KDE neon” “Kogaion” “Korora” “Mint” “LMDE” “Logos” “Mageia” “Mandriva” “Manjaro” “Netrunner” “NixOS” “openSUSE” “Parabola GNU/Linux-libre” “Pardus” “Parrot Security” “PCLinuxOS” “Peppermint” “Qubes OS” “Raspbian” “Red Hat Enterprise Linux” “ROSA” “Sabayon” “SailfishOS” “Scientific Linux” “Slackware” “Solus” “SparkyLinux” “SteamOS” “SwagArch” “Trisquel” “Ubuntu” “Viperr” “Void” “DragonFlyBSD” “FreeBSD” “NetBSD” “OpenBSD” “FreeBSD - Old” “Unknown” “Haiku” “Mac OS X” “Cygwin”)

screenfetch -w -A ${os[$RAND]}


#PS1 without sound
#PS1=’$(if [[ $? == 0 ]]; then echo “\n┌[\e[0;32m^_^”; else echo “\n┌[\e[1;31m0_0”; fi)\e[0m]-[\h]-[\e[0;32;49m\w[\e[0m]\n└>’

rightprompt() {
printf “%*s” $COLUMNS “<┘”

#under construction
#PS1=’[$(tput sc; rightprompt; tput rc)]left prompt > ‘
PS1=’$(if [[ $? == 0 ]]; then echo “\n┌[\e[0;32m^_^”; else echo “\n┌[\e[1;31m0_0”; /home/lukas/scripts/ & fi)\e[0m]-[\h]-[\e[0;32;49m\w[\e[0m]-[\A]-[##]-[]-[]---------------------------------┐\n[$(tput sc; rightprompt; tput rc)]└>’

#ps1 and error sound
#without right text
#PS1=’$(if [[ $? == 0 ]]; then echo “\n┌[\e[0;32m^_^”; else echo “\n┌[\e[1;31m0_0”; /home/lukas/scripts/ & fi)\e[0m]-[\h]-[\e[0;32;49m\w[\e[0m] \n└>’


User specific aliases and functions

cd_ls() {
cd $1
ls --color=auto
alias cd=cd_ls
alias ls="ls --color"
alias …="cd …"
alias …="cd …/…"
alias makepkg=“makepkg -sirc”

alias whoami=whoami_sound
/usr/bin/locate “[email protected]
alias “locate”=locate_sound
/usr/bin/find “[email protected]
alias “find”=find_sound
sudo /usr/bin/pacman “[email protected]
alias pacman=install_sound

And here is my whole `.bashrc` if you want to take a look, maybe at some other aliases.
# Feedback
It is some work for me to write those articles, obviously, but I am also having fun.

Please give me some feedback and improvement suggestions.
Sorry for the long post, here is an ascii APERTURE logo :slight_smile:

      . :[email protected]@@[email protected]#H/.,+%;,
   ,/X+ [email protected]@[email protected]%=,-%[email protected]/,
 [email protected]; [email protected]@MH+-,;[email protected]@+-
;@[email protected]@M- [email protected];. [email protected]@M#@/.

,%[email protected]@MH ,@%= .—=-=:=,.
[email protected]#@@@MX ., -%HX$$%%%+;
=-./@M@M$ .;@MMMM@MM:
[email protected]/ -$MM/ [email protected]@@M$
,@M@H: :@: . =X#@@@@-
,@@@MMX, . /H- ;@M@M=
[email protected]@@@M@+, %MM+…%#$.
/[email protected]/. [email protected]; =;
/%+%[email protected]$= , [email protected]@@@MX,
.=--------. -%H.,@@@@@MX,
.%[email protected]@@HHHXX$$$%± .:$MMX [email protected]@MM%.
[email protected]@MM#H;,[email protected]+ /MMMX=
=%@M@M#@[email protected]@@@M; %M%=
,:+$±,/H#[email protected]= =,

(oaktree) #2

This was cool. We all know that real hacking requires quirky sound feedback at all times. :yum:

(Command-Line Ninja) #3

I have never thought about sound. Feedback, however is a really powerful tool in design; I like this!

It would be cool to integrate these sounds into malware. You could seriously freak somebody out using these sounds :stuck_out_tongue:

([email protected] [email protected]) #4

Agreed! Metasploit actually has a payload (for windows I think) that plays the sound “You’ve been pwned” (Or something of that nature) on the target machine . It’s a great tool for testing exploits and freaking out friends & family.

(Command-Line Ninja) #5

When I was small, I used to SSH into my families Apple computers, and use the say command to freak them out xD

(oaktree) #6

@pry0cc, you can also overwrite common commands with an alias that does a say.