Some files moved to their own repos
This commit is contained in:
170
acpid.pl
170
acpid.pl
@@ -1,170 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Hibernates system if battery charge drops under $MIN_CHARGE and battery discharging
|
||||
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use Fcntl;
|
||||
|
||||
sub logger($); # logs messages if $debug != 0
|
||||
# maybe one time i'll use it
|
||||
sub i3wmstate; # returns 1 if i3wm running, else - 0
|
||||
|
||||
|
||||
$0 = 'acpid.pl';
|
||||
my $debug = 0;
|
||||
my $MIN_CHARGE = 10;
|
||||
|
||||
my $base = '/sys/class/power_supply/BAT0';
|
||||
|
||||
unless(-f "$base/present") {
|
||||
logger("Battery info at /sys/class/BAT0/present not found, quitting.\n");
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $battery_present = 2;
|
||||
my $battery_check = 2;
|
||||
my $charging = 2;
|
||||
|
||||
while ( sleep(180) ) {
|
||||
# check that battery is in place
|
||||
open(ACPI, "$base/present") or next;
|
||||
my $buf = '';
|
||||
|
||||
if (read(ACPI, $buf, 1)) {
|
||||
if ($battery_check == 0) {
|
||||
logger("Ability to read from /sys/class/BAT0/present restored\n");
|
||||
$battery_check = 1;
|
||||
}
|
||||
|
||||
if ($buf == '0') {
|
||||
if ($battery_present != 0) {
|
||||
logger("We have no battery, skipping charge level polling until it appears\n");
|
||||
$battery_present = 0;
|
||||
}
|
||||
|
||||
close ACPI;
|
||||
next;
|
||||
}
|
||||
} else {
|
||||
if ($battery_check != 0) {
|
||||
logger("Unable to read from /sys/class/BAT0/present\n");
|
||||
$battery_check = 0;
|
||||
}
|
||||
|
||||
close ACPI;
|
||||
next;
|
||||
}
|
||||
|
||||
close ACPI;
|
||||
$battery_present = 1;
|
||||
|
||||
# check status, we have no need to poll battery if it charging/charged
|
||||
unless (-f "$base/status") {
|
||||
logger("Something broken in /sys, unable to find $base/status, quitting\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# TODO: file access save state and print on change
|
||||
open(STATUS, "$base/status") or do {
|
||||
logger("Unable to open $base/status\n");
|
||||
next;
|
||||
};
|
||||
|
||||
$buf = <STATUS>;
|
||||
close STATUS;
|
||||
|
||||
chomp($buf);
|
||||
|
||||
if ($buf ne 'Discharging') {
|
||||
if ($charging != 1) {
|
||||
logger("Battery charging.\n");
|
||||
$charging = 1;
|
||||
}
|
||||
} else {
|
||||
if ($charging != 0) {
|
||||
logger("Battery discharging.\n");
|
||||
$charging = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# read charge state
|
||||
unless (-f "$base/capacity") {
|
||||
logger("Something broken in /sys, unable to find $base/capacity, quitting\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# TODO: file access save state and print on change
|
||||
open(CHARGE, "$base/capacity") or do {
|
||||
logger("Unable to open $base/capacity\n");
|
||||
next;
|
||||
};
|
||||
|
||||
read(CHARGE, $buf, 3) or do {
|
||||
logger("Unable to read $base/capacity, but file is in place\n");
|
||||
next;
|
||||
};
|
||||
|
||||
chomp($buf); # just in case
|
||||
|
||||
if ($buf < $MIN_CHARGE) {
|
||||
logger("Battery charge is less than 10%, hibernating\n");
|
||||
`dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate`;
|
||||
} else {
|
||||
if ($buf < ($MIN_CHARGE + 5)) {
|
||||
`notify-send --urgency=critical --expire-time=10000 --icon=battery-caution "Low battery charge: $buf%"`;
|
||||
}
|
||||
|
||||
if ( ($charging == 1) and ( $buf > 100) ) {
|
||||
`notify-send --urgency=normal --expire-time=3000 "Battery overcharging"`;
|
||||
}
|
||||
|
||||
logger("Charge is $buf%\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub logger ($) {
|
||||
if ($debug != 0) {
|
||||
my $msg = shift;
|
||||
$msg = localtime() . ' ' . $msg;
|
||||
syswrite STDOUT, $msg;
|
||||
}
|
||||
}
|
||||
|
||||
sub i3wmstate {
|
||||
my $flag = 0;
|
||||
opendir(P, '/proc') || die 'no /proc found!';
|
||||
|
||||
while (readdir(P)) {
|
||||
my $pid = $_;
|
||||
next unless(defined($pid));
|
||||
next if ($pid eq '');
|
||||
|
||||
if (-d "/proc/$pid") {
|
||||
# dir UID == APCID.pl process user owner
|
||||
if ((stat("/proc/$pid"))[4] == int(getpwnam($ENV{'LOGNAME'}))) {
|
||||
next unless(-r "/proc/$pid/cmdline");
|
||||
open(CMDLINE, "/proc/$pid/cmdline") || die "unable to open /proc/$pid/cmdline";
|
||||
my $cl = <CMDLINE>;
|
||||
close(CMDLINE);
|
||||
|
||||
if(defined($cl)) {
|
||||
if ((substr($cl, 0, 2) eq 'i3') and (length($cl) <= 4)) {
|
||||
$flag = 1;
|
||||
undef $cl;
|
||||
undef $pid;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
undef $cl;
|
||||
}
|
||||
}
|
||||
|
||||
undef $pid;
|
||||
}
|
||||
|
||||
return $flag;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use JSON::PP;
|
||||
|
||||
my $jstr = `ceph osd tree --format=json`;
|
||||
|
||||
my $json = decode_json $jstr;
|
||||
|
||||
my @nodes = @{ $json->{'nodes'} };
|
||||
|
||||
foreach my $node (@nodes) {
|
||||
if ($node->{'type'} eq 'host') {
|
||||
print "Хост: $node->{'name'}\n";
|
||||
my @children = @{ $node->{'children'} };
|
||||
|
||||
foreach my $child (@children) {
|
||||
print "Диск: osd.$child\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use warnings "all";
|
||||
use strict;
|
||||
use Fcntl;
|
||||
|
||||
sub get_ceph_status(); # defined - not healthy | undef - healthy
|
||||
sub mark_osd_out($);
|
||||
sub logger($);
|
||||
sub restore_prio(@);
|
||||
|
||||
if ((int(@ARGV) < 1) or ($ARGV[0] eq '--help') or ($ARGV[0] eq '-h')) {
|
||||
print "\n Usage: $0 osd_num osd_num osd_num\n\n";
|
||||
print " Example: user\@host\# $0 10 25 44 128 9 36 33 78 91\n\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my @osd_list = @ARGV;
|
||||
my $PACK = 2;
|
||||
my $OSDINDEX = 0;
|
||||
|
||||
while ( 1 ) {
|
||||
while ($PACK >0) {
|
||||
if (defined($osd_list[$OSDINDEX])) {
|
||||
logger("Mark $osd_list[$OSDINDEX] as in");
|
||||
mark_osd_in($osd_list[$OSDINDEX]);
|
||||
} else {
|
||||
# last (and not full) pack of osds, we _can_ quit now
|
||||
logger("All OSD marked as in");
|
||||
exit 0;
|
||||
}
|
||||
|
||||
$OSDINDEX = $OSDINDEX + 1;
|
||||
$PACK = $PACK - 1;
|
||||
sleep 300;
|
||||
}
|
||||
|
||||
while (defined(get_ceph_status())) {
|
||||
sleep 60;
|
||||
}
|
||||
|
||||
$PACK = 2;
|
||||
restore_prio(@osd_list);
|
||||
}
|
||||
|
||||
sub get_ceph_status() {
|
||||
my $status = `/bin/ceph -s`;
|
||||
my @msg = split(/\n/, $status);
|
||||
# by default we assume that ceph is unhealthy, with misplaced pgs, and degraded pgs
|
||||
my $healthy = undef;
|
||||
my $misplaced = undef;
|
||||
my $degraded = undef;
|
||||
|
||||
foreach (@msg) {
|
||||
return undef if ($_ =~ /health HEALTH_OK$/);
|
||||
$degraded = 1 if ($_ =~ /recovery \d+\/\d+ objects degraded/);
|
||||
$misplaced = 1 if ($_ =~ /recovery \d+\/\d+ objects misplaced/)
|
||||
}
|
||||
|
||||
if ((defined($degraded)) or (defined($misplaced))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub mark_osd_in($) {
|
||||
my $osd = shift;
|
||||
`/bin/ceph osd in $osd`;
|
||||
sleep(90);
|
||||
`./prio-recovery.sh $osd`;
|
||||
}
|
||||
|
||||
sub logger($) {
|
||||
my $msg = shift;
|
||||
syswrite STDOUT, "$msg\n";
|
||||
}
|
||||
|
||||
sub restore_prio(@) {
|
||||
my @osds = @_;
|
||||
|
||||
foreach(@osds) {
|
||||
`./prio-client.sh $_`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use warnings "all";
|
||||
use strict;
|
||||
use Fcntl;
|
||||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
|
||||
sub get_ceph_status(); # defined - not healthy | undef - healthy
|
||||
sub get_osd_status($); # give osd id, returns 1 if osd have pgs | undef - no pg left on osd
|
||||
sub mark_osd_out($);
|
||||
sub logger($);
|
||||
sub metabackup(@);
|
||||
sub worker(@);
|
||||
|
||||
|
||||
if ((int(@ARGV) < 1) or ($ARGV[0] eq '--help') or ($ARGV[0] eq '-h')) {
|
||||
print "\n Usage: $0 osd_num osd_num osd_num\n\n";
|
||||
print " Example: user\@host\# $0 10 25 44 128 9 36 33 78 91\n\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my @osd_list = @ARGV;
|
||||
my $PACK = 5;
|
||||
my $OSDINDEX = 0;
|
||||
my %JOBS;
|
||||
my $OSD;
|
||||
my @threads;
|
||||
|
||||
for (my $i = 0; $i < @osd_list; $i++) {
|
||||
if ($OSDINDEX >= $PACK) {
|
||||
$OSDINDEX = 0;
|
||||
}
|
||||
|
||||
${JOBS}{$OSDINDEX}{$osd_list[$i]} = 1;
|
||||
$OSDINDEX++;
|
||||
}
|
||||
|
||||
# ${JOBS}{$OSDINDEX}{OSD_ID} = 1
|
||||
# hash of hashes of hashes
|
||||
|
||||
foreach (keys(%JOBS)) {
|
||||
my @jobs = keys($JOBS{$_});
|
||||
push @threads, threads->create(\&worker, @jobs);
|
||||
sleep (300); # do not start all pack in one shot
|
||||
}
|
||||
|
||||
# wait 'till jobs are complete
|
||||
foreach (@threads) {
|
||||
$_->join();
|
||||
}
|
||||
|
||||
print "All requested OSDS are out, performing backup\n";
|
||||
metabackup(@osd_list);
|
||||
|
||||
exit 0;
|
||||
|
||||
sub get_ceph_status() {
|
||||
my $status = `/bin/ceph -s`;
|
||||
my @msg = split(/\n/, $status);
|
||||
# by default we assume that ceph is unhealthy, with misplaced pgs, and degraded pgs
|
||||
my $healthy = undef;
|
||||
my $misplaced = undef;
|
||||
my $degraded = undef;
|
||||
|
||||
foreach (@msg) {
|
||||
return undef if ($_ =~ /health HEALTH_OK$/);
|
||||
$degraded = 1 if ($_ =~ /recovery \d+\/\d+ objects degraded/);
|
||||
$misplaced = 1 if ($_ =~ /recovery \d+\/\d+ objects misplaced/)
|
||||
}
|
||||
|
||||
if ((defined($degraded)) or (defined($misplaced))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub get_osd_status($) {
|
||||
my $osd = shift;
|
||||
my $status = `ceph osd df`;
|
||||
|
||||
foreach (split(/\n/, $status)) {
|
||||
if ($_ =~ /^ ? ?$osd /) {
|
||||
$status = $_;
|
||||
}
|
||||
}
|
||||
|
||||
if ($status =~ / 0.$/) {
|
||||
# zero placement groups here
|
||||
return undef;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub mark_osd_out($) {
|
||||
my $osd = shift;
|
||||
`/bin/ceph osd out $osd`;
|
||||
}
|
||||
|
||||
sub logger($) {
|
||||
my $msg = shift;
|
||||
syswrite STDOUT, "$msg\n";
|
||||
}
|
||||
|
||||
sub metabackup(@) {
|
||||
my @list = @_;
|
||||
|
||||
# just to make sure :)
|
||||
while (defined(get_ceph_status())) {
|
||||
sleep 60;
|
||||
}
|
||||
|
||||
`mount|sudo grep ceph >/ceph-mountmap`;
|
||||
|
||||
system('/bin/sudo', '/bin/mkdir', "/root/ceph");
|
||||
chdir('/var/lib/ceph/osd');
|
||||
my $osd;
|
||||
|
||||
foreach $osd (@list) {
|
||||
system('/bin/sudo', "/bin/systemctl", "stop", sprintf("ceph-osd@%s", $osd));
|
||||
sleep 1;
|
||||
system('/bin/sudo', '/bin/tar', '-zcf', sprintf("/root/ceph/ceph-%s.tar.gz", $osd), sprintf("ceph-%s", $osd));
|
||||
}
|
||||
}
|
||||
|
||||
sub worker(@) {
|
||||
my @OSD = @_;
|
||||
|
||||
foreach my $osd (@OSD) {
|
||||
mark_osd_out($osd);
|
||||
sleep(15); # ceph is slow
|
||||
|
||||
while (defined(get_osd_status($osd))) {
|
||||
sleep 150;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
|
||||
my $str = `ceph osd pool stats`;
|
||||
my @arr = split(/\n\n/, $str);
|
||||
|
||||
my $msg = "{\n \"data\": [\n";
|
||||
|
||||
foreach my $p (@arr) {
|
||||
my @str = split(/\s+/, $p);
|
||||
next if ((not defined($str[1])) or ($str[1] eq ''));
|
||||
next if ((not defined($str[3])) or ($str[3] eq ''));
|
||||
{# in jinja template engine this is comment, so in real script fix this #}
|
||||
$msg .= sprintf(" {\n \"\{#POOLID}\": \"%s\",\n", $str[3]);
|
||||
$msg .= sprintf(" \"\{#POOLNAME}\": \"%s\"\n },\n", $str[1]);
|
||||
}
|
||||
chop($msg);
|
||||
chop($msg);
|
||||
|
||||
$msg .= "\n ]\n}\n";
|
||||
print $msg;
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
|
||||
sub usage();
|
||||
# print usage banner if we have not enough arg
|
||||
usage() if ((not defined($ARGV[1])) or ($ARGV[1] eq ''));
|
||||
|
||||
my $pflag = 0;
|
||||
my $paramflag = 0;
|
||||
|
||||
my $str = `ceph osd pool stats`;
|
||||
my @arr = split(/\n\n/, $str);
|
||||
|
||||
my $msg = "{\n \"data\": [\n";
|
||||
|
||||
foreach my $p (@arr) {
|
||||
next unless (defined((split(/\s+/, $p))[1]));
|
||||
next unless ((split(/\s+/, $p))[1] eq $ARGV[0]);
|
||||
|
||||
if ((split(/\s+/, $p))[4] eq 'nothing') {
|
||||
syswrite STDOUT, '0';
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my @data = split(/\n/, $p);
|
||||
|
||||
foreach my $l (@data) {
|
||||
if (substr($l, 2, 6) eq 'client') {
|
||||
if ($ARGV[1] eq 'crops') {
|
||||
syswrite STDOUT, (split(/\s/, $l))[10];
|
||||
} elsif ($ARGV[1] eq 'cwops') {
|
||||
syswrite STDOUT, (split(/\s/, $l))[13];
|
||||
} elsif ($ARGV[1] eq 'crbps') {
|
||||
if ((split(/\s/, $l))[5] =~ /^k/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^M/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^G/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024 * 1024;
|
||||
}
|
||||
} elsif ($ARGV[1] eq 'cwbps') {
|
||||
if ((split(/\s/, $l))[5] =~ /^k/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^M/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^G/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024 * 1024;
|
||||
}
|
||||
}
|
||||
} elsif (substr($l, 2, 8) eq 'recovery') {
|
||||
if ($ARGV[1] eq 'rbps') {
|
||||
if ((split(/\s/, $l))[5] =~ /^k/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^M/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024;
|
||||
} elsif ((split(/\s/, $l))[5] =~ /^G/) {
|
||||
syswrite STDOUT, (split(/\s/, $l))[4] * 1024 * 1024 * 1024;
|
||||
} else {
|
||||
# i never seen stats in bytes per second, so as an exception printout just zero
|
||||
syswrite STDOUT, '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
sub usage () {
|
||||
print <<EOF;
|
||||
Usage: $0 <poolname> <parameter>
|
||||
|
||||
Where parameter can be:
|
||||
crops - client reads per second
|
||||
cwops - client writes per second
|
||||
crbps - client read kbytes per second
|
||||
cwbps - client write kbytes per second
|
||||
rbps - recovery io in bytes per second
|
||||
EOF
|
||||
exit 0;
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
pool vms.sata.zone3 id 13
|
||||
nothing is going on
|
||||
|
||||
pool volumes.sata.zone1 id 14
|
||||
recovery io 1418 MB/s, 360 objects/s
|
||||
client io 24445 kB/s rd, 37316 kB/s wr, 975 op/s rd, 1115 op/s wr
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# This script reweights osd by 0.02 if utilization overgrows 85%
|
||||
# it also reweight osd 80% full osds by 0.01 as a "bonus".
|
||||
# It assumes that ceph cluster is less than 75-77% packed with data.
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use Fcntl;
|
||||
|
||||
use JSON::PP;
|
||||
use Data::Dumper;
|
||||
sub help();
|
||||
|
||||
my $dry = 1;
|
||||
|
||||
if (defined($ARGV[0]) and ($ARGV[0] eq '--do-it')) {
|
||||
my $jstr = `ceph osd df --format=json-pretty`;
|
||||
$jstr =~ s/\-nan/0/gi; # ceph tends to return broken json if custer is not in perfect shape
|
||||
my $j = decode_json $jstr;
|
||||
|
||||
foreach my $osd (@{$j->{'nodes'}}) {
|
||||
# skip all unrelated objects
|
||||
next unless (defined($osd->{'utilization'}));
|
||||
# skip all objects that are not 80% full
|
||||
next if ($osd->{'utilization'} < 80.000001);
|
||||
my $new_weight = 1;
|
||||
|
||||
if (($osd->{'utilization'} >= 80.000001) and ($osd->{'utilization'} < 85.000001)) {
|
||||
$new_weight = $osd->{'reweight'} - 0.01;
|
||||
printf ("osd.%s is %02.6f%% full, reweight it %01.6f -> %01.6f\n", $osd->{'id'}, $osd->{'utilization'}, $osd->{'reweight'}, $new_weight);
|
||||
}
|
||||
|
||||
if ($osd->{'utilization'} >= 85.000001) {
|
||||
$new_weight = $osd->{'reweight'} - 0.02;
|
||||
printf ("osd.%s is %02.6f%% full, reweight it %01.6f -> %01.6f\n", $osd->{'id'}, $osd->{'utilization'}, $osd->{'reweight'}, $new_weight);
|
||||
}
|
||||
|
||||
if (defined($ARGV[1])) {
|
||||
help () if ($ARGV[1] ne '--dry');
|
||||
} else {
|
||||
system('ceph', 'osd', 'reweght', sprintf("%d", $osd->{'id'}), sprintf("%f", $new_weight));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
help();
|
||||
}
|
||||
|
||||
sub help() {
|
||||
print <<MSG;
|
||||
Usage:
|
||||
$0 prints this help
|
||||
$0 --do-it just reweghts osds
|
||||
$0 --do-it --dry will print what should be done
|
||||
|
||||
it reweghts 80% full osds by 0.01 and 85%+ full osds by 0.02
|
||||
|
||||
Note: you should wait until rebalance ends in order to understand state of
|
||||
cluster utilization.
|
||||
MSG
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
exit 0;
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ugly udev hook to toggle display configuration
|
||||
|
||||
|
||||
# grab the display and xauthority cookie
|
||||
export DISPLAY=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $2}')
|
||||
X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $1}')
|
||||
export XAUTHORITY=/home/$X_USER/.Xauthority
|
||||
|
||||
# get the status of the external display
|
||||
status=$(< /sys/class/drm/card0-HDMI-A-1/status)
|
||||
case $status in
|
||||
disconnected)
|
||||
su $X_USER -c 'xrandr --output HDMI-1 --off'
|
||||
logger "disabled hdmi output for $X_USER"
|
||||
;;
|
||||
connected)
|
||||
while [[ $(< /sys/class/drm/card0-HDMI-A-1/enabled) -ne 'enabled' ]]; do
|
||||
su $X_USER -c 'xrandr --output HDMI-1 --auto'
|
||||
sleep 1;
|
||||
done
|
||||
|
||||
su $X_USER -c 'xrandr --output HDMI-1 --auto --right-of eDP-1'
|
||||
logger "enabled hdmi output for $X_USER"
|
||||
;;
|
||||
esac
|
||||
230
i3status-mt
230
i3status-mt
@@ -1,230 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
# vim: set ai et ts=8 sw=8 sts=8 :
|
||||
|
||||
# set username
|
||||
# set uptime
|
||||
# set time
|
||||
# set xtitle of focused window
|
||||
# set list of windows for current tag
|
||||
# set list of windows for all tags
|
||||
# set la
|
||||
# set current language
|
||||
# set battery charge
|
||||
|
||||
# main loop impl. :
|
||||
# save cur. str and compare it with prev. if it differs - update
|
||||
|
||||
# proposed: 3 types of loop:
|
||||
# slow loop for batt charge, la
|
||||
# 1 second loop for time, uptime
|
||||
# main (fast) loop for window name, language
|
||||
|
||||
use Fcntl;
|
||||
use Encode qw(decode encode);
|
||||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
sub gettimestr();
|
||||
sub getfocusedwidowtitlestr();
|
||||
sub getlangstr();
|
||||
sub getuptimestr();
|
||||
sub getlastr();
|
||||
sub getbatterychargestr1();
|
||||
sub getbatterychargestr2();
|
||||
|
||||
sub slow_thread();
|
||||
sub onesec_thread();
|
||||
|
||||
my $pstr = '';
|
||||
|
||||
my $charge :shared;
|
||||
my $la :shared;
|
||||
my $uptime :shared;
|
||||
my $time :shared;
|
||||
|
||||
threads->create('slow_thread');
|
||||
threads->create('onesec_thread');
|
||||
|
||||
sleep 1;
|
||||
|
||||
while(1){
|
||||
$str = '';
|
||||
$str .= getfocusedwidowtitlestr();
|
||||
$str .= "$ENV{'USER'}";
|
||||
$str .= getlangstr();
|
||||
$str .= $uptime;
|
||||
$str .= $la;
|
||||
$str .= $charge;
|
||||
$str .= $time;
|
||||
|
||||
if($pstr ne $str){
|
||||
syswrite STDOUT, "$str\n";
|
||||
$pstr = $str;
|
||||
}
|
||||
|
||||
# sleep for 0.333 second;
|
||||
select(undef, undef, undef, 0.333);
|
||||
}
|
||||
|
||||
|
||||
sub slow_thread(){
|
||||
threads->detach();
|
||||
|
||||
while(1){
|
||||
$charge = getbatterychargestr2();
|
||||
$la = getlastr();
|
||||
sleep 300;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub onesec_thread(){
|
||||
threads->detach();
|
||||
|
||||
while(1){
|
||||
$uptime = getuptimestr();
|
||||
$time = gettimestr();
|
||||
# as we report time with precision of 1 minute, update 1/60 seconds
|
||||
sleep 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub gettimestr(){
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = (localtime)[0,1,2,3,4,5,6];
|
||||
my @months = ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек');
|
||||
my @wdays = ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб');
|
||||
$year = $year + 1900;
|
||||
|
||||
my $str .= sprintf(" | %s, %s %s %s %02s:%02s ", $wdays[$wday], $mday, $months[$mon], $year, $hour, $min);
|
||||
|
||||
undef $sec; undef $min; undef $hour; undef $mday; undef $mon; undef $year; undef $wday;
|
||||
@months = -1; undef @months;
|
||||
@wdays = -1; undef @wdays;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
sub getfocusedwidowtitlestr() {
|
||||
# making some utf-8 mumbo-jumbo :(
|
||||
my $str;
|
||||
utf8::upgrade($str);
|
||||
|
||||
if (-x '/usr/bin/xdotool'){
|
||||
$str = `xdotool getactivewindow getwindowname`;
|
||||
}elsif (-x '/usr/bin/xprop'){
|
||||
$str = (split( /=/, `xprop -id \$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME`))[1];
|
||||
chop $str; chop $str; $str = reverse $str; chop $str; chop $str; $str = reverse $str;
|
||||
}
|
||||
|
||||
chomp($str);
|
||||
|
||||
$str = encode('UTF-8', decode('UTF-8', $str));
|
||||
|
||||
if (length($str) != 0) {
|
||||
my $stripped = undef;
|
||||
|
||||
if (length($str) > 40){
|
||||
$str = substr($str, -38, 38);
|
||||
$str = encode('UTF-8', decode('UTF-8', $str));
|
||||
$str = ' ... ' . $str;
|
||||
}
|
||||
|
||||
$str = '['. $str .'] | ';
|
||||
}else{
|
||||
$str = '| ';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
sub getuptimestr(){
|
||||
if(tell(UPTIME) == -1){ open UPTIME, "/proc/uptime"; };
|
||||
|
||||
$u = <UPTIME>;
|
||||
seek UPTIME, SEEK_SET, 0;
|
||||
$u = (split(/ /, $u, 2))[0];
|
||||
$days = int($u / 86400); # 86400 = 1 day
|
||||
$hours = int(($u - (86400 * $days)) / 3600); # 3600 = 1 hour
|
||||
$minutes = int(($u - (86400 * $days) - (3600 * $hours)) / 60);
|
||||
$seconds = int($u - (86400 * $days) - (3600 * $hours) - (60 * $minutes));
|
||||
my $str = sprintf(" | up:[%sd,%02sh,%02sm]", $days, $hours, $minutes);
|
||||
|
||||
undef $u; undef $days; undef $hours; undef $minutes; undef $seconds;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
sub getlastr(){
|
||||
if(tell(LA) == -1){ open LA, "/proc/loadavg"; };
|
||||
|
||||
my $la = <LA>;
|
||||
seek LA, SEEK_SET, 0;
|
||||
$la = (split(/ /, $la, 2))[0];
|
||||
|
||||
return (" | LA:[$la]");
|
||||
}
|
||||
|
||||
|
||||
sub getbatterychargestr1(){
|
||||
my $str = '';
|
||||
|
||||
if (-f "/sys/class/power_supply/BAT0/present"){
|
||||
open A, "/sys/class/power_supply/BAT0/present";
|
||||
$P = <A>;
|
||||
close A;
|
||||
chomp($P);
|
||||
|
||||
if($P eq '1'){
|
||||
open A, "/sys/class/power_supply/BAT0/charge_full";
|
||||
my $full_charge = <A>; chomp($full_charge); close A;
|
||||
open A, "/sys/class/power_supply/BAT0/charge_now";
|
||||
my $current_charge = <A>; chomp($current_charge); close A;
|
||||
$str .= sprintf(" | Bat:[%03d%%]", int(($current_charge / $full_charge) * 100) );
|
||||
undef $current_charge; undef $full_charge;
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
sub getbatterychargestr2(){
|
||||
my $str .= " | Power:[";
|
||||
open AC,"/sys/class/power_supply/ADP1/online";
|
||||
|
||||
if(<AC> == 1){
|
||||
$str .= "AC";
|
||||
}else{
|
||||
$str .= "DC";
|
||||
}
|
||||
|
||||
close AC; # display % charge only if possible
|
||||
if (open DC,"/sys/class/power_supply/BAT0/capacity"){
|
||||
$str .= ' '. <DC>;
|
||||
close DC;
|
||||
chomp $str;
|
||||
$str .= '%';
|
||||
}
|
||||
$str .= "]";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
sub getlangstr(){
|
||||
my $str .= " | Lang:[";
|
||||
|
||||
if(`xset -q` =~ /Group 2: on /o){
|
||||
$str .= "RU]";
|
||||
}else{
|
||||
$str .= "EN]";
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
291
i3status-mt-json
291
i3status-mt-json
@@ -1,291 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
# vim: set ai et ts=8 sw=8 sts=8 ft=perl :
|
||||
|
||||
# set username
|
||||
# set uptime
|
||||
# set time
|
||||
# set xtitle of focused window
|
||||
# set list of windows for current tag
|
||||
# set list of windows for all tags
|
||||
# set la
|
||||
# set current language
|
||||
# set battery charge
|
||||
|
||||
# main loop impl. :
|
||||
# save cur. str and compare it with prev. if it differs - update
|
||||
|
||||
# proposed: 3 types of loop:
|
||||
# slow loop for batt charge, la
|
||||
# 1 second loop for time, uptime
|
||||
# main (fast) loop for window name, language
|
||||
|
||||
use Fcntl;
|
||||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
sub gettimestr();
|
||||
sub getfocusedwidowtitlestr();
|
||||
sub getlangstr();
|
||||
sub getuptimestr();
|
||||
sub getlastr();
|
||||
sub getbatterychargestr1();
|
||||
sub getbatterychargestr2();
|
||||
sub getinboxstat();
|
||||
sub getproblemsstat();
|
||||
|
||||
sub slow_thread();
|
||||
sub onesec_thread();
|
||||
|
||||
my $pstr = '';
|
||||
|
||||
my $charge :shared;
|
||||
my $la :shared;
|
||||
my $uptime :shared;
|
||||
my $time :shared;
|
||||
my $inbox :shared;
|
||||
my $problems :shared;
|
||||
|
||||
my $default_color = '#3e78fd';
|
||||
|
||||
threads->create('slow_thread');
|
||||
threads->create('onesec_thread');
|
||||
|
||||
sleep 1;
|
||||
|
||||
syswrite STDOUT, "{\"version\":1, \"click_events\": true}\n";
|
||||
syswrite STDOUT, "[\n[],\n";
|
||||
while(1){
|
||||
$str = "[ ";
|
||||
# $str .= getfocusedwidowtitlestr() . ",";
|
||||
$str .= getfocusedwidowtitlestr() . ", ";
|
||||
$str .= sprintf("{ \"name\" : \"username\", \"full_text\" : \"%s\", \"color\" : \"%s\" }", $ENV{'USER'}, $default_color) . ", ";
|
||||
$str .= getlangstr() . ", ";
|
||||
$str .= $uptime . ", ";
|
||||
$str .= $la . ", ";
|
||||
$str .= $charge . ", ";
|
||||
$str .= $time;
|
||||
$str .= " ],\n";
|
||||
if($pstr ne $str){
|
||||
syswrite STDOUT, "$str\n";
|
||||
$pstr = $str;
|
||||
}
|
||||
|
||||
# sleep for 0.333 second;
|
||||
select(undef, undef, undef, 0.333);
|
||||
}
|
||||
|
||||
sub slow_thread(){
|
||||
threads->detach();
|
||||
|
||||
while(1){
|
||||
$charge = getbatterychargestr2();
|
||||
$la = getlastr();
|
||||
sleep 300;
|
||||
}
|
||||
}
|
||||
|
||||
sub onesec_thread(){
|
||||
threads->detach();
|
||||
|
||||
while(1){
|
||||
$uptime = getuptimestr();
|
||||
$time = gettimestr();
|
||||
$inbox = getinboxstat();
|
||||
$problems = getproblemsstat();
|
||||
# as we report time with precision of 1 minute, update 1/60 seconds
|
||||
sleep 60;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
sub gettimestr(){
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = (localtime)[0,1,2,3,4,5,6];
|
||||
my @months = ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек');
|
||||
my @wdays = ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб');
|
||||
$year = $year + 1900;
|
||||
|
||||
my $str .= sprintf("{ \"name\" : \"time\", \"full_text\" : \"%s, %s %s %s %02s:%02s\", \"color\" : \"%s\" }", $wdays[$wday], $mday, $months[$mon], $year, $hour, $min, $default_color);
|
||||
|
||||
undef $sec; undef $min; undef $hour; undef $mday; undef $mon; undef $year; undef $wday;
|
||||
@months = -1; undef @months;
|
||||
@wdays = -1; undef @wdays;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getfocusedwidowtitlestr(){
|
||||
my $str;
|
||||
|
||||
if (-x '/usr/bin/xdotool'){
|
||||
$str = `xdotool getactivewindow getwindowname`;
|
||||
}elsif (-x '/usr/bin/xprop'){
|
||||
$str = (split( /=/, `xprop -id \$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME`))[1];
|
||||
chop $str; chop $str; $str = reverse $str; chop $str; chop $str; $str = reverse $str;
|
||||
}
|
||||
|
||||
chomp($str);
|
||||
$string =~ s/[\"|\{|\}|\'|,]/_/g;
|
||||
|
||||
if (length($string) > 64){
|
||||
$string = substr($string, 0, 64);
|
||||
}
|
||||
|
||||
$str = sprintf ("{ \"name\" : \"title\", \"full_text\" : \"%s\", \"color\" : \"%s\" }", $str, $default_color);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getuptimestr(){
|
||||
if(tell(UPTIME) == -1){ open UPTIME, "/proc/uptime"; };
|
||||
|
||||
$u = <UPTIME>;
|
||||
seek UPTIME, SEEK_SET, 0;
|
||||
$u = (split(/ /, $u, 2))[0];
|
||||
$days = int($u / 86400); # 86400 = 1 day
|
||||
$hours = int(($u - (86400 * $days)) / 3600); # 3600 = 1 hour
|
||||
$minutes = int(($u - (86400 * $days) - (3600 * $hours)) / 60);
|
||||
$seconds = int($u - (86400 * $days) - (3600 * $hours) - (60 * $minutes));
|
||||
my $str = sprintf("{ \"name\" : \"uptime\", \"full_text\" : \"UP: %sd,%02sh,%02sm\", \"color\" : \"%s\" }", $days, $hours, $minutes, $default_color);
|
||||
|
||||
undef $u; undef $days; undef $hours; undef $minutes; undef $seconds;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getlastr(){
|
||||
if(tell(LA) == -1){ open LA, "/proc/loadavg"; };
|
||||
|
||||
my $la = <LA>;
|
||||
seek LA, SEEK_SET, 0;
|
||||
$la = (split(/ /, $la, 2))[0];
|
||||
$la = sprintf("{ \"name\" : \"la\", \"full_text\" : \"LA: %s\", \"color\" : \"%s\" }", $la, $default_color);
|
||||
|
||||
return $la;
|
||||
}
|
||||
|
||||
sub getbatterychargestr1(){
|
||||
my $str = '';
|
||||
|
||||
if (-f "/sys/class/power_supply/BAT0/present"){
|
||||
open A, "/sys/class/power_supply/BAT0/present";
|
||||
$P = <A>;
|
||||
close A;
|
||||
chomp($P);
|
||||
|
||||
if($P eq '1'){
|
||||
open A, "/sys/class/power_supply/BAT0/energy_full";
|
||||
my $full_charge = <A>; chomp($full_charge); close A;
|
||||
open A, "/sys/class/power_supply/BAT0/energy_now";
|
||||
my $current_charge = <A>; chomp($current_charge); close A;
|
||||
$str .= sprintf("Bat:%03d%%", int(($current_charge / $full_charge) * 100) );
|
||||
undef $current_charge; undef $full_charge;
|
||||
}
|
||||
}
|
||||
|
||||
$str = sprintf("{ \"name\" : \"powersource\", \"full_text\" : \"%s\", \"color\" : \"#555555\" }", $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getbatterychargestr2(){
|
||||
my $str = '';
|
||||
my $color = $default_color;
|
||||
open AC,"/sys/class/power_supply/ADP1/online";
|
||||
|
||||
if(<AC> == 1){
|
||||
$str .= "AC";
|
||||
}else{
|
||||
$str .= "DC";
|
||||
}
|
||||
|
||||
close AC; # display % charge only if possible
|
||||
if (open DC,"/sys/class/power_supply/BAT0/capacity"){
|
||||
my $charge = <DC>;
|
||||
close DC;
|
||||
chomp($charge);
|
||||
|
||||
if ($charge < 10){
|
||||
$color = '#800000';
|
||||
} elsif (($charge >= 10) and ($charge < 25)){
|
||||
$color = '#ffa500';
|
||||
} elsif (($charge >= 25) and ($charge < 80)){
|
||||
$color = '#008000';
|
||||
} else {
|
||||
$color = '#0000a0';
|
||||
}
|
||||
|
||||
$str .= " $charge";
|
||||
}
|
||||
|
||||
$str = sprintf("{ \"name\" : \"powersource\", \"full_text\" : \"Power: %s%%\", \"color\" : \"%s\" }", $str, $color);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getlangstr(){
|
||||
my $str .= "Lang: ";
|
||||
|
||||
if(`xset -q` =~ /Group 2: on /o){
|
||||
$str .= "RU";
|
||||
}else{
|
||||
$str .= "EN";
|
||||
}
|
||||
|
||||
$str = sprintf("{ \"name\":\"lang\", \"full_text\" : \"%s\", \"color\" : \"%s\" }", $str, $default_color);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getinboxstat(){
|
||||
if((-d "$ENV{'HOME'}/Maildir/INBOX/cur") and (-d "$ENV{'HOME'}/Maildir/INBOX/new")){
|
||||
my $inboxtotal = 0;
|
||||
my $inboxunread = 0;
|
||||
my $inboxunseen = 0;
|
||||
opendir DIR, "$ENV{'HOME'}/Maildir/INBOX/cur";
|
||||
foreach (readdir(DIR)){
|
||||
next if ($_ eq '.');
|
||||
next if ($_ eq '..');
|
||||
unless ($_ =~ /,F?R?S$/){ $inboxunread++; }
|
||||
$inboxtotal++;
|
||||
}
|
||||
closedir DIR;
|
||||
opendir DIR, "$ENV{'HOME'}/Maildir/INBOX/new";
|
||||
foreach (readdir(DIR)){
|
||||
next if ($_ eq '.');
|
||||
next if ($_ eq '..');
|
||||
unless ($_ =~ /,F?R?S$/){ $inboxunread++; $inboxunseen++; }
|
||||
$inboxtotal++;
|
||||
}
|
||||
closedir DIR;
|
||||
return (sprintf("i %d/%d/%d", $inboxunseen, $inboxunread, $inboxtotal));
|
||||
}
|
||||
return('');
|
||||
}
|
||||
|
||||
sub getproblemsstat(){
|
||||
if((-d "$ENV{'HOME'}/Maildir/Problems/cur") and (-d "$ENV{'HOME'}/Maildir/Problems/new")){
|
||||
my $inboxtotal = 0;
|
||||
my $inboxunread = 0;
|
||||
my $inboxunseen = 0;
|
||||
opendir DIR, "$ENV{'HOME'}/Maildir/Problems/cur";
|
||||
foreach (readdir(DIR)){
|
||||
next if ($_ eq '.');
|
||||
next if ($_ eq '..');
|
||||
unless ($_ =~ /,F?R?S$/){ $inboxunread++; }
|
||||
$inboxtotal++;
|
||||
}
|
||||
closedir DIR;
|
||||
opendir DIR, "$ENV{'HOME'}/Maildir/Problems/new";
|
||||
foreach (readdir(DIR)){
|
||||
next if ($_ eq '.');
|
||||
next if ($_ eq '..');
|
||||
unless ($_ =~ /,F?R?S$/){ $inboxunread++; $inboxunseen++; }
|
||||
$inboxtotal++;
|
||||
}
|
||||
closedir DIR;
|
||||
return (sprintf("p %d/%d/%d", $inboxunseen, $inboxunread, $inboxtotal));
|
||||
}
|
||||
return('');
|
||||
}
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use Fcntl;
|
||||
use POSIX;
|
||||
|
||||
use JSON::PP;
|
||||
use utf8;
|
||||
use Encode;
|
||||
use open qw(:std :utf8);
|
||||
|
||||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
sub gettimestr();
|
||||
sub getfocusedwidowtitlestr();
|
||||
sub getuptimestr();
|
||||
sub getlastr();
|
||||
sub getbatterychargestr1();
|
||||
sub getbatterychargestr2();
|
||||
|
||||
sub slow_thread();
|
||||
sub onesec_thread();
|
||||
sub reader();
|
||||
sub launcher($);
|
||||
|
||||
my @charge :shared;
|
||||
my $la :shared;
|
||||
my $uptime :shared;
|
||||
my $time :shared;
|
||||
my $shoot :shared = 1;
|
||||
|
||||
my $default_color = '#5c5b5a';
|
||||
my $blue_color = '#3e78fd';
|
||||
|
||||
my @name = qw /
|
||||
ff vv ch con tel pid hc mp db kee
|
||||
title username uptime la powersource time /;
|
||||
|
||||
my @align = qw /
|
||||
left left left left left left left left left left
|
||||
center right right right right right /;
|
||||
|
||||
my $a;
|
||||
my %name_index;
|
||||
|
||||
for (my $i = 0; $i < @name; $i++) {
|
||||
$name_index{$name[$i]} = $i;
|
||||
$a->[$i]->{'name'} = $name[$i];
|
||||
|
||||
if ($name[$i] eq 'username') {
|
||||
$a->[$i]->{'full_text'} = $ENV{'USER'};
|
||||
} elsif ($name[$i] eq 'title') {
|
||||
$a->[$i]->{'min_width'} = ' ';
|
||||
} else {
|
||||
$a->[$i]->{'full_text'} = $name[$i];
|
||||
}
|
||||
|
||||
$a->[$i]->{'color'} = $blue_color;
|
||||
|
||||
if ($align[$i] eq 'left') {
|
||||
$align[$i] = "center";
|
||||
$a->[$i]->{'color'} = $default_color;
|
||||
$a->[$i]->{'separator_block_width'} = 1;
|
||||
$a->[$i]->{'separator'} = JSON::PP::false;
|
||||
$a->[$i]->{'border'} = '#3dbaf4';
|
||||
$a->[$i]->{'min_width'} = sprintf(' %s ', $name[$i]);
|
||||
}
|
||||
|
||||
$a->[$i]->{'align'} = $align[$i];
|
||||
}
|
||||
|
||||
my $title;
|
||||
my $prev_title = '';
|
||||
|
||||
threads->create('slow_thread');
|
||||
threads->create('onesec_thread');
|
||||
threads->create('reader');
|
||||
|
||||
sleep 1;
|
||||
|
||||
syswrite STDOUT, "{\"version\":1, \"click_events\": true}\n";
|
||||
syswrite STDOUT, "[\n[],\n";
|
||||
|
||||
while (1) {
|
||||
my $in = '';
|
||||
|
||||
$title = getfocusedwidowtitlestr();
|
||||
|
||||
if ($title ne $prev_title) {
|
||||
$shoot = 1;
|
||||
$prev_title = $title;
|
||||
}
|
||||
|
||||
if ($shoot == 1) {
|
||||
$a->[$name_index{'title'}]->{'full_text'} = $title;
|
||||
$a->[$name_index{'uptime'}]->{'full_text'} = $uptime;
|
||||
$a->[$name_index{'la'}]->{'full_text'} = $la;
|
||||
$a->[$name_index{'powersource'}]->{'full_text'} = $charge[0];
|
||||
$a->[$name_index{'powersource'}]->{'color'} = $charge[1];
|
||||
$a->[$name_index{'time'}]->{'full_text'} = $time;
|
||||
my $json = JSON::PP->new;
|
||||
$json = $json->ascii(0);
|
||||
$json = $json->utf8(0);
|
||||
$json = $json->allow_unknown (0);
|
||||
$json = $json->canonical(1);
|
||||
$json = $json->space_before(0);
|
||||
$json = $json->space_after(0);
|
||||
$json = $json->indent(0);
|
||||
my $str = $json->encode($a);
|
||||
undef $json;
|
||||
syswrite STDOUT, $str . ",\n";
|
||||
undef $str;
|
||||
$shoot = 0;
|
||||
}
|
||||
|
||||
# sleep for 0.333 second;
|
||||
select(undef, undef, undef, 0.333);
|
||||
}
|
||||
|
||||
sub slow_thread() {
|
||||
threads->detach();
|
||||
my @prev_charge = ('','');
|
||||
my @current_charge;
|
||||
my $prev_la = '';
|
||||
my $current_la;
|
||||
|
||||
while (1) {
|
||||
@current_charge = getbatterychargestr2();
|
||||
|
||||
if ($current_charge[0] ne $prev_charge[0]) {
|
||||
$shoot = 1;
|
||||
@prev_charge = @current_charge;
|
||||
@charge = @current_charge;
|
||||
}
|
||||
|
||||
$current_la = getlastr();
|
||||
|
||||
if ($current_la ne $prev_la) {
|
||||
$shoot = 1;
|
||||
$prev_la = $current_la;
|
||||
$la = $current_la;
|
||||
}
|
||||
|
||||
sleep 300;
|
||||
}
|
||||
}
|
||||
|
||||
sub onesec_thread() {
|
||||
threads->detach();
|
||||
|
||||
while (1) {
|
||||
$uptime = getuptimestr();
|
||||
$time = gettimestr();
|
||||
# as we report time with precision of 1 minute, update 1/60 seconds
|
||||
$shoot = 1;
|
||||
sleep 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub gettimestr() {
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = (localtime)[0,1,2,3,4,5,6];
|
||||
my @months = ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек');
|
||||
my @wdays = ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб');
|
||||
$year = $year + 1900;
|
||||
|
||||
my $z = sprintf("%s, %s %s %s %02s:%02s", $wdays[$wday], $mday, $months[$mon], $year, $hour, $min),
|
||||
|
||||
undef $sec; undef $min; undef $hour; undef $mday; undef $mon; undef $year; undef $wday;
|
||||
@months = -1; undef @months;
|
||||
@wdays = -1; undef @wdays;
|
||||
|
||||
return $z;
|
||||
}
|
||||
|
||||
sub getfocusedwidowtitlestr() {
|
||||
my $str;
|
||||
|
||||
if (-x '/usr/bin/xdotool') {
|
||||
$str = `xdotool getactivewindow getwindowname`;
|
||||
} elsif (-x '/usr/bin/xprop') {
|
||||
$str = (split( /=/, `xprop -id \$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME`))[1];
|
||||
chop $str; chop $str; $str = reverse $str; chop $str; chop $str; $str = reverse $str;
|
||||
}
|
||||
|
||||
chomp($str);
|
||||
$str =~ s/[\"|\{|\}|\'|,|\(|\)|\[|\]]/ /g;
|
||||
|
||||
if (int(length($str)) > 24) {
|
||||
$str = substr($str, 0, 25);
|
||||
} elsif (int(length($str)) < 1) {
|
||||
$str = ' ';
|
||||
}
|
||||
|
||||
# not sure about utf-8-ness of this chunk, so try to check it
|
||||
$str = eval { decode('UTF-8', $str, Encode::FB_CROAK) } // ' ';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getuptimestr() {
|
||||
if(tell(UPTIME) == -1){ open UPTIME, "/proc/uptime"; };
|
||||
|
||||
my $u = <UPTIME>;
|
||||
seek UPTIME, SEEK_SET, 0;
|
||||
$u = (split(/ /, $u, 2))[0];
|
||||
my $days = int($u / 86400); # 86400 = 1 day
|
||||
my $hours = int(($u - (86400 * $days)) / 3600); # 3600 = 1 hour
|
||||
my $minutes = int(($u - (86400 * $days) - (3600 * $hours)) / 60);
|
||||
my $seconds = int($u - (86400 * $days) - (3600 * $hours) - (60 * $minutes));
|
||||
|
||||
$u = sprintf("UP: %sd,%02sh,%02sm", $days, $hours, $minutes);
|
||||
|
||||
undef $days; undef $hours; undef $minutes; undef $seconds;
|
||||
|
||||
return $u;
|
||||
}
|
||||
|
||||
sub getlastr() {
|
||||
if(tell(LA) == -1){ open LA, "/proc/loadavg"; };
|
||||
|
||||
my $la = <LA>;
|
||||
seek LA, SEEK_SET, 0;
|
||||
$la = (split(/ /, $la, 2))[0];
|
||||
|
||||
return $la;
|
||||
}
|
||||
|
||||
sub getbatterychargestr1() {
|
||||
my $str = '';
|
||||
|
||||
if (-f "/sys/class/power_supply/BAT0/present"){
|
||||
open A, "/sys/class/power_supply/BAT0/present";
|
||||
my $P = <A>;
|
||||
close A;
|
||||
chomp($P);
|
||||
|
||||
if($P eq '1') {
|
||||
open A, "/sys/class/power_supply/BAT0/energy_full";
|
||||
my $full_charge = <A>; chomp($full_charge); close A;
|
||||
open A, "/sys/class/power_supply/BAT0/energy_now";
|
||||
my $current_charge = <A>; chomp($current_charge); close A;
|
||||
$str .= sprintf("Bat:%03d%%", int(($current_charge / $full_charge) * 100) );
|
||||
undef $current_charge; undef $full_charge;
|
||||
}
|
||||
|
||||
undef $P;
|
||||
}
|
||||
|
||||
my @z = ($str, '#555555');
|
||||
|
||||
return @z;
|
||||
}
|
||||
|
||||
sub getbatterychargestr2() {
|
||||
my $str = '';
|
||||
my $color = $default_color;
|
||||
my $file;
|
||||
|
||||
if (-f "/sys/class/power_supply/ADP1/online") {
|
||||
$file = "/sys/class/power_supply/ADP1/online";
|
||||
} elsif ("/sys/class/power_supply/AC/online") {
|
||||
$file = "/sys/class/power_supply/AC/online";
|
||||
} else {
|
||||
return ('??', '??%');
|
||||
}
|
||||
|
||||
open AC, $file or return ('??', '??%');
|
||||
|
||||
if (<AC> == 1) {
|
||||
$str .= "AC";
|
||||
} else {
|
||||
$str .= "DC";
|
||||
}
|
||||
|
||||
close AC; # display % charge only if possible
|
||||
if (open DC,"/sys/class/power_supply/BAT0/capacity") {
|
||||
my $charge = <DC>;
|
||||
close DC;
|
||||
chomp($charge);
|
||||
|
||||
if ($charge < 10){
|
||||
$color = '#800000';
|
||||
} elsif (($charge >= 10) and ($charge < 25)) {
|
||||
$color = '#ffa500';
|
||||
} elsif (($charge >= 25) and ($charge < 80)) {
|
||||
$color = '#008000';
|
||||
} else {
|
||||
$color = '#0000a0';
|
||||
}
|
||||
|
||||
$str .= " $charge";
|
||||
}
|
||||
|
||||
my @z = (sprintf("Power: %s%%", $str), $color);
|
||||
|
||||
return @z;
|
||||
}
|
||||
|
||||
sub reader() {
|
||||
threads->detach();
|
||||
my $str = '';
|
||||
my $j;
|
||||
|
||||
while (<STDIN>) {
|
||||
$str = $_;
|
||||
|
||||
if (substr($str, 0, 1) ne '{') {
|
||||
$str = substr($str, 1);
|
||||
}
|
||||
|
||||
chomp($str);
|
||||
next if ((length($str) < 2) or (substr($str, -1, 1) ne '}'));
|
||||
|
||||
$j = decode_json($str);
|
||||
if ($j->{'button'} eq '1') {
|
||||
if ($j->{'name'} eq 'ff') { threads->create('launcher', '/usr/bin/firefox'); }
|
||||
if ($j->{'name'} eq 'vv') { threads->create('launcher', '/usr/local/bin/vivaldi'); }
|
||||
if ($j->{'name'} eq 'ch') { threads->create('launcher', '/usr/bin/chromium'); }
|
||||
if ($j->{'name'} eq 'con') { threads->create('launcher', '/usr/bin/urxvt'); }
|
||||
if ($j->{'name'} eq 'tel') { threads->create('launcher', '/home/eleksir/.local/bin/Telegram'); }
|
||||
if ($j->{'name'} eq 'pid') { threads->create('launcher', '/usr/bin/pidgin'); }
|
||||
if ($j->{'name'} eq 'hc') { threads->create('launcher', '/usr/bin/hexchat'); }
|
||||
if ($j->{'name'} eq 'mp') { threads->create('launcher', '/usr/bin/mousepad'); }
|
||||
if ($j->{'name'} eq 'db') { threads->create('launcher', '/usr/bin/deadbeef'); }
|
||||
if ($j->{'name'} eq 'kee') { threads->create('launcher', '/home/eleksir/.local/bin/kee'); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub launcher($) {
|
||||
my $prog = shift;
|
||||
threads->detach();
|
||||
|
||||
if (fork() == 0) {
|
||||
exec ($prog);
|
||||
}
|
||||
}
|
||||
|
||||
# vim: set ai tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab ft=perl : #
|
||||
168
i3status-st
168
i3status-st
@@ -1,168 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
# set username
|
||||
# set uptime
|
||||
# set time
|
||||
# set xtitle of focused window
|
||||
# set list of windows for current tag
|
||||
# set list of windows for all tags
|
||||
# set la
|
||||
# set current language
|
||||
# set battery charge
|
||||
|
||||
# main loop impl. :
|
||||
# save cur. str and compare it with prev. if it differs - update
|
||||
|
||||
# proposed: 3 types of loop:
|
||||
# slow loop for batt charge, la
|
||||
# 1 second loop for time, uptime
|
||||
# main (fast) loop for window name, language
|
||||
|
||||
use Fcntl;
|
||||
|
||||
sub gettimestr();
|
||||
sub getfocusedwidowtitlestr();
|
||||
sub getlangstr();
|
||||
sub getuptimestr();
|
||||
sub getlastr();
|
||||
sub getbatterychargestr1();
|
||||
sub getbatterychargestr2();
|
||||
|
||||
my $pstr = '';
|
||||
while(1){
|
||||
$str = '';
|
||||
$str .= getfocusedwidowtitlestr();
|
||||
$str .= "$ENV{'USER'}";
|
||||
$str .= getlangstr();
|
||||
$str .= getuptimestr();
|
||||
$str .= getlastr();
|
||||
$str .= getbatterychargestr2();
|
||||
$str .= gettimestr();
|
||||
|
||||
if($pstr ne $str){
|
||||
syswrite STDOUT, "$str\n";
|
||||
$pstr = $str;
|
||||
}
|
||||
|
||||
# sleep for 0.25 second;
|
||||
select(undef, undef, undef, 0.25);
|
||||
}
|
||||
|
||||
|
||||
sub gettimestr(){
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = (localtime)[0,1,2,3,4,5,6];
|
||||
my @months = ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек');
|
||||
my @wdays = ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб');
|
||||
$year = $year + 1900;
|
||||
|
||||
my $str .= sprintf(" | %s, %s %s %s %02s:%02s ", $wdays[$wday], $mday, $months[$mon], $year, $hour, $min);
|
||||
|
||||
undef $sec; undef $min; undef $hour; undef $mday; undef $mon; undef $year; undef $wday;
|
||||
@months = -1; undef @months;
|
||||
@wdays = -1; undef @wdays;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getfocusedwidowtitlestr(){
|
||||
my $str;
|
||||
|
||||
if (-x '/usr/bin/xdotool'){
|
||||
$str = `xdotool getactivewindow getwindowname`;
|
||||
}elsif (-x '/usr/bin/xprop'){
|
||||
$str = (split( /=/, `xprop -id \$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME`))[1];
|
||||
chop $str; chop $str; $str = reverse $str; chop $str; chop $str; $str = reverse $str;
|
||||
}
|
||||
|
||||
chomp($str);
|
||||
|
||||
if (length($str) != 0){
|
||||
$str = '['. $str .'] | ';
|
||||
}else{
|
||||
$str = '| ';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getuptimestr(){
|
||||
if(tell(UPTIME) == -1){ open UPTIME, "/proc/uptime"; };
|
||||
|
||||
$u = <UPTIME>;
|
||||
seek UPTIME, SEEK_SET, 0;
|
||||
$u = (split(/ /, $u, 2))[0];
|
||||
$days = int($u / 86400); # 86400 = 1 day
|
||||
$hours = int(($u - (86400 * $days)) / 3600); # 3600 = 1 hour
|
||||
$minutes = int(($u - (86400 * $days) - (3600 * $hours)) / 60);
|
||||
$seconds = int($u - (86400 * $days) - (3600 * $hours) - (60 * $minutes));
|
||||
my $str = sprintf(" | up:[%sd,%02sh,%02sm]", $days, $hours, $minutes);
|
||||
|
||||
undef $u; undef $days; undef $hours; undef $minutes; undef $seconds;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getlastr(){
|
||||
if(tell(LA) == -1){ open LA, "/proc/loadavg"; };
|
||||
|
||||
my $la = <LA>;
|
||||
seek LA, SEEK_SET, 0;
|
||||
$la = (split(/ /, $la, 2))[0];
|
||||
|
||||
return (" | LA:[$la]");
|
||||
}
|
||||
|
||||
sub getbatterychargestr1(){
|
||||
my $str = '';
|
||||
|
||||
if (-f "/sys/class/power_supply/BAT0/present"){
|
||||
open A, "/sys/class/power_supply/BAT0/present";
|
||||
$P = <A>;
|
||||
close A;
|
||||
chomp($P);
|
||||
|
||||
if($P eq '1'){
|
||||
open A, "/sys/class/power_supply/BAT0/energy_full";
|
||||
my $full_charge = <A>; chomp($full_charge); close A;
|
||||
open A, "/sys/class/power_supply/BAT0/energy_now";
|
||||
my $current_charge = <A>; chomp($current_charge); close A;
|
||||
$str .= sprintf(" | Bat:[%03d%%]", int(($current_charge / $full_charge) * 100) );
|
||||
undef $current_charge; undef $full_charge;
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getbatterychargestr2(){
|
||||
my $str .= " | Power:[";
|
||||
open AC,"/sys/class/power_supply/ADP1/online";
|
||||
|
||||
if(<AC> == 1){
|
||||
$str .= "AC";
|
||||
}else{
|
||||
$str .= "DC";
|
||||
}
|
||||
|
||||
close AC; # display % charge only if possible
|
||||
if (open DC,"/sys/class/power_supply/BAT0/capacity"){
|
||||
$str .= ' '. <DC>;
|
||||
close DC;
|
||||
chomp $str;
|
||||
$str .= '%';
|
||||
}
|
||||
$str .= "]";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub getlangstr(){
|
||||
my $str .= " | Lang:[";
|
||||
|
||||
if(`xset -q` =~ /Group 2: on /o){
|
||||
$str .= "RU]";
|
||||
}else{
|
||||
$str .= "EN]";
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
OSD="$1"
|
||||
|
||||
if [ "$OSD" = "" ]; then
|
||||
echo "OSD ID is not set"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "==> $OSD"
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_op_priority 1'
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_threads 6'
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_max_active 1'
|
||||
ceph tell osd.$OSD injectargs '--osd_max_backfills 1'
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
OSD="$1"
|
||||
|
||||
if [ "$OSD" = "" ]; then
|
||||
echo "OSD ID is not set"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_op_priority 10'
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_threads 10'
|
||||
ceph tell osd.$OSD injectargs '--osd_recovery_max_active 3'
|
||||
ceph tell osd.$OSD injectargs '--osd_max_backfills 10'
|
||||
|
||||
86
rle.pl
86
rle.pl
@@ -1,86 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use Fcntl;
|
||||
|
||||
my $fname = undef;
|
||||
|
||||
if(defined($ARGV[0])){
|
||||
if($ARGV[0] eq "--help"){
|
||||
syswrite STDOUT, "Usage: $0 <filename>\n";
|
||||
syswrite STDOUT, "or pipe data thrugh $0's STDIN to $0 STDOUT\n";
|
||||
exit 0;
|
||||
}
|
||||
$fname = $ARGV[0];
|
||||
}
|
||||
|
||||
my $byte;
|
||||
my $counter = 1;
|
||||
my $block_size = 65536;
|
||||
my $first_remembered_byte = undef;
|
||||
my $second_remembered_byte = undef;
|
||||
|
||||
if (defined($fname)){
|
||||
sysopen(STDIN, $fname, O_RDONLY) or die "Can not open file $fname!\n";
|
||||
sysopen(STDOUT, "$fname.rle", O_WRONLY|O_TRUNC|O_CREAT) or die "Can not open file $fname.rle!\n";
|
||||
}
|
||||
binmode(STDIN);
|
||||
binmode(STDOUT);
|
||||
|
||||
exit 0 if ((sysread(STDIN, $byte, 1)) == 0);
|
||||
|
||||
$first_remembered_byte = $byte;
|
||||
my $output_buf_byte_counter = 0;
|
||||
my $output_buf = '';
|
||||
my $input_buf = '';
|
||||
|
||||
while ( 1 ) {
|
||||
my $read_bytes = sysread(STDIN, $input_buf, $block_size);
|
||||
last if($read_bytes == 0);
|
||||
my $i = 0;
|
||||
for ( $i = 0; $i < $read_bytes; $i++ ) {
|
||||
$byte = substr( $input_buf, $i, 1);
|
||||
last unless(defined($byte));
|
||||
$second_remembered_byte = $first_remembered_byte;
|
||||
$first_remembered_byte = $byte;
|
||||
|
||||
if(($first_remembered_byte eq $second_remembered_byte) and ($counter <= 254)){
|
||||
$counter++;
|
||||
next;
|
||||
}
|
||||
|
||||
if ($output_buf_byte_counter == $block_size){
|
||||
syswrite STDOUT, $output_buf || die "Cannot write output stream!\n";
|
||||
$output_buf = '';
|
||||
$output_buf_byte_counter = 0;
|
||||
}else{
|
||||
$output_buf_byte_counter++;
|
||||
}
|
||||
|
||||
$output_buf .= chr($counter) . $second_remembered_byte;
|
||||
$second_remembered_byte = $first_remembered_byte;
|
||||
$counter = 1;
|
||||
}
|
||||
undef $i;
|
||||
undef $read_bytes;
|
||||
}
|
||||
close(STDIN);
|
||||
# 0-byte string
|
||||
exit 0 unless (defined($first_remembered_byte));
|
||||
# 1-byte string
|
||||
unless(defined($second_remembered_byte)){
|
||||
$output_buf = chr($counter) . $first_remembered_byte;
|
||||
}else{
|
||||
# 2+ bytes string
|
||||
$output_buf .= chr($counter) . $second_remembered_byte;
|
||||
}
|
||||
syswrite STDOUT, $output_buf || die "Cannot write output stream!\n";
|
||||
close(STDOUT);
|
||||
undef $fname;
|
||||
undef $counter;
|
||||
undef $first_remembered_byte;
|
||||
undef $second_remembered_byte;
|
||||
undef $byte;
|
||||
undef $input_buf;
|
||||
undef $output_buf;
|
||||
69
unrle.pl
69
unrle.pl
@@ -1,69 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use Fcntl;
|
||||
|
||||
my $fname = undef;
|
||||
if(defined($ARGV[0])){
|
||||
if($ARGV[0] eq "--help"){
|
||||
syswrite STDOUT, "Usage: $0 <filename>\n";
|
||||
syswrite STDOUT, "or pipe data thrugh $0's STDIN to $0 STDOUT\n";
|
||||
exit 0;
|
||||
}
|
||||
exit unless ($ARGV[0] =~ /\.rle$/);
|
||||
$fname = $ARGV[0];
|
||||
$fname = substr($fname, 0, -4);
|
||||
}
|
||||
|
||||
my $byte = '';
|
||||
my $dbyte = '';
|
||||
my $block_size = 65536;
|
||||
|
||||
if (defined($fname)){
|
||||
sysopen(STDIN, "$fname.rle", O_RDONLY) or die "Can not open file $fname!\n";
|
||||
sysopen(STDOUT, $fname, O_WRONLY|O_TRUNC|O_CREAT) or die "Can not open file $fname.rle!\n";
|
||||
}
|
||||
binmode(STDIN);
|
||||
binmode(STDOUT);
|
||||
|
||||
my $output_buf_byte_counter = 0;
|
||||
my $output_buf = '';
|
||||
my $input_buf ='';
|
||||
|
||||
while ( 1 ) {
|
||||
my $read_bytes = sysread(STDIN, $input_buf, $block_size);
|
||||
last unless(defined($read_bytes));
|
||||
last if($read_bytes == 0);
|
||||
my $i = 0;
|
||||
for ( $i = 0; $i < $read_bytes; $i++ ) {
|
||||
$dbyte = substr( $input_buf, $i, 1);
|
||||
last unless(defined($dbyte));
|
||||
$i++;
|
||||
$byte = substr( $input_buf, $i, 1);
|
||||
last unless(defined($byte));
|
||||
|
||||
for(my $i = 0; $i < ord($dbyte); $i++){
|
||||
if ($output_buf_byte_counter == $block_size){
|
||||
syswrite STDOUT, $output_buf || die "Cannot write output stream!\n";
|
||||
$output_buf = '';
|
||||
$output_buf_byte_counter = 0;
|
||||
}else{
|
||||
$output_buf_byte_counter++;
|
||||
}
|
||||
$output_buf .= $byte;
|
||||
}
|
||||
}
|
||||
undef $i;
|
||||
undef $read_bytes;
|
||||
}
|
||||
close(STDIN);
|
||||
syswrite STDOUT, $output_buf || die "Cannot write output stream!\n";
|
||||
close(STDOUT);
|
||||
undef $fname;
|
||||
undef $byte;
|
||||
undef $dbyte;
|
||||
undef $block_size;
|
||||
undef $output_buf_byte_counter;
|
||||
undef $output_buf;
|
||||
undef $input_buf;
|
||||
53
xbacklight
53
xbacklight
@@ -1,53 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
my $arg = $ARGV[0];
|
||||
my $step = 10; # measured in percents
|
||||
|
||||
sub fsread($); # read 1-st line from file
|
||||
sub fswrite(@); # write string to file
|
||||
|
||||
my $brightnessfile = "/sys/class/backlight/acpi_video0/brightness";
|
||||
my $maxbrightness = fsread("/sys/class/backlight/acpi_video0/max_brightness");
|
||||
my $currbrightness = fsread($brightnessfile);
|
||||
|
||||
my $a = $maxbrightness / 100;
|
||||
$step = int($step * $a);
|
||||
|
||||
if ( $arg eq "up" ) {
|
||||
if ($currbrightness != $maxbrightness) {
|
||||
my $projectedbrightness = $currbrightness + $step;
|
||||
|
||||
if ($projectedbrightness > $maxbrightness) {
|
||||
$projectedbrightness = $maxbrightness;
|
||||
}
|
||||
|
||||
fswrite($projectedbrightness, $brightnessfile);
|
||||
}
|
||||
} elsif ( $arg eq "down" ) {
|
||||
if ($currbrightness != 0) {
|
||||
my $projectedbrightness = $currbrightness - $step;
|
||||
|
||||
if ($projectedbrightness < 0) {
|
||||
$projectedbrightness = 0;
|
||||
}
|
||||
|
||||
fswrite($projectedbrightness, $brightnessfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub fsread($) {
|
||||
my $fname = shift;
|
||||
open (F, $fname) || die;
|
||||
my $str = <F>;
|
||||
close F;
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub fswrite (@) {
|
||||
my $str = shift;
|
||||
my $fname = shift;
|
||||
open(OF, ">", $fname) || die;
|
||||
print OF $str;
|
||||
close OF;
|
||||
}
|
||||
Reference in New Issue
Block a user