Bash Scripts, Linux

Get the size of your BTRFS Snapshots

If you want to get the size of your BTRFS snapshots you would probably use btrfs qgroup show.  This only shows you a list of IDs and the sizes are in bytes. I wrote a script that will convert the sizes from bytes to kilobytes, megabytes or gigabytes. It will combine the IDs with the name of each snapshot or subvolume from btrfs subvolume list to make each row a lot more meaningful.

In the end instead of seeing a list like this:
Screenshot from 2015-05-26 15:47:24

You’ll see:

Detailed information of each BTRFS snapshot
Detailed information of each BTRFS snapshot

Instead of meaningless IDs you now have the name of your BTRFS subvolumes or snapshots. Instead of a hard to decipher string of bytes it converts each amount into the most appropriate unit of measurement. You can also see the total amount of data that is being used by the snapshots.

For this to work you first need to enable  quotas. Run this command to enable quotas if you haven’t done so already:

sudo btrfs quota enable /

You can clone the project from github by running:
git clone https://github.com/agronick/btrfs-size.git

Or you can just go a wget on the script:
wget https://raw.githubusercontent.com/agronick/btrfs-size/master/btrfs-size.sh

Set it to executable with:
chmod +x ./btrfs-size.sh

Now you can just run the script with: ./btrfs-size.sh

All the columns are pretty self explanatory. The Total column will tell you how much data is in that BTRFS subvolume. The Exclusive Data column is how much data is exclusive to that subvolume. Since BTRFS is a “copy on write” filesystem none of the data is replicated when you create a snapshot. It only needs to make a copy when something changes.

Leave your feedback here to let me know how it worked for you.

Linux

Debugging Vala programs in an IDE

Geany

Geany is an IDE the supports a number of languages including Vala. This tutorial will show you how to get the debugger plugin for Geany working with Vala code. At the time of this writing the plugin in the Ubuntu repositories happens to be broken. We’ll install it from source and configure it for Vala. If you don’t use Ubuntu or a derivative like Elementary OS this article should still be applicable. You just might need to change a few things.

Installation

You can install Geany with:
sudo apt-get install geany

There is a package called geany-plugin-debugger. You can try installing it. At the time of this writing its broken. It installs to the wrong location. If you copy the files to the right location it causes a segmentation fault as soon as you enable it. This was reported half a year ago: https://bugs.launchpad.net/ubuntu/+source/geany-plugins/+bug/1354747

Instead you can get all the plugins for Geany off Github. At the current time the version of Geany in the Ubuntu repos is 1.24. All we care about is the debugger but the other ones are nice to have. I removed the ones from the build script that won’t compile on 1.24 and forked it. You can get it using this command:
git clone https://github.com/agronick/geany-plugins.git

If you have Geany 1.25 grab the offical one:
git clone https://github.com/geany/geany-plugins.git

You need autotools to compile it. Just do sudo apt-get autotools 

Now to install it just do:
./autogen.sh
make -j PROCESSORS #Replace PROCESSORS with the number of processor cores your computer has or the number of jobs you want to spawn to compile
sudo make install

Hopefully this worked. If you get an dependency error install whatever dependency is missing.

Now open up Geany. If you go to Tools > Plugin Manager you should be able to enable the debugger. It wont work just yet though. There are a few more things you need to set up.

Configuration

At this point you’ll want to create a new project. Now you’ll need to set the build parameters. Go to Build > Set Build Commands.

Set this under Vala Commands:

Label Command
Compile valac -c "%f"
Build valac -g --save-temps --pkg gtk+-3.0 "%f"

You can remove the –pkg gtk+-3.0 part if you don’t want to build GTK apps.

Now you will need to do the following:

  1. Insert a breakpoint in your Vala program
  2. Click the build icon
  3. Open the debugging view
  4. Browse for the executable it created
  5. Run your Vala program

Steps for debugging
 There you go. You now have a working Vala debugger. You can step through the code and look up variables at runtime right in your IDE. I hope this helps and is useful. I know I was looking for it for a few months. Its nice to finally have.

I also made this video on how to debug segmentation faults in a command line:

Elementary OS, Linux

Elementary OS Slideshow Wallpaper

