Scripts

From Trisquel Enhancement Project
Jump to: navigation, search

All scripts on this page can be downloaded here. The latest development code is available here.

autodetect-wifi[edit]

Screenshot
#!/bin/sh

# AUTODETECT-WIFI outputs the location of wireless driver/firmware
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT

# Driver
MODULE=$(lspci -ks`lspci|grep 'Network controller:'|cut -d' ' -f1`|grep 'Kernel modules:'|cut -d: -f2|tr -d ' ')	# wireless driver kernel module (internal)
[ "$1" = --in-use ] && MODULE=`ls /sys/class/net/wlan*/device/driver/module/drivers 2>/dev/null|head -1|cut -d: -f2`	# wireless driver kernel module in use
if [ "$MODULE" = '' ];then echo 'ERROR: There is no wireless device currently in use';exit;fi
DRIVER=`/sbin/modinfo $MODULE|grep ^filename:|tr -s ' '|cut -d' ' -f2`	# full path to wireless driver kernel module
echo DRIVER=$DRIVER

# Firmware
TMP=/tmp/firmware
sudo rmmod $MODULE 2>/dev/null
/sbin/udevadm monitor --property|grep ^FIRMWARE=|tail -1|cut -d= -f2>$TMP &
sudo modprobe $MODULE
killall udevadm
FIRMWARE=/lib/firmware/`cat $TMP`
[ "`cat $TMP`" = '/*(DEBLOBBED)*/' ] && FIRMWARE='(deblobbed)'
[ "`cat $TMP`" = '' ] && FIRMWARE='(none)'
rm $TMP
echo FIRMWARE=$FIRMWARE

Compress[edit]

Screenshot
#!/bin/sh

# COMPRESS is a Nautilus script for quick and efficient compression
# of files/folders
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
TMP=/tmp/stdout
ICON=/usr/share/icons/gnome/16x16/mimetypes/package-x-generic.png
(echo;7zr a -mx=9 "$1".7z "$1";echo $?>$TMP)|if ! zenity --progress --title="Adding files to archive" --window-icon=$ICON --width=312 --text="Archive: $1.7z" --pulsate --auto-close;then pkill 7zr;fi
[ `cat $TMP` = 2 ] && zenity --error --title= --window-icon=$ICON --text="An error occurred while adding files to the archive.";rm $TMP

Compress Audio[edit]

Screenshot
#!/bin/sh

# COMPRESS AUDIO is a Nautilus script for quick and efficient
# compression of audio data. Please note that the newly created
# content does not preserve the original folder structure.
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
TMP=/tmp/stderr
if [ -d "$1" ];then DIR="$1 (compressed)/";mkdir "$DIR";fi
(find "$1" -type f -printf '#%p\n' -execdir flac --output-prefix="$DIR" --best {} \; 2>$TMP &
until [ `ps xo%c|grep find`. = . ];do
	cat $TMP|tr '\15' '\12'|grep %|tail -1|cut -d: -f2|cut -d' ' -f2
done;pkill zenity)|if ! zenity --progress --title=Converting… --window-icon=. --width=221;then killall find flac;fi
[ "`cat $TMP|grep ERROR`" != '' ] && zenity --text-info --title=Error --window-icon=/usr/share/icons/gnome/16x16/status/error.png --width=500 --height=300 --filename=$TMP;rm $TMP

Create Checksum…[edit]

Screenshot
#!/bin/sh

