Pages

Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

2015-01-25

Changing themes in Openbox

Skackware64 14.1, Openbox, tint2, conky, feh.
## After using three month almost only Slackware with my slightly-Steampunk theme, I got bored and recalled idea I had - to make script to start X+OB (without display manager) with visual theme I like at that moment, with choice of others.
So I made it happen. In most primitive bash (me - bash-n00b).

# There are one Chooser and four Swapper scripts (as I have currently four themes):
-- 1. Created conf-number file, like:
if [ ! -f obtheme/theme ]; then echo "1" > 'obtheme/theme' ; fi
Get the number:
theme=$(grep -o '[0-9]*' obtheme/theme)
Every time theme is chosen, new number is also written into theme-file.
Those above are for marking previously chosen theme ('if then echo') - and also to let wallpaper-randomizer script to know which one is current.
Then I set some variables;
did 'while' and 'if' between choices, 'read' those 'if'-s, and 'break'-ed with correct answer;
And final 'if-elif' then does
if ... ; then exec "ob-thx.sh"
with chosen theme-swapper script.

-- 2. Swappers
I Collected everything possible to ~/obtheme/xx folders. Like tint-stuff and wallpapers and conf files to be swapped.
For various reasons - there are either symlinks or files overwritten (respectively 'ln -sf' and 'cp').
- Two gtk confs (.gtkrc-2.0 and .config/gtk-3.0/settings.ini = gtk-theme swap);
- my wallpaper randomizer script for that theme (symlink). But - randomizer can also be modified to pick folder according to already existing theme-file number, and then there is no need to swap it | Edit - Done, see the end of the post |;
- .fehbg in ~/ (to pick up another wallpaper-folder);
- rc.xml (OB-theme swap) and autostart in ./config/openbox. Those are also symlinks which point to theme-specific files. Different tint2 and conky confs are opened from swapped auostart;
- and lastly, 'startx'. Or for debugging - as Slackware without display-manager doesn't want to log X-errors - startx 2>.xsession_errors

So, I now start my X either with alias 'sx' - no change, stright to X;
with 'sxz' - which opens up dialog of theme-change;
or, I can pass that and use aliases for swappers: sx1, sx2... .

For anyone fluent with bash - to make such scripts is totally no issue. What takes time is preparing themes - from various conf changes to actual pic-making or theme-tweaking.
But I have to say - it's most satisfactory to see my whole "desktop" instantly and totally changed.

Addon: Here is a simple script for swapping wallpapers inside the current theme wp-folder. Also, keyboard W+1 is mapped in rc.xml as 'swap desktop to first one and run randwp1.sh'.

#!/bin/bash
## very simple random wallpaper picker, through feh or nitrogen
## --------------------------

sp1="/home/user/obtheme/sp/wp"
sf2="/home/user/obtheme/sf/wp"
fan3="/home/user/obtheme/fan/wp"
nat4="/home/user/obtheme/nat/wp"

# theme number variable from theme file
theme=$(grep -o '[0-9]*' /home/user/obtheme/theme)
echo $theme
# directory containing images
DIR=$(if [ $theme -eq 1 ] ; then echo "$sp1" ; 
 elif [ $theme -eq 2 ] ; then echo "$sf2" ; 
 elif [ $theme -eq 3 ] ; then echo "$fan3" ; 
 elif [ $theme -eq 4 ] ; then echo "$nat4" ; 
 fi)
