Post your handy utility scripts!

Hey guys,

I have a couple of scripts I wrote as I was learning Arch, which I am still learning… I thought I would share them here… Mainly for Plasma DE as I only use Plasma, not tested on other DEs…

  • Automated KVM Install & Config Script :
#!/usr/bin/env bash
set -e
########################################################################################################################
# Author	:	TechXero Thanks to Ermanno Ferrari @EFLinux for How-To
# Website	:	https://www.techxero.com / https://www.eflinux.net
########################################################################################################################

echo "##################################################################################################################"
echo "#                                           KVM Installer Script                                                 #"
echo "##################################################################################################################"
sleep 3
echo "Downloading KVM and Dpendencies..."
sudo pacman -S --noconfirm --needed qemu qemu-arch-extra virt-manager ovmf vde2 ebtables dnsmasq bridge-utils openbsd-netcat
sudo wget "https://raw.githubusercontent.com/TechXero/ArchLinux/main/Configs-n-Scripts/kvmnet.xml" -O ~/kvmnet.xml
echo "Starting LibVirt-d Service..."
sudo systemctl enable libvirtd.service && sudo systemctl start libvirtd.service
sleep 5
echo "Setting up Networking services..."
sudo virsh net-define kvmnet.xml
sudo virsh net-start XeroNet
sudo virsh net-autostart XeroNet
echo "All Done Happy VM'ing. Brough to you by @TechXero & @ermanno_ferrari"
sleep 5
  • Automated SAMBA Install & Config Script :
#!/bin/bash
set -e
##################################################################################################################
# Author	:	TechXero
# Website	:	https://www.techxero.com
#################################################################################

echo "################################################################"
echo "#########       enabling samba software         ################"
echo "################################################################"

sudo pacman -S --noconfirm --needed samba
sudo wget "https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD" -O /etc/samba/smb.conf.original
sudo wget "https://raw.githubusercontent.com/arcolinux/arcolinux-system-config/master/etc/samba/smb.conf.arcolinux" -O /etc/samba/smb.conf.arcolinux
sudo wget "https://raw.githubusercontent.com/TechXero/ArchLinux/main/Configs-n-Scripts/smb.conf" -O /etc/samba/smb.conf
sudo systemctl enable smb.service
sudo systemctl start smb.service
sudo systemctl enable nmb.service
sudo systemctl start nmb.service

##Change your username here
read -p "What is your login? It will be used to add this user to smb : " choice
sudo smbpasswd -a $choice

#access samba share windows
sudo pacman -S --noconfirm --needed gvfs-smb

echo "################################################################"
echo "#########       samba  software enabled         ################"
echo "################################################################"
sleep 5
echo "Network Discovery"

sudo pacman -S --noconfirm --needed avahi
sudo systemctl enable avahi-daemon.service
sudo systemctl start avahi-daemon.service

#shares on a mac
sudo pacman -S --noconfirm --needed nss-mdns

#shares on a linux
sudo pacman -S --noconfirm --needed gvfs-smb

#change nsswitch.conf for access to nas servers
#original line comes from the package filesystem
#hosts: files mymachines myhostname resolve [!UNAVAIL=return] dns
#ArcoLinux line
#hosts: files mymachines resolve [!UNAVAIL=return] mdns dns wins myhostname

#first part
sudo sed -i 's/files mymachines myhostname/files mymachines/g' /etc/nsswitch.conf
#last part
sudo sed -i 's/\[\!UNAVAIL=return\] dns/\[\!UNAVAIL=return\] mdns dns wins myhostname/g' /etc/nsswitch.conf

echo "################################################################"
echo "####       network discovery  software installed        ########"
echo "################################################################"
sleep 5
echo "Network Shares"

if pacman -Qi samba &> /dev/null; then
  echo "###################################################################"
  echo "Samba is installed"
  echo "###################################################################"
else
  tput setaf 1;echo "###################################################################"
  echo "First use our scripts to install samba and/or network discovery"
  echo "###################################################################";tput sgr0
  exit 1
fi

#checking if filemanager is installed then install extra packages
if pacman -Qi dolphin &> /dev/null; then
  sudo pacman -S --noconfirm --needed kdenetwork-filesharing
fi
if pacman -Qi thunar &> /dev/null; then
  yay -S --noconfirm --needed thunar-shares-plugin
fi

FILE=/etc/samba/smb.conf

if test -f "$FILE"; then
    echo "/etc/samba/smb.conf has been found"
else
  tput setaf 1;echo "###################################################################"
  echo "We did not find /etc/samba/smb.conf"
  echo "First use our scripts to install samba and/or network discovery"
  echo "###################################################################";tput sgr0
  exit 1
