Skip to content

Bash, awk, xsltproc, and YAD are used in a program to view Linux configuration settings.

License

Notifications You must be signed in to change notification settings

cjungmann/bashconf

Repository files navigation

bashconf

A simple script-based program for accessing gsettings values, similar to dconf-editor, with the ability to use a shortcut via a command line argument. It was developed and tested on Ubuntu 14.04. It doesn't apply to Windows at all, and may not work on other Linux-based platforms.

At the current stage of development, this program is mainly suitable for viewing schema keys with current and default values.

Having neglected far more important projects while working on this, I am setting this aside with no plans. However, there are some things I would like to add if I do come back to this. These ideas are listed in the Future Plans section at the bottom of this document.

Purpose of Program

The program, bashconf has two purposes,

  1. Allow easier, possibly saved, access to specific configuration pages.

  2. A demonstration of techniques with BASH, AWK, YAD, and xsltproc. Some of the techniques are described under Programming Techniques later in this document, others are simply comments in the script files. Look around.

Program Usage

The following examples assume that you are in the bashconf working directory. Ignore the ./ if you've installed to to /usr/bin.

Start fresh with a list of the lowest-level schema domains, then select a line to get subcategories. Drill down to eventually open the keys pages of specific schemas.

$ ./bashconf

If you want to open a specific page or branch, add it to the command:

$ ./bashconf org.gnome.desktop.wm.keybindings

Press Cancel or the Escape key on any page to close the current dialog. Closing a dialog reveals the dialog that opened the just-closed dialog. This continues until the initial dialog is closed, at which point the program ends.

Program Setup

I don't expect this program to replace dconf-editor, so I have not attempted to conform to the Filesystem Hierarchy Standard. I plan to use this program in its working directory.

Generate Cached Information

This program compares information from gsettings and the set of .gschema.xml files that explain how to access and edit the configuration settings. Run the following command to compile a list of schemas and their helper files for faster access later. The program will not run without the cache file.

./setup_schema_list

Shortcut to Program

I made a shortcut in /~/bin (which is in my PATH):

#!/bin/bash
savedir="$PWD"
cd /home/chuck/work/bashconf
./bashconf $*
cd "$savedir"

Programming Techniques

I don't get a lot of practice using bash scripts, and even less with awk scripting, so I want to document some techniques I used in this program for future reference.

  • awk for processing data. Other times I have used awk to create an XML file from data, then XSL to modify the data. However, with this project, I realized that awk would be completely adequate for what I wanted to do, and a much lower computational cost.

    I want to particularly highlight:

    • awk interpreter directive Using #!/usr/bin/awk -f in the first line of the script invokes awk to run the script. For a complete awk solution, this is more direct that making a bash script call awk.

    • if/else-if/else execution When an awk script must execute actions based on pattern matches, an if/else-if/else model can be duplicated with a next instruction at the end of an action. If the pattern doesn't match, awk won't encounter the next, to the following pattern will be considered.

      Seek the script util_identify_relocatables for an example.

    • awk lookup pattern util_identify_relocatables is also an example of using a third source of data as a guide for the output. A list of special-case schemas is passed to the awk script via a named value. The script selects an action based on whether or not the schema of the current line is included in the third data source.

    • awk unique selection The script util_get_schemas compares each line with the previous, only writing output if the current and previous lines are different. This obviously depends on the list being sorted on the target field.

    • awk pattern / action syntax Unlike the flexibility of favored C/C++ syntax for code blocks, awk requires that the opening curly-brace of the action follows the pattern on the same line, even if the action block continues for multiple lines. Also note the use of OFS (output field separator) instead of printf.

      # Single-line action obviously follows,
      BEGIN { RS = "\n"; FS = "\t"; OFS = "\t" }
      
      # For multi-line actions, the curly-brace follows the pattern on the same line:
      rlist~$1 {
         print 
         print $1, "r", $2
      }
  • bash use, on the command line and in scripts.

    • awk script in heredoc Avoid using multiple scripts to accomplish a single task by including an awk script in the bash script.

      The script util_get_keys demonstrates:

      • A here doc awk script.
      • How to use the awk script variable with awk.
    • awk script with parameters

    • Variable substitution notation to replace periods with slashes, also in util_get_keys.

    • Convert strings to arrays in bashconf script.

      For a string like 12|13|14 can be converted to (12 13 14) with: IFS='|' read -r -a parr <<< "$1"

  • YAD Yet Another Dialog. I started this with dialog for console dialogs, then found gdialog for X11 to show more text in a smaller area, and finally decided to implement with YAD.

    This is my first attempt using YAD, so there's probably not much to learn here. I intend to use YAD frequently in the future to do things I couldn't easily do previously. Those projects will be better examples of what can be done in YAD.

Future Plans

I must set this aside to do more pressing work, but there are some features I would like to add to this project.

  • Ability to edit key values There are several key types, many can also hold arrays (ie, multiple values), so this part is not done. To do it right, I would have to use a list dialog to show current entries, perhaps as checkboxes perform an action on several at once, like delete. The list dialog would need an add button as well.

  • Handling Relocatable Schemas Relocatable schemas are the reason this project is so rudimentary, I spent two days trying to figure them out, specifically, how to read the .gschema.xml and gsettings values to determine the appropriate path to access keys in a org.compiz profile. I wanted to be able to view and change the workspaces configuration, but I could never get the observed current value of hsize and vsize, that is, I have a 3x2 workspaces configuration, gsettings reported 1x1.

  • Bookmarking Schemas With the ability to jump directly to a page from a command line parameter, it should be a short step to adding bookmarks. However, this would mean a more formal installation, with a /~/.bashconf directory in which to save the bookmarks, and more sophisiticated YAD configuration to advertise and make the bookmarks available.

  • Quicker Exit It's not very nice to have to escape-escape-escape... to exit the program. I should add handling for Ctrl-C or add a button to the dialog to fully exit.

About

Bash, awk, xsltproc, and YAD are used in a program to view Linux configuration settings.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published