Much ado about scripting, Linux & Eclipse: card subject to change

Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

2011-11-09

HOWTO: Make KDE remember dual-monitor randr settings

Every time I boot up, KDE appears to forget that I want my monitors to be positioned left-to-right and instead defaults to mirrored config. But, after a lot of cursing and a little googling, I found an answer so it'll no so much keep your settings, but reset its broken config to your settings.

1. Hit ALT-F2, then enter "display" to run the Display Settings app.

2. Configure your settings as you'd like. Note that if the Apply button isn't active after your changes, you can change/revert something like a Position: button to make it active.

3. On restart, KDE may forget your dual-monitor settings. So, to prevent this, go look in your ~/.kde/share/config/krandrrc file:

[Display]
ApplyOnStartup=true
StartupCommands=xrandr --output "DVI-I-1" --pos 1920x0 --mode 1920x1200 --refresh 59.9502\nxrandr --output "HDMI-1" --pos 0x130 --mode 1920x1080 --refresh 60\nxrandr --noprimary

4. Copy the configuration into a new file, and replace \n with newlines. I like to put scripts like this in /etc/X11 because they relate to screen res and positioning.

# from ~/.kde/share/config/krandrrc
xrandr --output "DVI-I-1" --pos 1920x0 --mode 1920x1200 --refresh 59.9502 
xrandr --output "HDMI-1" --pos 0x130 --mode 1920x1080 --refresh 60 
xrandr --noprimary

5. Ensure the script is readable/executable for all users:

chmod 755 /etc/X11/1920x2.sh

6. Hit ALT-F2, then enter "autostart" to run the Autostart config tool.

7. Click Add script... and browse for the script you created above.

8. Reboot and watch the magic unfold.

2011-02-01

HOWTO: Find osgi dependencies in features

Say you're trying to build something with Tycho & Maven 3 and while resolving dependencies before compilation, you're told:

[INFO] [Software being installed: 
  org.eclipse.tm.terminal.local.feature.group 0.1.0.v201006041240-10-7w312117152433, 
  Missing requirement: 
    org.eclipse.tm.terminal.local 0.1.0.v201006041322 
      requires 
        'bundle org.eclipse.cdt.core 5.2.0' 
          but it could not be found, 
  Cannot satisfy dependency: 
    org.eclipse.tm.terminal.local.feature.group 0.1.0.v201006041240-10-7w312117152433 
      depends on: 
        org.eclipse.tm.terminal.local [0.1.0.v201006041322]]

To quickly verify where this dependency is coming from, you can go look into the feature.xml for the org.eclipse.tm.terminal.local feature jar... but if you don't have it installed, this is somewhat more cumbersome; besides, you then have to unpack the jar before you can look inside it.

And maybe that feature contains a number of OTHER dependencies that you'll also need to resolve in your target platform when building. Sure, there are UI tools to do this within Eclipse, but when you're working on remote servers sometimes UI isn't available.

Workaround? Assuming you have a mirror of the update site(s) from which you're trying to resolve the dependency (eg., Helios) or can ssh to dev.eclipse.org, you can simply run a quick shell script to do the investigative work for you:

$ cd ~/downloads/releases/helios/201009240900/aggregate/; ~/bin/findDepInFeature "*tm*" cdt

./features/org.eclipse.tm.terminal.local_0.1.0.v201006041240-10-7w312117152433.jar
      <import feature="org.eclipse.cdt.platform" version="7.0.0" match="greaterOrEqual"/>
      <import plugin="org.eclipse.cdt.core" version="5.2.0" match="compatible"/>
      <import plugin="org.eclipse.core.runtime"/>
Where the script looks like this:
#!/bin/bash
# find plugins/feature deps by searching in some folder for feature jars, and searching through their feature.xml files for dependencies

# 1 - featurePattern - pattern of features to search (eg., "org.eclipse.tptp" or "\*" for all features)
# 2 - dependencyPattern  - pattern of plugins/feature deps for which to search (eg., "org.eclipse.tptp.platform.instrumentation.ui")
# 3 - location       - directory in which to search, if not "."