fi

sleep 5

echo "################################################################"
echo "#########                       Some TechXero Magic                     ###############"
echo "################################################################"

file="/etc/samba/smb.conf"

sudo sed -i '/^\[global\]/a \
\
usershare allow guests = true \
usershare max shares =  100 \
usershare owner only = no \
usershare path = /var/lib/samba/usershares' $file

sudo mkdir -p /var/lib/samba/usershares
sudo groupadd -r sambashare
sudo gpasswd -a $USER sambashare
sudo chown root:sambashare /var/lib/samba/usershares
sudo chmod 1770 /var/lib/samba/usershares

tput setaf 1;echo "###################################################################"
echo "Now reboot before sharing folders"
echo "###################################################################";tput sgr0
  • Pamac-AUR for those like me who love it… (Uses Paru as helper since yay is dying)
#!/bin/bash
set -e
##################################################################################################################
# Written to be used on 64 bits computers
# Author 	: 	TechXero
# Website 	: 	http://www.techxero.com
##################################################################################################################
#################################################################################

sudo pacman -S base-devel --noconfirm --needed

echo "###################################################################"
echo "#########   Installing Paru & grabing Pamac-All ;)  ###############"
echo "###################################################################"
sleep 5

echo "First Step - Building & Installing Paru AUR Helper..."
sleep 5
source="https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=paru-bin"
folder="paru-bin"
name="PKGBUILD"

mkdir /tmp/$folder
wget $source -O /tmp/$folder/$name
cd /tmp/$folder
makepkg -i
sleep 5

echo "Final Step - Building & Installing Pamac-AUR GUI..."
sleep 5
paru -S pamac-aur
sleep 5

echo "All done, now you can profit !"
sleep 3
echo "Brought to you by @TechXero :D"
  • My .bashrc Aliases collection :
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

#list
alias ls='ls --color=auto'
alias la='ls -a'
alias ll='ls -la'
alias l='ls'          
alias l.="ls -A | egrep '^\.'"      

alias vtop='vtop -t wizard'

#fix obvious typo's
alias cd..="cd .."
alias pdw="pwd"

## Colorize the grep command output for ease of use (good for log files)##
alias grep="grep --color=auto"
alias egrep="egrep --color=auto"
alias fgrep="fgrep --color=auto"

#readable output
alias df='df -h'

#pacman unlock

alias unlock="sudo rm /var/lib/pacman/db.lck"

#free
alias free="free -mt"

#continue download
alias wget="wget -c"

#userlist
alias userlist="cut -d: -f1 /etc/passwd"

#merge new settings
alias merge="xrdb -merge ~/.Xresources"

# Aliases for software managment
# pacman or yay
alias search='sudo pacman -Qs'
alias remove='sudo pacman -R'
alias install='sudo pacman -S'
alias update='sudo pacman -Syyu'
alias clrcache='sudo pacman -Scc'
alias upall='yay && sudo pacman -Syyu'
alias psr="sudo pacman -Ss --color auto"
alias unlock='sudo rm /var/lib/pacman/db.lck'
alias orphans='sudo pacman -Rns $(pacman -Qtdq)'

alias aget='yay -S'
alias arm='yay -Rs'
alias pksyua='yay -Syu --noconfirm'

alias pdep="deps p"
alias pclean="sudo pacman -Rns \$(pacman -Qtdq)"

# yay as aur helper - updates everything
alias pksyua="yay -Syu --noconfirm"
alias upall="yay -Syu --noconfirm"
alias yins="yay -S --color auto"
alias yrm="yay -R --color auto"
alias ysr="yay -Ss --color auto"
alias ydep="deps y"

#generate repo databases
alias add-repo="repo-add hefftor-repo.db.tar.gz *.pkg.tar.xz"

#ps
alias psa="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"

#grub update
alias grubup='sudo grub-mkconfig -o /boot/grub/grub.cfg'

#improve png
alias fixpng="find . -type f -name "*.png" -exec convert {} -strip {} \;"

#add new fonts
alias fc="sudo fc-cache -fv"

#copy/paste all content of /etc/skel over to home folder - Beware
alias skel='cp -Rf ~/.config ~/.config-backup-$(date +%Y.%m.%d-%H.%M.%S) && cp -rf /etc/skel/* ~'
#backup contents of /etc/skel to hidden backup folder in home/user
alias bupskel='cp -Rf /etc/skel ~/.skel-backup-$(date +%Y.%m.%d-%H.%M.%S)'


