slitaz-dev-tools rev 96

Baba scripts
author Babaorum <postmaster@baba0rum.com>
date Mon May 30 15:10:14 2011 +0100 (2011-05-30)
parents c9f517d25721
children affbc3fda53b
files baba-scripts/edf baba-scripts/rename.pl baba-scripts/reninc.pl baba-scripts/renup.pl baba-scripts/xdf baba-scripts/yaff
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/baba-scripts/edf	Mon May 30 15:10:14 2011 +0100
     1.3 @@ -0,0 +1,34 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +MAIN_DIALOG='
     1.7 +<window title="edf" window_position="1" decorated="false" width-request="600">
     1.8 +	<vbox>
     1.9 +		<text use-markup="true"><label>"<b>Enhanced df</b>"</label></text>
    1.10 +		<text height-request="10"><label>""</label></text>
    1.11 +		<tree>
    1.12 +			<label>Device|Mount point|Total size|Occupied|Occ.ratio|Free</label>
    1.13 +'
    1.14 +I=$IFS; IFS=$'\n'
    1.15 +for line in `df -h | tail -n +2 | grep ^/dev/ | sed -e "s/ \+/|/g"`
    1.16 +do
    1.17 +	device=`echo $line | cut -d'|' -f1`
    1.18 +	total=`echo $line | cut -d'|' -f2`
    1.19 +	occupied=`echo $line | cut -d'|' -f3`
    1.20 +	free=`echo $line | cut -d'|' -f4`
    1.21 +	ratio=`echo $line | cut -d'|' -f5`
    1.22 +	mount=`echo $line | cut -d'|' -f6`
    1.23 +	MAIN_DIALOG=$MAIN_DIALOG"
    1.24 +				<item>$device|$mount|$total|$occupied|$ratio|$free</item>"
    1.25 +done
    1.26 +IFS=$I
    1.27 +MAIN_DIALOG=$MAIN_DIALOG'
    1.28 +		</tree>
    1.29 +		<button ok></button>
    1.30 +	</vbox>
    1.31 +</window>
    1.32 +'
    1.33 +export MAIN_DIALOG
    1.34 +
    1.35 +gtkdialog -p MAIN_DIALOG
    1.36 +
    1.37 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/baba-scripts/rename.pl	Mon May 30 15:10:14 2011 +0100
     2.3 @@ -0,0 +1,22 @@
     2.4 +#! /usr/bin/perl
     2.5 +$testmode = 0;  #false
     2.6 +if ($ARGV[0] eq '-t') {
     2.7 +   $testmode = 1;  #true
     2.8 +   shift;
     2.9 +}
    2.10 +($regexp = shift @ARGV) || die "Usage:  rename [-t] perlexpr [filenames]\n-t : option to test action (nothing really done)\n";
    2.11 +if (!@ARGV) {
    2.12 +   @ARGV = <STDIN>;
    2.13 +   chomp(@ARGV);
    2.14 +}
    2.15 +print "Test mode\n" if ($testmode);
    2.16 +foreach $_ (@ARGV) {
    2.17 +   $old_name = $_;
    2.18 +   eval $regexp;
    2.19 +   die $@ if $@;
    2.20 +   unless ($old_name eq $_) {
    2.21 +	   print "$old_name -> $_\n";
    2.22 +	   rename($old_name, $_) unless $testmode;
    2.23 +   }
    2.24 +}
    2.25 +exit(0);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/baba-scripts/reninc.pl	Mon May 30 15:10:14 2011 +0100
     3.3 @@ -0,0 +1,45 @@
     3.4 +#! /usr/bin/perl
     3.5 +#check for help
     3.6 +chomp (my $workdir = `pwd`);
     3.7 +chomp (my $scriptname=`basename "$0"`);
     3.8 +scalar @ARGV > 0 || die <<EOT1;
     3.9 +Usage : $scriptname [-psdn [argument]] directory|here
    3.10 +
    3.11 +Options :
    3.12 +    -p prefix
    3.13 +    -s suffix
    3.14 +    -d starting_base_number
    3.15 +    -n length of number part (1: one number, 2: two numbers, etc)
    3.16 +
    3.17 +Parameters :
    3.18 +    directory : complete path of directory to process, or "here" for
    3.19 +                working directory
    3.20 +                ($workdir)
    3.21 +EOT1
    3.22 +#check arguments
    3.23 +my ($pref, $suff, $start, $num_length) = ('', '', 1, 1);
    3.24 +while (scalar @ARGV > 0)
    3.25 +{
    3.26 +	my $arg = shift @ARGV;
    3.27 +	if ($arg eq "-p") { $pref = shift @ARGV; next; }
    3.28 +	elsif ($arg eq "-s") { $suff = shift @ARGV; next; }
    3.29 +	elsif ($arg eq "-d") { $start = shift @ARGV; next; }
    3.30 +	elsif ($arg eq "-n") { $num_length = shift(@ARGV) - 1; next; }
    3.31 +	elsif (-d $arg) { $dir = shift @ARGV; next; }
    3.32 +	elsif ($arg eq "here") { $dir = $workdir; next; }
    3.33 +}
    3.34 +#main routine
    3.35 +chdir $dir;
    3.36 +foreach (<*>)
    3.37 +{
    3.38 +	my $counter = $start;
    3.39 +	my ($purename, $ext) = (m/^(.+?)\.([^\.]+)$/);
    3.40 +	for (my $n = 1; $n <= $num_length; $n++)
    3.41 +	{
    3.42 +		last if ($num_length eq 0);
    3.43 +		if ($start < 10**$n) { $counter = '0'.$counter; }
    3.44 +	}
    3.45 +	$start++;
    3.46 +	print "Rename \"$_\" in $pref$counter$suff.$ext\n";
    3.47 +	rename $_, $pref.$counter.$suff.'.'.$ext;
    3.48 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/baba-scripts/renup.pl	Mon May 30 15:10:14 2011 +0100
     4.3 @@ -0,0 +1,59 @@
     4.4 +#! /usr/bin/perl -w
     4.5 +chomp (my $scriptname = `basename "$0"`);
     4.6 +chomp (my $workdir = `pwd`);
     4.7 +my $help = <<HELP;
     4.8 +Usage : $scriptname -h
     4.9 +        $scriptname [-t] [work-directory]
    4.10 +HELP
    4.11 +my $testmode = 0;
    4.12 +my $prefix = "";
    4.13 +#check dependencies
    4.14 +die "Execution error: rename.pl needed but not found\n" if (`which rename.pl` eq '');
    4.15 +#check parameters
    4.16 +die $help if ($ARGV[0] eq '-h' or $ARGV[0] eq '--help');
    4.17 +foreach my $a (@ARGV)
    4.18 +{
    4.19 +	if ($a eq '-t') { $testmode = 1; }
    4.20 +	else
    4.21 +	{
    4.22 +		$a = $workdir.'/'.$a if ($a !~ /^\//);
    4.23 +		if(-d $a and -r $a) { $workdir = $a; }
    4.24 +		else { die "Syntax error: $a is not a valid directory\n$help"; }
    4.25 +	}
    4.26 +}
    4.27 +#asks a pattern for rename.pl if unknown
    4.28 +if ($prefix eq '')
    4.29 +{
    4.30 +	print "*** CAUTION: no prefix specified in substitution pattern for rename.pl\n";
    4.31 +	print "*** Please fill in a prefix once for the whole process\n";
    4.32 +	print "*** (press ENTER key to validate) : ";
    4.33 +	chomp ($prefix = <STDIN>);
    4.34 +}
    4.35 +#look for subdirectories in $workdir
    4.36 +print "Scanning subdirectories in $workdir...\n";
    4.37 +chdir $workdir;
    4.38 +foreach $f (<*>)
    4.39 +{
    4.40 +	my $path = $workdir.'/'.$f;
    4.41 +	if (-d $path)
    4.42 +	{
    4.43 +		chdir $path;
    4.44 +		my @all = <*>;
    4.45 +		my @regularfiles = grep { -f } @all;
    4.46 +		printf "\n> %s : %d files\n", $f, scalar @regularfiles;
    4.47 +		next if (scalar @regularfiles == 0);  #skip if empty
    4.48 +		#parse numeric part of $path to use in rename.pl's pattern
    4.49 +		$path =~ /(\d+)/;
    4.50 +		my $num = $1;
    4.51 +		system 'rename.pl '.($testmode == 1? '-t ':'').'"s/^/'.$prefix.$num.'_/" *';  #call rename.pl
    4.52 +		#update files data (changed because of renaming)
    4.53 +		@all = <*>;
    4.54 +		@regularfiles = grep { -f } @all;
    4.55 +		#~ print join ("\n", @regularfiles), "\n";
    4.56 +		map { rename $_, $workdir.'/'.$_ } @regularfiles unless ($testmode);  #move files one level up
    4.57 +		#check for subdirectory inside
    4.58 +		if (scalar (grep { -d } @all) > 0) { warn "Caution: subdirectory found in $f => not deleted\n"; next; }
    4.59 +		chdir $workdir;
    4.60 +		unless ($testmode) { rmdir $path or die "$!\n"; }
    4.61 +	}
    4.62 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/baba-scripts/xdf	Mon May 30 15:10:14 2011 +0100
     5.3 @@ -0,0 +1,39 @@
     5.4 +#!/bin/sh
     5.5 +field() {
     5.6 +	textwidth=`length "$1"`
     5.7 +	freewidth=$(( $2 - $textwidth ))
     5.8 +	fieldtext="$1"
     5.9 +	position=${3-after}
    5.10 +	for i in `seq 1 $freewidth`; do
    5.11 +		case $position in
    5.12 +			before) fieldtext=" $fieldtext" ;;
    5.13 +			after) 	fieldtext="$fieldtext " ;;
    5.14 +		esac
    5.15 +	done
    5.16 +	echo "$fieldtext"
    5.17 +}
    5.18 +#df -h | grep ^/dev/ | grep -v ^/dev/root | sed "s/ \+/ /g" | while read line; do
    5.19 +df -h | grep ^/dev/ | sed "s/ \+/ /g" | while read line; do
    5.20 +	device=`echo $line | cut -d' ' -f1`
    5.21 +	device=`field $device 8`
    5.22 +	size=`echo $line | cut -d' ' -f2`
    5.23 +	size=`field $size 6 before`
    5.24 +	used=`echo $line | cut -d' ' -f3`
    5.25 +	used=`field $used 6 before`
    5.26 +	free=`echo $line | cut -d' ' -f4`
    5.27 +	free=`field $free 6 before`
    5.28 +	usepercent=`echo $line | cut -d' ' -f5`
    5.29 +	usebar="|"
    5.30 +	counter=`expr ${usepercent%\%} '/' 10`
    5.31 +	for i in `seq 1 $counter`; do
    5.32 +		usebar="${usebar}>"
    5.33 +	done
    5.34 +	for i in `seq $counter 9`; do
    5.35 +		usebar="${usebar}."
    5.36 +	done
    5.37 +	usebar="${usebar}|"
    5.38 +	usepercent=`field $usepercent 4 before`
    5.39 +	mntpoint=`echo $line | cut -d' ' -f6`
    5.40 +	mntpoint=`field "($mntpoint)" 20`
    5.41 +	echo "$device $mntpoint $used/$size $usebar $usepercent - $free free"
    5.42 +done
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/baba-scripts/yaff	Mon May 30 15:10:14 2011 +0100
     6.3 @@ -0,0 +1,198 @@
     6.4 +#!/bin/sh
     6.5 +BIN=`which firefox`
     6.6 +PROFILE_DIR=$HOME/.mozilla/firefox
     6.7 +CONFDIR=$HOME/.yaff
     6.8 +VERCONF=$CONFDIR/versions.conf
     6.9 +PROFCONF=$CONFDIR/profiles.conf
    6.10 +INSTANCES=`ps | grep firefox-bin | grep -v 'grep firefox-bin' | grep -v /bin/sh | wc -l`
    6.11 +[ $INSTANCES -gt 0 ] && NOREMOTE='-no-remote' || NOREMOTE=''
    6.12 +FIREFOX='3.5.7#/usr/bin/firefox 3.6#/home/gg/apps/firefox-3.6/firefox 4#/home/gg/apps/firefox-4/firefox#Firefox-4b'
    6.13 +PROFILES=""
    6.14 +
    6.15 +add_new_versions() {
    6.16 +	local tmp=`mktemp -t -p $CONFDIR`
    6.17 +	ADD_VERSIONS='
    6.18 +<window title="Yaff - Add new versions">
    6.19 +	<vbox>
    6.20 +		<hbox>
    6.21 +			<text width-request="100"><label>Version number</label></text>
    6.22 +			<entry width-request="20"><variable>VERNUMBER</variable></entry>
    6.23 +		</hbox>
    6.24 +		<button ok></button>
    6.25 +	</vbox>
    6.26 +</window>'
    6.27 +	export ADD_VERSIONS
    6.28 +	gtkdialog --program=ADD_VERSIONS &> $tmp
    6.29 +	cat $tmp
    6.30 +	[ -f "$tmp" ] && rm -f $tmp
    6.31 +}
    6.32 +
    6.33 +[ ! -d "$CONFDIR" ] && mkdir -p $CONFDIR
    6.34 +#~ [ ! -f "$VERCONF" -o `stat -c %s $VERCONF` -eq 0 ] && add_new_versions
    6.35 +[ ! -f "$VERCONF" -o `stat -c %s $VERCONF` -eq 0 ]
    6.36 +
    6.37 +[ ! -f "$PROFCONF" ] && touch $PROFCONF; echo -n "" > $PROFCONF
    6.38 +for firefox in $FIREFOX
    6.39 +do
    6.40 +	version=`echo $firefox | cut -d '#' -f 1`
    6.41 +	exec=`echo $firefox | cut -d '#' -f 2`
    6.42 +	profile=`echo $firefox | cut -d '#' -f 3`
    6.43 +	echo "$profile|$version" >> $PROFCONF
    6.44 +	[ -n "$profile" -a "$profile" != "" ] && echo "$version|$profile" >> $PROFCONF
    6.45 +done
    6.46 +	
    6.47 +
    6.48 +MAIN_DIALOG='
    6.49 +<window title="Yet Another Firefox" window_position="1">
    6.50 +	<vbox>
    6.51 +		<notebook labels="Choose a profile|Configuration|Information">
    6.52 +			<vbox>
    6.53 +				<list selection-mode="2">
    6.54 +					<variable>PROFIL</variable>'
    6.55 +[ ! -d $PROFILE_DIR ] && echo "Directory $PROFILE_DIR not found" >&2 && exit 1
    6.56 +cd $PROFILE_DIR
    6.57 +for dir in $(ls -F $PROFILE_DIR | grep -iv "Crash" | grep -iv "reports" | grep \/$ | grep -v "~/$")
    6.58 +#~ for dir in $(echo "$PROFILES")
    6.59 +do
    6.60 +	[ ! -d $dir -o ! -r $dir ] && continue
    6.61 +	dir=${dir#*.}
    6.62 +	MAIN_DIALOG=${MAIN_DIALOG}'<item>'${dir%%/}'</item>'
    6.63 +done
    6.64 +MAIN_DIALOG=$MAIN_DIALOG'
    6.65 +				</list>
    6.66 +				<text>
    6.67 +					<label>'$INSTANCES' running instance(s) of Firefox detected.</label>
    6.68 +				</text>
    6.69 +				<hbox homogeneous="true">'
    6.70 +for firefox in $FIREFOX
    6.71 +do
    6.72 +	version=`echo $firefox | cut -d '#' -f 1`
    6.73 +	exec=`echo $firefox | cut -d '#' -f 2`
    6.74 +	profile=`echo $firefox | cut -d '#' -f 3`
    6.75 +	radio='<radiobutton><label>'$version'</label><variable>F'${version//./_}'</variable></radiobutton>'
    6.76 +	#echo $radio
    6.77 +	MAIN_DIALOG=$MAIN_DIALOG$radio
    6.78 +done
    6.79 +MAIN_DIALOG=$MAIN_DIALOG'
    6.80 +				</hbox>
    6.81 +				<hbox>
    6.82 +					<button>
    6.83 +						<input file>/usr/share/pixmaps/mozicon16.png</input>
    6.84 +						<label>Launch Firefox</label>
    6.85 +						<action>Exit:OK</action>
    6.86 +					</button>
    6.87 +					<button>
    6.88 +						<input file icon="gtk-quit"></input>
    6.89 +						<label>Quit</label>
    6.90 +						<action type="CloseWindow">MAIN_DIALOG</action>
    6.91 +					</button>
    6.92 +				</hbox>
    6.93 +			</vbox>
    6.94 +			
    6.95 +			<vbox>
    6.96 +				<tree>
    6.97 +					<label>Version | Profile</label>
    6.98 +					<variable>DEFAULT_PROFILE</variable>'
    6.99 +for firefox in $FIREFOX
   6.100 +do
   6.101 +	version=`echo $firefox | cut -d'#' -f1`
   6.102 +	exec=`echo $firefox | cut -d'#' -f2`
   6.103 +	profile=`echo $firefox | cut -d'#' -f3`
   6.104 +	MAIN_DIALOG=$MAIN_DIALOG"<item>$version|$profile</item>"
   6.105 +done
   6.106 +MAIN_DIALOG=$MAIN_DIALOG'
   6.107 +				</tree>
   6.108 +				<hbox>
   6.109 +					<text>
   6.110 +						<label>Version number</label>
   6.111 +					</text>
   6.112 +					<entry>
   6.113 +						<variable>ENTRY_VERSION_NUMBER</variable>
   6.114 +					</entry>
   6.115 +				</hbox>
   6.116 +				<hbox>
   6.117 +					<text>
   6.118 +						<label>Path to this version executable</label>
   6.119 +					</text>
   6.120 +					<entry>
   6.121 +						<variable>ENTRY_VERSION_BIN</variable>
   6.122 +					</entry>
   6.123 +				</hbox>
   6.124 +				<hbox>
   6.125 +					<text>
   6.126 +						<label>Default profile</label>
   6.127 +					</text>
   6.128 +					<entry>
   6.129 +						<variable>ENTRY_VERSION_DEFAULT_PROFILE</variable>
   6.130 +					</entry>
   6.131 +				</hbox>
   6.132 +				<hbox>
   6.133 +					<button>
   6.134 +						<input file icon="gtk-add"></input>
   6.135 +						<label>New version</label>
   6.136 +						<action>zenity --info --text="coucou"</action>
   6.137 +					</button>
   6.138 +					<button>
   6.139 +						<input file icon="gtk-quit"></input>
   6.140 +						<label>Quit</label>
   6.141 +						<action type="CloseWindow">MAIN_DIALOG</action>
   6.142 +					</button>
   6.143 +				</hbox>
   6.144 +			</vbox>
   6.145 +			
   6.146 +			<vbox>
   6.147 +				<frame>
   6.148 +					<text use-markup="true" width-chars="30" height-request="50">
   6.149 +						<label>"<i>Copyleft [^c] 2010 Babaorum</i>"</label>
   6.150 +					</text>
   6.151 +					<text use-markup="true" width-chars="30">
   6.152 +						<label>"<b>YAFF (Yet Another Firefox)</b>"</label>
   6.153 +					</text>
   6.154 +					<text>
   6.155 +						<label>lets you launch many instances of Firefox in different versions with different profiles.</label>
   6.156 +					</text>
   6.157 +				</frame>
   6.158 +				<hbox>
   6.159 +					<button>
   6.160 +						<input file icon="gtk-quit"></input>
   6.161 +						<label>Quit</label>
   6.162 +						<action type="CloseWindow">MAIN_DIALOG</action>
   6.163 +					</button>
   6.164 +				</hbox>
   6.165 +			</vbox>
   6.166 +		</notebook>
   6.167 +	</vbox>
   6.168 +</window>'
   6.169 +export MAIN_DIALOG
   6.170 +VARIABLES=$(gtkdialog --program=MAIN_DIALOG)
   6.171 +eval $VARIABLES
   6.172 +for firefox in $FIREFOX
   6.173 +do
   6.174 +	version=`echo $firefox | cut -d '#' -f 1`
   6.175 +	bin=`echo $firefox | cut -d '#' -f 2`
   6.176 +	profile=`echo $firefox | cut -d '#' -f 3`
   6.177 +	name_var="F${version}"
   6.178 +	name_var=${name_var//./_}
   6.179 +	eval "version_var=\$$name_var"
   6.180 +	if [ "$version_var" = "true" ]
   6.181 +	then
   6.182 +		BIN=$bin
   6.183 +		if [ -n $profile -a "$profile" != "" -a "$PROFIL" = "" ]; then
   6.184 +			PROFIL=$profile
   6.185 +			export ALERT_DIALOG='
   6.186 +				<window title="CAUTION !" window_position="1">
   6.187 +					<vbox>
   6.188 +						<text use-markup="true"><label>"Profile for this version will be locked on: <b>'$PROFIL'</b>"</label></text>
   6.189 +						<button ok></button>
   6.190 +					</vbox>
   6.191 +				</window>'
   6.192 +			gtkdialog --program=ALERT_DIALOG
   6.193 +		fi
   6.194 +		break
   6.195 +	fi
   6.196 +done
   6.197 +if [ $EXIT = "OK" -a "$PROFIL" != "" ]
   6.198 +then
   6.199 +	echo "$BIN $NOREMOTE -P \"$PROFIL\" 1>/dev/null 2>&1"
   6.200 +	$BIN $NOREMOTE -P "$PROFIL" 1>/dev/null 2>&1
   6.201 +fi