if [[ ! $1 ]]; then
        echo "Usage: $0 <featurePattern> <dependencyPattern> <location>"
        echo ""
        echo "Example: $0 tm.terminal cdt"
        exit 1
fi

# if no location, look in current dir (.)
if [[ $3 ]]; then location="$3"; else location="."; fi

# if no featurePattern, search all features for dependencyPattern
if [[ ! $2 ]]; then featurePattern="*"; dependencyPattern="$1"; else dependencyPattern="$2"; featurePattern="$1"; fi

rm -fr /tmp/findinfeature/; mkdir -p /tmp/findinfeature/features/
for f in $(find "$location" -type f -name "*${featurePattern}*" | egrep -v "pack.gz|source" | grep features | egrep "${featurePattern}"); do
        #echo "$f [$featurePattern, $dependencyPattern]"
        unzip -q $f -d /tmp/findinfeature/ feature.xml
        #       <import feature="org.eclipse.cdt.platform" version="7.0.0" match="greaterOrEqual"/>
        #       <import plugin="org.eclipse.cdt.core" version="5.2.0" match="compatible"/>
        if [[ ! $(cat /tmp/findinfeature/feature.xml | egrep "<import" -A3 | egrep "plugin=|feature=" -A1 -B1 | egrep "\".*${dependencyPattern}[^\"]*\"" -A1 -B1) ]]; then
                rm -fr /tmp/findinfeature/feature.xml
        else
                mv /tmp/findinfeature/feature.xml /tmp/findinfeature/${f}_feature.xml
                echo "${f}"
                cat /tmp/findinfeature/${f}_feature.xml | egrep "<import" -A3 | egrep "plugin=|feature=" -A1 -B1 | egrep "\".*${dependencyPattern}[^\"]*\"" -A1 -B1
                echo ""
        fi
        rm -fr /tmp/findinfeature/feature.xml
done

2009-07-21

HOWTO: generate .m3u playlist from .mp3 directory

Been trying to find a solution to this one for ages. Turns out it's stupidly simple - just dump the results of a find into a file.

#!/bin/bash
dir="$1"
echo "Create playlist for $1 ..."
if [[ $2 ]]; then list="$2"; else list="$1"; fi

pushd "$dir" 2>&1 >/dev/null
find . -type f -name "*.mp3" > "$list.m3u"
echo "Found these files:"
cat "$list.m3u"
popd 2>&1 >/dev/null

With or without the "./" prefix on each found file, the resulting .m3u files work on my Blackberry (and are found automatically), including nested folders and paths with spaces. To run the above, just do this:

$ ./m3u.sh "artist folder/disc folder" "playlist name"

2009-05-11

Automatic Eclipse mirror selection / Better download pages?

Have you ever wanted to fetch a whole stack of Eclipse project runtimes so you can build against them? For example, say you want all the Galileo M7 builds from Platform, TPTP, BIRT, DTP, WTP, and dependencies (EMF, GEF, XSD). You can find the URLs for each zip you want on the projects' pages, and download them one-by-one from the closest mirror, but that's time- and bandwidth-consuming, esp. if you want these on a remote server, not your local box.

Enter the "&r=1" option on http://www.eclipse.org/downloads/download.php, which will fetch from the closest mirror automatically.

So, now, you can script the M7 stack fetch like this:

for u in $*; do
  if [[ ! ${u##*file=*} ]]; then # add the r=1 suffix
    u=${u}"&r=1"
  fi
  echo "wget $u ..."
  wget --no-clobber "$u"
done

Then run it like this:

./fetch.sh \
"http://www.eclipse.org/downloads/download.php?file=/tools/gef/downloads/drops/3.5.0/S200905011522/GEF-runtime-3.5.0M7.zip" \
"http://www.eclipse.org/downloads/download.php?file=/birt/downloads/drops/M-R1-2.5M7-200905061338/birt-report-framework-2.5M7.zip" \
"http://www.eclipse.org/downloads/download.php?file=/birt/downloads/drops/M-R1-2.5M7-200905061338/birt-wtp-integration-sdk-2.5M7.zip" \
"http://www.eclipse.org/downloads/download.php?file=/datatools/downloads/drops/N_DTP_1.7/dtp-1.7.0M7-200905052200.zip" \
"http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/S-3.5M7-200904302300/eclipse-SDK-3.5M7-win32.zip" \
"http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/S-3.5M7-200904302300/eclipse-SDK-3.5M7-linux-gtk.tar.gz" \
"http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/S-3.5M7-200904302300/eclipse-SDK-3.5M7-linux-gtk-x86_64.tar.gz" \
"http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/S-3.5M7-200904302300/eclipse-SDK-3.5M7-macosx-carbon.tar.gz" \
"http://www.eclipse.org/downloads/download.php?file=/modeling/emf/emf/downloads/drops/2.5.0/S200905041408/emf-runtime-2.5.0M7.zip" \
"http://www.eclipse.org/downloads/download.php?file=/tptp/4.6.0/TPTP-4.6.0M7-200904260100/tptp.runtime-TPTP-4.6.0M7.zip" \
"http://www.eclipse.org/downloads/download.php?file=/webtools/downloads/drops/R3.1/S-3.1M7-20090505073946/wtp-S-3.1M7-20090505073946.zip" \
"http://www.eclipse.org/downloads/download.php?file=/webtools/downloads/drops/R3.1/S-3.1M7-20090505073946/wtp-jpt-S-3.1M7-20090505073946.zip" \
"http://www.eclipse.org/downloads/download.php?file=/modeling/emf/emf/downloads/drops/2.5.0/S200905041408/xsd-runtime-2.5.0M7.zip" 

So, now the only problem is that every project structures & styles their downloads pages differently...

  1. DTP -> choose file(s)
  2. GEF -> choose file(s)
  3. EMF/XSD -> choose file(s)
  4. WTP -> choose build -> choose file(s)
  5. Platform -> choose build -> choose file(s) & platform(s) -> click through warnings
  6. TPTP -> choose branch tab -> choose build -> choose file(s)
  7. BIRT -> More Downloads -> Recent Builds -> choose build -> choose file(s)

Am I the only person that finds this inconsistency annoying? Is it time for a more consistent UI? I'm exploring what to do for Athena-based builds, and welcome suggestions in bug 275682. What pages do you like best? Worst? Which are easiest to use? Hardest? Do you prefer the old blue-and-white pages? The purple Phoenix pages? The grey Nova pages? Any UI designers want to contribute?

Or, really, are downloads obsolete? If we could collect statistics on p2 jar downloads, I'm sure we'd see that most people prefer that approach, and I for one would certainly prefer to just build against a p2 repo (or 7) than a pile of zips. I suppose the hybrid solution for now is to provide zipped p2 repos for download, many projects do today (Modeling, GEF, PDT, VE ...).

2008-12-08

Obfuscation 101: Ant-contrib

I have recently fallen in love with ant-contrib. I'd still rather write Bash scripts, but if one must interact w/ Ant, ant-contrib is the only way to survive it. Without it, you don't have variables, for-loops, or if-elseif-then trees.

Of course, with every love there are moments of extreme angst. For example, I've been fighting with this error for the last 12 hrs, on and off, as I've been trying to resolve bug 256440:

Invalid type class org.apache.tools.ant.TaskAdapter used in For task, it does not have a public iterator method

What does that mean? It means I'm a dumbass.

Though I should know better, I rely on tools such as Eclipse's Ant editor to tell me when I've messed up task syntax. And though it can do CTRL-SPACE completion for the <for> task, the editor doesn't mark this invalid (if I've already typed it in).

<for ...>
 <if>
   ...
 </if>
</for>

The fix?

<for ...>
 <sequential>
   <if>
     ...
   </if>
 </sequential>
</for>

Ultimately, though, I wish error messages would be written with the end-user in mind. The above problem would have been solved in seconds had it been simply "For task cannot contain nested If task... dumbass." :)

2008-11-18

HOWTO: Use the p2 Update UI to control where you install

A few months ago, I wrote about using the p2 director to control where you install plugins & features.

Here's the other approach I mentioned in that article -- using the p2 Update UI and a little filesystem trickery.

  1. Use the p2 Update UI (Help > Software Updates... > Available Software) to install what you want. When prompted to restart, click No -- DO NOT RESTART OR APPLY CHANGES.
  2. Open a console window and run ./moveInstall.sh foo 10 to move all plugins and features created in the last 10 minutes from ./plugins and ./features into ~/eclipse/eclipse-plugins-foo, then link them from ./dropins/foo.link.

    Note that the name, foo, is arbitrary -- it can represent the specific feature set you just installed (eg., "jet" for JET plus dependencies) or it could be something generic like "team", where I've got plugins for Mylyn, Tasktop, Subclipse, CVS, JIRA, and Bugzilla. You can also add/replace plugins & features in an existing folder by running the script again.

  3. Use the p2 Update UI (Help > Software Updates... > Revert Configuration) to revert the changes you just installed by selecting the timestamp of the configuration from BEFORE you installed the plugins & features in step 1.

    Since you moved the files when Eclipse wasn't looking, it simply removes the p2 metadata, but can't delete the plugins and features.

  4. When prompted, restart Eclipse. On restart, the new plugins & features will be loaded.

Because the new plugins & features are not in the Eclipse root, you can now use those plugins with multiple versions of Eclipse -- just copy the foo.link file into another Eclipse's dropins/ folder.

This is perfect for testing milestone builds without having to reinstall everything each time.

Of course it's so easy to do this in shell script I have to wonder why p2 can't do it under the covers so we can get back the old functionality from Eclipse 3.3...

2008-09-11

HOWTO: timestamp your Bash prompt

This has always been a pain for me -- waiting for crontab events to kick, you have to keep typing date or date;ls -la|tail waiting for files to show up.

Recently, I got annoyed enough to take matters into my own hands, and I found this. Most of the advice in there doesn't seem to work for the system I was working on, but I worked out another solution, using the PROMPT_COMMAND variable. The following code should go in your ~/.bashrc, /etc/bashrc, or equivalent.

red="\033[1;31m";
norm="\033[0;39m";
cyan="\033[1;36m";
if [ "$PS1" ]; then
    if [[ $UID -eq 0 ]]; then
      PS1="\[$red\]\u@\h:\w\\[\033[0;39m\]\n# "
    else
      PS1="\[$cyan\]\u@\h:\w\\[\033[0;39m\]\n\$ "
    fi
    export PROMPT_COMMAND="echo -n \[\$(date +%H:%M:%S)\]"
    export PS1=" "$PS1"\[\e]30;\u@\h\a\]"
fi
The result?
[15:17:16] nickb@emft:/opt
$ 
- or, when logged in as root -
[15:18:06] root@emft:/home/nickb
# 

2007-12-03

Pattern Match Searches Within Multiple Files And Archives

Have you ever wondered what plugin is locking a particular file extension, and forcing it to be opened with a certain editor? Or wanted to scan some plugins to check their copyright information? Whatever the filetype, this script will allow you to search inside zips and jars for text files matching a given regular expression. Sure, there's probably a graphical way to do this, but nothing beats the purity of the almighty commanline.

Here's some sample output, looking for the plugins that lock *.mod files:

$ find.in.zip.sh ~/eclipse/eclipse-plugins-other "*.jar" "plugin.xml" "extensions.*.mod" -verbose

** [1] /tmp/plugins/org.eclipse.wst.dtd.core_1.1.200.v200710021541.jar!plugin.xml **
41-     <extension point="org.eclipse.core.runtime.contentTypes">
42-             <content-type
43:                     file-extensions="dtd,mod,ent"
44-                     priority="normal"
45-                     name="%DTD_Content_Type_Extension_Element.name"

** [2] /tmp/plugins/org.eclipse.wst.xml.ui_1.0.400.v200711071909.jar!plugin.xml **
16-     <extension point="org.eclipse.wst.xml.ui.catalogFileType">
17-             <fileType
18:                     extensions="dtd, ent, mod"
19-                     description="%_UI_PREF_DTD_FILES"
20-                     id="org.eclipse.wst.xml.core.ui.catalogFileType.dtd">

Looking for files that aren't in zips? Use this simpler script:

$ find.sh ~/eclipse/eclipse-plugins-enable34/ "feature.xml" "2007 by" -verbose

** [1] /tmp/features/org.eclipse.eclipsemonkey_1.0.0.200706060947/feature.xml **
11-
12-   <copyright>
13:      Portions copyright 2007 by Aptana Inc.
14:Other portions copyright 2006-2007 by Eclipse Foundation Inc.
15-   </copyright>
16-

Oh, and if you don't see red when you run these, make sure you have this in your ~/.bashrc, /etc/bashrc, or /etc/bash.bashrc file:

export GREP_OPTIONS='--color=auto'

2007-10-14

Video Codecs & Unpacking Script

BitTorrent a lot?

Annoyed at always having to unrar, move the resulting video file, then move the source folder out of your incoming folder and into your 'ready to be deleted when share ratio is > 1' folder? (I use > 3.) I am. Here's a quick unpack script for doing the above in one simple command. Works with foo.rar and foo.part01.rar as the input file.

Secondly, do you find sometimes you can't play the videos you've downloaded? Or you try to share them with someone, and they work great for you but that someone can't play them? Here's a quick list of places to get a/v codecs/players for Windows. You may not need all of these, but if you can't play audio or video, try these. As always, YMMV.

  1. Install updated Windows Media Player & DivX Codec/Player Bundle
  2. Install codecs from c|net: [1], [2], [3] and Nimo

For linux users (*ubuntu, debian, etc.) see these walkthroughs for installing libdvdcss and w32codecs: [1], [2], [3].

2007-05-15

Lotus Notes: A Retrospective

Did a quick, narcissistic self-google tonight and discovered that a number of people have been talking about my Notes 7 installer script.

This got me thinking about Notes through the ages, from the bad old days of 4.x when I first started w/ IBM in '99 and longed for Groupwise or PINE to my days of writing LotusScript and designing database apps (while trying not to curse at Designer for its frequent, and at the very least, predictable crashes) in and around the 5.5-6.0 days, to the days when I first tried to install some flavour of Notes on a linux box.

Notes 6.0 and 6.5 thru WINE were horrible, and painful to set up -- I can't recall if I ever managed to get them working, but I do remember wondering how IBM could invest so much time and money in Linux without making Notes run there.

Notes 7.0b3 with WINE (still with the 6.5 splash screen) was buggy to the point where right-clicking your inbox caused the RSOD (Red Screen Of Death), but was at least a little easier to install, in that I could actually do it on a Debian-based system. Unfortunately, it was pretty temperamental and if you accidentlally upgraded your WINE from a very special patched version available only on internal IBM servers, you broke it. It also came with the unfortunate acronym "NUL", for Notes Under Linux. I'll let you make your own jokes.

Notes 7.0 was certainly an improvement over the past versions, but being a full Eclipse-based Java client, there's a certain amount of memory usage that's unavoidable. That said, there's no more Windows emulation through WINE, so it's more stable. I can now run Notes 7 without random crashes and hangups on Linux (though I do still get some pretty odd error messages thrown at me once in a while -- it just wouldn't be Notes without 'em!). Yes, I'm often annoyed by the fact that modal dialog boxes appear UNDER my main Notes window and sometimes don't appear until I minimize everything. True, my laptop is a T60p w/ 2G or RAM and a dual-core 2.0G processor, so it's got horsepower to burn, but the point is, from a usability standpoint, Notes 7 actually works on Linux. Combine it with a couple Eclipse workspaces and Sametime 7.5.1 and you *do* chew up a lot of RAM, but then, that's why you're running Linux, right? Try doing that on Windows and still getting reasonable performance when your virus scan software starts up. ;-) Of course I still prefer Gmail, but I digress.

It's my fond hope that the folks that package Notes will heed the rants about how much of a pain it is to install on anything but Windows, RHEL and SuSE, and make the experience easier for everyone else, like us SimplyMEPIS / (k)ubuntu folks. Clearly, things have improved substantially. That said, there's still a long way to go before Notes can be installed via apt-get without having to worry about missing fonts, libraries, PATH entries, or which of the several included startup scripts to use to launch Notes.

Notes 8 is now available in beta, and according to fellow IBMer-blogger Chris Aniszczyk, Notes 8 will be even better still. When I go through the process of installing that one, I'll provide a new script or at least blog the experience. Stay tuned.

2007-04-19

DRM Packaging for Linux

In order to put .mp3s on my new SE W810i phone as ringtunes, I have to convert them first to .dm files. This is a pain, but it could be worse. So, I found SonyEricsson's DRM Packager, installed it, and it works great. Unfortunately, they only provide this tool for Windows and Mac.

So, naturally, it was time to write a Linux implementation. ;-)