Elementaryos logo I set out to code a lightweight script that will make your desktop background change at a preset interval. It changes the background with a fade turning your wallpaper into a slideshow. Having a desktop slideshow seems to be a desired feature in Elementary OS and this method does it using hardly any memory. This should work on any Gtk based distro but I’ve only used it on Elementary OS. Even if you don’t want a slideshow you can use the script to load a random background on each boot up or whenever you run the script. Just use the –bootonly option.

You can find the script on my Github or do a simple wget put the script wherever you want:

wget https://raw.githubusercontent.com/agronick/Wallpaper-Slideshow/master/wallpaper_slideshow.sh

Once it is saved just set it to executable with:

chmod +x ./wallpaper_slideshow.sh

There are a few parameters you can use:

Usage: ./wallpaper_slideshow.sh [FOLDER] [MINUTES]…

  • [FOLDER] Set a folder with images. If it has other files they will be ignored.
  • [MINUTES] (Optional default:2) Set the number of minutes that you want to wait before changing to the next image.
  • [–bootonly] Set this if you want to change to a random image on boot and then exit.
  • [–wait] Do a delay of however minutes you set MINUTES to before switching to the first image.
  • [–log] Display information to the console and log it to syslog.
  • [–help] Display a help message and then exit.

If you just want to see it cycle the default Elementary OS wallpapers every two minutes run ./wallpaper_slideshow.sh without any parameters.

Here is a sample command: ./wallpaper_slideshow.sh ~/Pictures/Backgrounds/ 2 --log

Once you found a setup you like you can append –makecmd to show you a command you can copy and paste into Elementary OS’s startup application settings.

Setting it up for startup in Elementary OS
You need to go to Applications > System Tools > System Settings > Applications > Startup

Elementray OS Startup Applications

Once there click the + in the bottom left. You can then paste the command given to you by –makecmd in the highlighted box.

That’s it. You’ll now have a slideshow wallpaper on your desktop. The script is programmed to load a random set of images and display them as desktop wallpaper sequentially. When it gets to the end it will shuffle the list and start displaying from the beginning.

Update: If you’ve downloaded in the past you probably want to redownload. Elementary OS wasn’t killing the script when it ended a session. Now the script will kill itself if it spends 10 minutes disconnected to a desktop.

Update2: The script now supports changing your ElementaryOS’ login screen. There is a post detailing the changes.

If you are looking for a great collection of wallpaper you can find one here: http://chromecastbg.alexmeub.com/ Click Download in the top right to get them all.

Linux

Display statistics for EnhanceIO

There doesn’t seem to be any any GUIs for Enhance IO. There is a way to display statistics in a terminal. By cobbling together a few commands you can display the statistics and highlight what is being changed. You can set a shortcut for this in .bashrc so you can always access it quickly.

Open up .bashrc and append the following line to the bottom:

alias cache-stats="watch -d 'cat /proc/enhanceio/OSD_0_CACHE/stats /proc/enhanceio/OSD_0_CACHE/io_hist | pr -J -T --columns=2'"

Now you can view all the information EnhanceIO gives you and the differences between each update will be highlighted.

This will display the statistics and the IO history together. Its easy enough to see where one ends and the other begins. This will also concatenate the files into two columns.

Here is what the EnhaceIO stats will look like
Here is what the EnhaceIO stats will look like. Click for a larger view.
KDE, Linux, OpenSuse

Installing KDE5 on OpenSUSE 13.2 as the only desktop enviorment

If you’re looking for a way to install KDE5 during the OpenSUSE OS installation there is a way. It takes a few steps but it works. I’ll explain how to do it below. As of this writing it will install KDE 5.1 on OpenSUSE 13.2.

Make sure you have a network connection during the install because the options you need don’t appear unless you add repos before installation. Fortunately the OpenSUSE installer now has you set up a network connection before you do anything else.

On this screen make sure you have “Add Online Repositories” checked off.
step1

The default repos are all you need.
defaultrepos

On this screen do not select any of the default desktop environments. Select “Minimal X Window”.
desktop

On this screen click software.
software

Check off Plasma 5 base on the left. Here you should also search for NetworkManager and install it as well. You might also want to check off some other packages such as image viewers and PDF readers. Everything you need to have a working OpenSUSE system with KDE 5.1 is selected already though.
plasma5base

Once you boot up you’ll have you’ll have a very minimal graphical interface. Log in as Root. You will need to go into Yast and then click the /etc/sysconfig editor.