echo "$DIR"
# select a random jpg from the directory
PIC=$(ls $DIR/*.jpg | shuf -n1)
echo "$PIC"

# use nitrogen to set wallpaper
# nitrogen --set-scaled $PIC
# use feh
feh --bg-scale $PIC

exit 

2014-01-07

Second Conky for weather

I went even further with my blingish adventures... Somewhere - related to tweaking conky - I stumbled upon weather forecasts. The thing never interested me much - as I don't consider weather-forecast overly trustworthy activity, and also, I didn't feel need to complicate my Linux-wrestling with trifle things.
Well, it suddenly felt alright now.
Here it comes - very simple conky with very simple layout, and launched from Openbox root-menu.

Essential link. The same info can be found in Cruchbang forum. From here (or there) you can get scripts for automatic download of data and conkyrc-s for presenting it.
I didn't change the script (except the URL of weather-data page), but I changed conkyrc quite heavily. I didn't want pics and special fonts and stuff - I wanted it to be functional, period.

Currently it looks like that, but will be tuned a bit more. Screws are for fitting in with my slightly-steam-punkish theme.

No code comes here for conkyrc, but two very helpful links:

Essentially: go get script and conkyrc. Tune conkyrc. Almost done.
Almost, because maybe of interest is:

- getting weather-conky working and quitting according to need. I, for example, do not want it sillily hanging on desktop - temperatures doesn't change so fast that it should require permanent watch. 
And here comes code for that. Which is borrowed in very big extent from Ubuntu forum.
/bin/wconky.sh - checks for weatherconkys' pidfile existence in folder where it's created. If it's already there, kills conky, if it's not there, starts conky and writes new pidfile.


#!/bin/bash
# ----------
# Simple script to start/kill weather conky

# folder where script is and data will be
basedir="/home/user/accuweather_conky/"
# pidfile name
pidfile="$basedir/weatherconky.pid"
if [ ! -e "$pidfile" ]
   then
   PROG="conky -c /home/user/.conkyrc_acc_int"
   $PROG &
   PID=$!
   echo $PID > "$pidfile"
else
   pidkill=`cat $pidfile`
   echo $pidkill
   kill -9 $pidkill
   rm $pidfile
fi

exit 0

Why this pidfile stuff? Beacuse I already have one conky started from autostart, with nice minimal sys-info, and I don't want that one killed (with killall). And naturally I am too lazy for pgrep and manual kill -9.

I stuck the script into main OB menu, just before 'exit'. No mysteries here: simple 'sh wconky.sh' as the execute command.
And that's it. Click once - get weather, click second time - no weather.
It was mildly interesting thing to fiddle with. It's usefulness is still in doubt.

2013-12-25

Openbox and wallpaper

This topic kinda intriqued me - after relatively easy installs in FB - and I tried out some 10 different versions of scripts I found through links here.

Basically, there is two different kind of change - one that swaps wallpapers after some amount of time, and another that swaps wallpaper together with desktop change.
Scripts are the same but timed ones - obviously - have to have time-trigger.
For this, there also are two options: crontab or Conky (howtos can be found by those same already-mentioned-links).
I definitely do not want spastic desktop, so I went for new-desktop-new-wallpaper kind. This type needs desktop/execute type combo keybind.

The result of my experiments was kinda depressing fail but also ultimately victorious: Most of found scripts didn't work (in my environments), and one that did, went with Nitrogen in Debian, but had to have Feh in Slackware. Problem probably was version of Nitrogen in Slack - an investigative hour wasted nevertheless (no, not really - I got results). But after that I didn't feel anymore like shitting around with new compile, flags, optional dependencies etc.
So it's nitrogen in Debian and Feh in Slack. The friendly scriptlet is like that:
#!/bin/bash
## very simple random wallpaper picker, uses nitrogen or feh
## From Crunchbang forum ##

# directory containing images
DIR="/home/user/picsdir/wpdir"

# select a random jpg from the directory
PIC=$(ls $DIR/*.jpg | shuf -n1)

# use nitrogen to set wallpaper
nitrogen --set-scaled $PIC
# or comment prev nitrogen and outcomment next for feh
#feh --bg-scale $PIC

# and just for terminal fun
echo "$PIC"
exit

To mention - scripts should be executable (chmod +x) and preferably on PATH.
I used two of them, smartly named as randwp1.sh and randwp2.sh, with wpdirs like wp1 and wp2, and keybinded them to W-Left and W-Right.
Two because then I can have two different sets of 'randoms' - like steampunk/fantasy or pr0n1/pr0n2.
Why not to combine action with ready binds of 'GoToDesktop'-type? As much as I tried, this combination didn't work... I was even so crazy that I made 'execute' of GoToDesktop with xdotool (to have 2 similar executes) - and that was success alright... only... then I used xdotool'ed icon on my tint panel, and tint hung totally.
Out it went and in came that, and these entries have to be created:
    <keybind key="W-Left">
    <action name="Desktop">
    <desktop>1</desktop>
    </action>
    <action name="Execute">
    <startupnotify><enabled>true</enabled>
    <name>wp1</name></startupnotify>
    <command>sh /home/user/bin/randwp1.sh</command>
    </action>
    </keybind>       
    <keybind key="W-Right">
    <action name="Desktop">
    <desktop>2</desktop>
    </action>
    <action name="Execute">
    <startupnotify><enabled>true</enabled>
    <name>wp2</name></startupnotify>
    <command>sh /home/user/bin/randwp2.sh</command>
    </action>
    </keybind>

That works for me. No hangs. And jumping back-and-forth, new wallpaper every time!
Oh, and moral: you never know what works; when messing with scripts, bash for beginners is quite must... Me, have to dig in, seems, for less waste of time, less failures.
Merry Christmas.

2013-10-12

Firefox, Grub2, Bash aliases etc

I have been busy - and it seems to continue like that. So, no much time to play around. Here come bits and pieces of things I had to do or didn't but still did. Let's start with Firefoxes:

## The problem: Firefox consumes up to 100% of CPU, and never falls below 20%. To make it even more exciting - this doesn't happen in every session... but when it does, then nothing helps. I started to have this behaviour couple a weeks ago in two different distros - Debian Wheezy and Slackware 14. Common was that they both had Firefox 17.09esr AND had some similar updates to Xorg.
Problem seems to be solved by installing other Firefox version. I went for 24.0. For further thrill - the one I downloaded from Mozillas' server, absolutely refused to start... but one I got from here, was OK and works without turning CPUs fan to jet engine.
How to manually install Firefox - look here.
Edit | If after install there isn't any plugins anymore - like IcedTea - then the easiest way is: create a folder .mozilla/plugins, cd to there and do
ln -s /usr/lib64/IcedTeaPlugin.so (in Slack, or from usr/lib/ in Debian) |

## I finally had enough of Grub2s' auto-generated menuentries. First, there are too many of them (menu-submenu thing, and some kernels doesn't have to be shown at all) and second, labels that Grub creates are not especially informative - or not at all - my Puppy Slacko had a label 'Unknown Linux'.
So I made files 06_debian, 07_slack, 08_test and 41_win (from /etc/grub.d/40_custom). First has my two debians, second has Salix and Slackware, third is for temporary Linuxes and fourth for you-guess-what. Took entries from each distros /boot/grub/grub.cfg (or from /etc/lilo.conf), cleaned them up (everything after label, hint-crap in if-fi part (do NOT delete search-part there)) and inserted them to their new homes.
Also, fixed finally the console resolution problem (all resos in non-master-grub distros' consoles stay at 640x480 - despite that my master-grubs' conf is fixed AND I fixed it in every bloody other grub).
First, the master-grubs reso-fix (in /etc/default/grub) works ONLY for this same grub, AND - when Grub2 os-probes other distros and creates menuentries - it does NOT include reso part there.
So, it's fixable in two ways:
- either add two lines after label part ends and business-part starts:
load_video
set gfxpayload=keep

- or add kernel parameter: vga=791 (to end of line starting with 'linux...' Mind! This number has to be picked according to resolution your monitor is capable in console.)
Frankly - i didn't experiment with all possible combinations - I used first option for Grub-distros, and the second one for Lilo-distros.
One more thing - if there appears unwanted (penguin) logo at the beginning of boot, then adding kernel parameter logo.nologo fixes it.
See also previous Grub posts: 1 and 2.

## Some desecrating of Slackware:
- Sudo. As there is no group for that, you can't add user to it, and sudo doesn't work. Now, you can add yourself to wheel group
usermod -G wheel username
and then you can enable sudoing through wheel.
Do 'visudo' ... and yeah, it bloody opens in vi. I, for example, know nothing of this adorable 'very powerful' editor. So: I added following to end of my .bashrc
export EDITOR=nano
, saved, opened new terminal, visudo - and now it opens in nano.
Find the following line
# %wheel ALL=(ALL) ALL
, uncomment it, save. And sudo should work now.
In Slack there might be slight problem with system-binaries still not working. It's because user lacks path to them - not because sudo is not working. Open up your .bashrc and add PATH to /sbin:/usr/sbin:usr/local/sbin - that should solve the problem.
- Colors. To make Slacks' boot and shutdown texts fancier-looking, it's easiest to shamelessly copy relevant parts from Salix (thanks, Salix-folks).
First, one has to copy color-definitions file /etc/shell-colors, and then comes boring compare-search-replace routine in files: /etc/rc.d/rc.S, rc.K, rc.M, rc.4, rc.sysvinit, rc.6
Not sure it's worth of it... well, yeah, I think it was for me.
- rc.M and refreshes. There are several things Slackware refreshes at every boot. Like font cache, icons cache, libraries list (ldconfig), mime cache. It does those tasks in background (command &), so there is probably not much difference (in boot time etc) if they are there or not. Still, it's a bit pointless to refresh those things every time.
So I decided that it's good time to start messing with bash scripts and to make some tiny simpleminded launchers I can start from openbox menu. (And then out-comment relevant parts in rc.M)
As I also know nothing of bash, it took unholy amount of googling and trying. First thing, I couldn't get scripts running with su (despite various suggested tricks in web). So I did it through sudo (see above, that's why I made it to work). I wanted my scriptlets to open new terminal, do it's thing, and leave terminal open - so I could see what occurred. And one successful example is here:
#!/bin/sh
# Refresh font cache
Terminal --execute bash -c 'echo "fc-cache -fv";sudo fc-cache -fv;bash'
quit


## I shit around with three different package managements. Quite frequently I mix up if there are --, or -, or there isn't any -. So, kinda lazy solution for this is to use similar aliases in all distros.
Orderly way to do this is to create separate .bash_aliases file and define all your stuff there (simple text file, only aliases there, no #! or something needed):
alias up='sudo apt-get update' - is one definition, and that's for Debian, 'slapt-get -u' goes for Salix and 'slackpkg update' for Slackware.
alias upg='sudo apt-get dist-upgrade' is for Sid, 'slapt-get --upgrade' for Salix and 'slackpkg upgrade-all' for Slackware.
And so on. To keep in mind - aliases have to be unique (in one particular distro), can't have different commands with the same name (meaning, it's bad idea to create alias 'nano' for something - as there is already app exec 'nano').
Also, in this case, .bashrc should have the following somewhere:
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi


And the future posting will be probably quite infrequent. Depends how 'busy' my busy is...