Setting up the DRM Packager for use with Linux is easy. Packaging is faster on a native Windows system (seconds instead of milliseconds), but then you have to actually boot Windows, so overall it's still faster.

I'm currently using the following tools for converting MP3s to ringtunes:

  1. mp3 slicing: kwave sound editor, part of KDE (save as uncompressed .wav files)
  2. mpeg compression: lame or sneetchalizer (.mp3 or .mp4)
  3. DRM packaging: Sony Ericsson's DRM Packager tool -- details below (.dm)
  4. copying files to device: Konqueror, part of KDE (drag and drop from hard drive to usb device)

DRM packaging

  1. Download 'DRM Packager 1.35 - Windows' from Sony Ericsson's site.
  2. Install from Executable (using WINE) to default location, eg: ~/.wine/drive_c/Program Files/Sony Ericsson/DRM Packager/.
  3.   wine ~/DRMPackager-1.35-Windows.exe
  4. If your WINE instance doesn't use z: as the drive for the filesystem root (/), edit drmpack.sh and change to s: or whatever your WINE wants.
  5.   rootDir="z:"; # wine directory mapping
  6. Run drmpack.sh to convert a single file or recurse through a directory of .mp3 & .mp4 files, in order to generate .dm files. For syntax help, run w/o commandline options or read the source.
  7.   nickb@nickbdesk:~/ringtunes $ ./drmpack.sh tunes
    
      Processing directory /home/nickb/ringtunes/tunes ...
      Creating /home/nickb/ringtunes/tunes/neuroticfish_shortcommercial.dm ...
      Creating /home/nickb/ringtunes/tunes/neuroticfish_theyrecomingtotakemeaway.dm ...
      Creating /home/nickb/ringtunes/tunes/placebo_runningupthathill.dm ...
      Creating /home/nickb/ringtunes/tunes/placebo_postblue.dm ...
  8. If you prefer a GUI, use DRM Packager.desktop to launch the GUI tool using WINE, then browse for files to add to the GUI, and click 'Create DRM Content'. For Sony Ericsson W810i, DO NOT CHANGE THE DEFAULT SETTINGS! You can launch the GUI from the commandline with:
  9.   wine "c:\Program Files\Sony Ericsson\DRM Packager\DRMPackagerGUI.exe"
  10. If the GUI won't open, try copying MSVCP60.DLL into the DRM Packager install folder. If you don't have a Windows machine handy to grab this file from, Google for a site like http://www.dll-files.com/dllindex/dll-files.shtml?msvcp60 you trust and download it from there.

Tested with:

  • Sony Ericsson W810i phone
  • Sony Ericsson DRMPackager-1.35-Windows.exe
  • WINE 0.9.9-0ubuntu2
  • MEPIS Linux 6.0 (based on Kubuntu 6.06LTS)
  • Windows XP Pro SP2
  • Thinkpad T60p