# CREATE CHECKSUM is a Nautilus script for creating checksum files
# Copyright (C) 2012-13  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
ICON=/usr/share/icons/gnome/16x16/mimetypes/binary.png
EXT=`! zenity --list --title="Create Checksum" --window-icon=$ICON --width=268 --height=224 --text="Select the checksum method:" --column=Pick --column=Method true md5 false sha1 false sha256 false sfv --radiolist` && exit
if ! zenity --progress --title="Creating checksum file" --window-icon=$ICON --width=320 --text="Checksum: $1.$EXT" --pulsate;then killall find cfv;fi &
if [ $EXT != sfv ];then find "`basename "$1"`" -type f -exec "$EXT"sum {} \;>$1.$EXT;else mv $(cfv -rrC "`basename "$1"`"|sed s/:.*//) "`basename "$1"`".sfv;fi;pkill zenity
[ ! -e "$1".$EXT ] && zenity --error --title="Error – 'Create Checksum'" --window-icon=$ICON --width=348 --text="Error saving file $1.$EXT"

pavol[edit]

Screenshot
#!/bin/sh

# PAVOL is a volume control overcoming the maximal gain software-wise
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
[ "$1" = up ] && OP=+
[ "$1" = down ] && OP=-
[ "$OP" = '' ] && exit
CVOL=`pactl list sinks|grep '	Volume:'|cut -b13-15`
[ $CVOL = 0 ] && [ $OP = - ] && exit
[ $CVOL = 200 ] && [ $OP = + ] && exit
NVOL=`awk "BEGIN{print int($CVOL/5+.5)*5$OP 5}"`
[ $NVOL -lt 0 ] && NVOL=0
[ $NVOL -gt 200 ] && NVOL=200
pactl set-sink-volume 0 $NVOL%
pactl set-sink-mute 0 0
ICON=xfce4-mixer-muted
[ $NVOL -gt 0 ] && ICON=stock_volume-0
[ $NVOL -gt 33 ] && ICON=stock_volume-med
[ $NVOL -gt 66 ] && ICON=stock_volume
notify-send -i $ICON "PulseAudio Volume $NVOL%"

spkmute[edit]

Screenshot
#!/bin/sh

# SPKMUTE un/mutes internal speakers when jack sensing does not work
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
STAT=`ossmix jack.int-speaker.mute TOGGLE|cut -d' ' -f8`
pactl set-sink-mute 0 0
CVOL=0
ICON=xfce4-mixer-muted
if [ $STAT = OFF ];then
	CVOL=`pactl list sinks|grep '	Volume:'|cut -b13-15|tr -d ' '`
	[ $CVOL -gt 0 ] && ICON=stock_volume-0
	[ $CVOL -gt 33 ] && ICON=stock_volume-med
	[ $CVOL -gt 66 ] && ICON=stock_volume;fi
notify-send -i $ICON "Speaker Mute $STAT" "Current Volume is $CVOL%"

Split…[edit]

Screenshot
#!/bin/sh

# SPLIT is a Nautilus script for splitting large files/folders into
# smaller parts
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
TMP=/tmp/stdout
ICON=/usr/share/kde4/apps/krusader/icons/hicolor/16x16/actions/kr_split.png
SIZE=`! zenity --list --title=Splitter --window-icon=$ICON --height=276 --text="Split to volumes, bytes:" --column=Pick --column=Size --column=Usage true 25599k Gmail false 102399k Seafile false 700m CD false 4g upload false 4480m DVD false custom other --radiolist` && exit
[ $SIZE = custom ] && SIZE=`! zenity --entry --title=Splitter --window-icon=$ICON --text="Enter {Size}[b|k|m|g]:"` && exit
(echo;7zr a -mx=0 -v$SIZE "$1".7z "$1";echo $?>$TMP)|if ! zenity --progress --title=Splitting… --window-icon=$ICON --text="Splitting $1…" --pulsate --auto-close;then pkill 7zr;fi
[ `cat $TMP` = 2 ] && zenity --error --title="Error – 'Splitter'" --window-icon=$ICON --text="Error writing file $1.7z.001!";rm $TMP

switch-gfx[edit]

#!/bin/sh

# SWITCH-GFX is a graphic driver switcher for the Sony VAIO VPCZ1 series
# Copyright (C) 2011-13  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
LNK=x86_64-linux-gnu_gl_conf
VAL=`update-alternatives --query $LNK|grep ^Value:|cut -d' ' -f2`
GPU=`lspci|grep 'VGA compatible controller:'|cut -d' ' -f5`
LIB=`echo $VAL|cut -d/ -f5`;[ $LIB != mesa ] && LIB=`echo $VAL|cut -d/ -f4|cut -d- -f1`
LIB2=`echo $LIB|sed s/mesa/Intel/|sed s/nvidia/nVidia/`
if [ "$1" = --status ];then echo "Dynamic Hybrid Graphics System is set to \"`echo $GPU|sed s/Intel/STAMINA/|sed s/nVidia/SPEED/`\" ($GPU),
while the graphics libraries are linked to \"`echo $LIB|tr a-z A-Z`\" ($LIB2)";[ $GPU != $LIB2 ] && echo "
ERROR: The graphics libraries are linked wrong. To fix this,
       run \"$0\" from Terminal";exit;fi
if [ "$1" = --fix-nvidia ];then
	if [ $GPU != nVidia ];then echo "ERROR: You are not using the nVidia graphics driver";exit;fi
	sudo update-initramfs -u;sudo reboot;exit;fi
CMD="--set $LNK /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf";[ $LIB = mesa ] && CMD="--auto $LNK"
sudo update-alternatives $CMD;sudo ldconfig
sudo reboot

Take Ownership[edit]

#!/bin/sh

# TAKE OWNERSHIP is a Nautilus script for regaining file/folder
# permissions
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# HEADER
if ! touch /;then gksu sh "$0" "$1";exit;fi

# SCRIPT
USER=`who|cut -d' ' -f1`
chown -R $USER:$USER "$1"
chmod -R 775 "$1"
find "$1" -type f -exec chmod -x {} \;

(Un)mount ISO Image[edit]

#!/bin/sh

# (UN)MOUNT ISO IMAGE is a Nautilus script for un/mounting ISO images
# Copyright (C) 2013  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# HEADER
if ! touch /;then gksu sh "$0" "$1";exit;fi

# SCRIPT
DIR=/media/`isoinfo -d -i"$1"|grep '^Volume id:'|cut -b12-`
if [ ! -d "$DIR" ];then
	mkdir "$DIR";mount -oloop "$1" "$DIR";else
	umount "$DIR";rmdir "$DIR";fi

x-run[edit]

#!/bin/sh

# X-RUN overrides system settings while an application is running
# Copyright (C) 2012-13  Peter Kárász, pK SOFTWARE <myself600@opmbx.org>
#
# Licensed under the GNU GPLv3(+); see <https://gnu.org/licenses/gpl>
# for details.

# SCRIPT
CBRT=`cat /sys/class/backlight/acpi_video0/brightness`
CVOL=`pactl list sinks|grep '	Volume:'|cut -b13-15`
CINT=`pactl list sinks|grep Mute:|cut -d' ' -f2|sed -e s/yes/1/ -e s/no/0/`
CVAL=`ossmix jack.int-speaker.mute|cut -d' ' -f10`
apply(){
	echo $BRT|sudo tee /sys/class/backlight/acpi_video0/brightness
	pactl set-sink-volume 0 $VOL%
	pactl set-sink-mute 0 $INT
	ossmix jack.int-speaker.mute $VAL
}
deadbeef --pause
BRT=8 VOL=100 INT=0 VAL=ON;apply
$@
BRT=$CBRT VOL=$CVOL INT=$CINT VAL=$CVAL;apply