Go to Desktop > Display Manager > DISPLAY_MANAGER and set it to kdm.
Then go to Desktop > Window Manager > DEFAULT_WM and set it to plasma5.

That’s it. Restart your system and you’ll have OpenSUSE KDE5 without the bulk of two full featured desktop environments.

You can try setting sddm as the display manager but as of now there is no easy way to get it running. Here is just one of several people I’ve heard feedback from:

From personal experience, sddm in openSUSE is very buggy. It does not allow a proper logout yet (display manager hangs during logout/restart/shutdown).

eeickmeyer (reddit.com)

KDE, Linux, OpenSuse

BIR – Linux GUI Batch Image Resizer

Images from your digital camera tend to be big. Really big. Even with our broadband connections having a slideshow of 5mb images does not make a lot of sense. If you want to email images you probably want to resize them all before you send them. There are also situations where you have images of many different sizes and you want to resize them uniformly. With a quick Google search I couldn’t find any way to do this that didn’t involve a command line. I set out to create a batch image resizer with a GUI similar to the ones I’ve used on Windows.

Its called BIR for Batch Image Resizer. It came out looking like this:

Linux batch image resizer
BIR – The Linux batch image resizer

Along with resizing it will also rotate your images and crop them. It has plenty of options for fine tuning. It can resize a directory recursively and preserve your directory structure in the destination folder. I coded this so it looks at all the images and finds the first parent folder that all of the files share. Alternatively, you can also set it so all of the resized files end up on the same folder with no subdirectories. I’ve tested it with hundreds of files and it seems to work fine no matter how much you throw at it.

It can resize almost any type of file you would need to resize. The list of formates are:

  • BMP Windows Bitmap
  • JPG Joint Photographic Experts Group
  • JPEG Joint Photographic Experts Group
  • PNG Portable Network Graphics
  • PPM Portable Pixmap
  • TIFF Tagged Image File Format
  • XBM X11 Bitmap
  • XPM X11 Pixmap

Thanks to some helpful people on Reddit people have tested it and helped me iron out any issues they discovered

The source code is available here:
https://github.com/agronick/BIR

Here you can find packages for OpenSuse, Fedora, RedHat, and CentOS.

Here you can find the package on the OpenSuse Build Service.

Version 2.0 fixes some issues with Ubuntu and all the code is updated for Qt5. If you need to compile it you use the same exact steps you used for qt4 except the qmake command might be qmake-qt5.

Compiling the Batch Image Resizer
If you rather not deal with resolving dependencies yourself you can download Qt from the Qt website. You can also download Qt-Creator which is the IDE I used to create this program.

If there are no precompiled release for your distro you can compile a release very easy. You just need the dependencies for Qt5. The development package will probably have a suffix like -dev. With a command like this you can search for packages with the letters “qt5” in them that also has the string “-dev”. This works for Ubuntu.

sudo apt-cache search qt5 | grep "dev"

So anyways, once you get the sources and dependencies compiling and installing is very easy.

$ mkdir build
$ cd BIR/build
$ qmake-qt5 ../  
$ make
$ sudo make install

Thats all there is to it. The program should appear in whatever launcher you use.

Linux

Stream a Reddit thread’s comments into a terminal window

Whenever I watch a football or hocky game I like to pull up the Reddit threads that are discussing them to see people’s reactions. I was a pain to refresh the screen and it would be so much better if you could see the comments streaming in real time. I came up with this little script using node and you can have it running in just a few minutes.reddistream2

To invoke it you just run

reddistream <URL of comments>

Thats it. The page updates every five seconds with the newest comments at the bottom.

To install Reddistream first install the Node package manager however its done on your system. That will bring in NodeJS as a dependency. Then you just need to install Reddistream:

sudo npm install reddistream -g

Now open up some Reddit comments and run Reddistream followed by the URL and watch the comments flow in.

Heres the github: https://github.com/agronick/reddistream
and
The NPM link: https://www.npmjs.org/package/reddistream

This lets you do lots of coll stuff because its in a terminal window. You can monitor for activity. You can pipe to other commands and you can redirect your output to a file.

Edit: So I added some new features.

  • It now clearly says who replied to a comment.
  • Comments are indented based off how many parent comments they have
  • Quotes are now italic
  • You can turn off these features by putting -r to disable showing who replied to a post and -i to disable indenting comments.