#get fastest mirrors in your neighborhood 
alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
alias mirrord="sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist"
alias mirrors="sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist"
alias mirrora="sudo reflector --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist"


#copy bashrc-latest over on bashrc - cb= copy bashrc
alias cb="sudo cp /etc/skel/.bashrc-latest /etc/skel/.bashrc && cp /etc/skel/.bashrc-latest ~/.bashrc && cp /etc/skel/.bashrc-latest ~/.bashrc-latest && source ~/.bashrc"
alias ci="sudo cp /etc/skel/.inputrc-latest /etc/skel/.inputrc && cp /etc/skel/.inputrc-latest ~/.inputrc && cp /etc/skel/.inputrc-latest ~/.inputrc-latest"

#switch between bash and zsh
alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'"
alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'"

#quickly kill conkies
alias kc='killall conky'

#mounting the folder Public for exchange between host and guest on virtualbox
alias vbm="sudo mount -t vboxsf -o rw,uid=1000,gid=1000 Public /home/$USER/Public"

alias gpl="git pull"
alias gcl="git clone"
alias ga="git add"
alias gc="git commit -m"
alias gp="git push -u origin master"
alias gr="git rm"
alias grd="git rm -r"
alias gra="gitremote"
alias gcln="gitclone"

#Bash aliases
alias mkfile='touch'
alias thor='sudo thunar'
alias kc='killall conky'
alias jctl='journalctl -p 3 -xb'
alias ssaver='xscreensaver-demo'
alias pingme='ping -c64 techxero.com'
alias cls='clear && neofetch | lolcat'
alias traceme='traceroute techxero.com'
alias nxplayer='cd /usr/NX/bin/ && ./nxplayer & cls'
alias microcode='grep . /sys/devices/system/cpu/vulnerabilities/*'

# alias serv="ssh USER@192.168.1.3"
# alias servseed="ssh USER@joker.seedhost.eu"

#hardware info --short
alias hw="hwinfo --short"

alias sZ="source ~/.bashrc"

alias ~="cd ~ && source ~/.bashrc"

alias yt='youtube-dl --recode-video mp4'

#youtube-dl
alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "

alias ytv-best="youtube-dl -f bestvideo+bestaudio "

alias rmd='rm -r'
alias srm='sudo rm'
alias srmd='sudo rm -r'
alias cpd='cp -R'
alias scp='sudo cp'
alias scpd='sudo cp -R'

alias slin='sudo ln -s'
alias lin='ln -s'

#Recent Installed Packages
alias rip="expac --timefmt='%Y-%m-%d %T' '%l\t%n %v' | sort | tail -100"

#Cleanup orphaned packages
alias cleanup='sudo pacman -Rns $(pacman -Qtdq)'

#get the error messages from journalctl
alias jctl="journalctl -p 3 -xb"

#nano
alias bashrc='sudo nano ~/.bashrc'
alias pconf='sudo nano /etc/pacman.conf'
alias mkpkg='sudo nano /etc/makepkg.conf'
alias ngrub='sudo nano /etc/default/grub'
alias smbconf='sudo nano /etc/samba/smb.conf'
alias baloorc='sudo nano ~/.config/baloofilerc'
alias tgram='sudo nano ~/.local/share/applications/userapp-Telegram*'

alias nmkinitcpio="sudo nano /etc/mkinitcpio.conf"
alias nhefflogout="sudo nano /etc/oblogout.conf"

#shutdown or reboot
alias ssn="sudo shutdown now"
alias sr="sudo reboot"

#cd/ aliases
alias home='cd ~'
alias etc='cd /etc/'
alias music='cd ~/Music'
alias vids='cd ~/Videos'
alias conf='cd ~/.config'
alias desk='cd ~/Desktop'
alias pics='cd ~/Pictures'
alias dldz='cd ~/Downloads'
alias docs='cd ~/Documents'
alias sapps='cd /usr/share/applications'
alias lapps='cd ~/.local/share/applications'

#XanMod Kernel Builder 
alias xankey='gpg --recv-key'
alias xanbuild='nano PKGBUILD && makepkg -si'
alias xanclone='cd ~ && git clone https://aur.archlinux.org/linux-xanmod.git && cd linux-xanmod'

#shopt
shopt -s autocd # change to named directory
shopt -s cdspell # autocorrects cd misspellings
shopt -s cmdhist # save multi-line commands in history as single line
shopt -s dotglob
shopt -s histappend # do not overwrite history
shopt -s expand_aliases # expand aliases
# shopt -s nocasematch

clear && neofetch | lolcat
EDITOR=nano

Hope those help

6 Likes