Showing posts with label gentoo. Show all posts
Showing posts with label gentoo. Show all posts

Tuesday, February 1, 2011

Using github and layman for my own gentoo overlay

Since I almost always have a local portage overlay in any gentoo machine I create, I've started to maintain in github.

Now, originally I just pulled the repository to /usr/local/portage.git on each machine and added the dir to PORTDIR_OVERLAY in make.conf.

But since I already have other third party overlays and maintain them using layman, I though why not use that for my own overlay as well?

So all is required is to create a custom repositories xml file and point to it from the layman config.

The repostiories xml (this one is using https since I can't access git from work - the down side is that it ask for password on every layman sync, but git://github.com/asssaf/portage.git or git@github.com:asssaf/portage.git can be used where this is not a problem):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE repositories SYSTEM "/dtd/repositories.dtd">
<repositories xmlns="" version="1.0">
<repo quality="experimental" status="unofficial">
<name><![CDATA[mygithub]]></name>
<description><![CDATA[mygithub]]></description>
<homepage>https://github.com/asssaf/portage</homepage>
<owner>
<email></email>
<name><![CDATA[Assaf]]></name>
</owner>
<source type="git">https://asssaf@github.com/asssaf/portage.git</source>
<feed></feed>
</repo>
</repositories>

And in /etc/layman/layman.cfg, add the line in bold:

overlays : http://www.gentoo.org/proj/en/overlays/repositories.xml
file:///etc/layman/localrepositories.xml


The overlay will be available for addition using 'layman -a mygithub' and pulled into (by default) /var/lib/layman/mygithub.

Monday, August 2, 2010

Restoring x server zap functionality

The xorg x server on gentoo has the ctrl-alt-backspace disabled by default. I really like that functionality (especially when seeing that there is a lot of memory in use when nothing is running, after a very long uptime).

Apparently you should use kernel SAK which is superior (alt-break-K if you have magic sysrq configured in the kernel). For some reason it is not recommended to use this to SAK, so a new key sequence should be defined for it. A good place to do it in gentoo is in /etc/conf.d/local.start, and since ctrl-alt-backspace is available, it can be used for this purpose (key code 14):

# Set ctrl-alt-backspace to SAK
echo "control alt keycode 14 = SAK" | /usr/bin/loadkeys

Optionally restore the key map in /etc/conf.d/local.stop:

# restore keymap to default
/usr/bin/loadkeys --default


It is also a good place to set a replacement key sequence for reboot, if ctrl-alt-del is disabled in /etc/inittab. For example ctrl-alt-break (key code 119):

echo "control alt keycode 119 = Boot" | /usr/bin/loadkeys

Thursday, July 29, 2010

Gradle ebuild

Latest ebuild can be found in github: https://github.com/asssaf/portage/tree/master/dev-java/gradle-bin

Pretty ugly (uses the bundled jars instead of installed ones), but it works.

# dev-java/gradle-bin-0.9_rc1.ebuild

# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI="2"

inherit java-pkg-2

MY_PN=${PN%%-bin}
#MY_PV=${PV/_pre/-preview-}
MY_PV=${PV/_rc/-rc-}
MY_P="${MY_PN}-${MY_PV}"

DESCRIPTION="Build Tool for Java"
SRC_URI="http://dist.codehaus.org/${MY_PN}/${MY_P}-bin.zip"
HOMEPAGE="http://www.gradle.org/"
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~x86"

RDEPEND=">=virtual/jdk-1.5"

IUSE=""

S="${WORKDIR}/${MY_P}"


src_unpack() {
unpack ${A}
}


# TODO we should use jars from packages, instead of what is bundled
src_install() {
#TODO set GRADLE_HOME
#local jar JARS="gradle-core gradle-open-api gradle-ui gradle-wrapper"

local gradle_home="${ROOT}/usr/share/${PN}"

insinto "${gradle_home}"
#doins gradle-imports || die "Failed to install files"

cd lib
for jar in *.jar; do
java-pkg_newjar ${jar} ${jar}
done

insinto "${gradle_home}/lib/plugins"
doins plugins/*

#sed -i "s/-${PV}.jar/.jar/" bin/gradle || die "Failed to patch launcher script"
#dobin bin/gradle || die "Failed to copy launcher script"
java-pkg_dolauncher "gradle" --main org.gradle.launcher.GradleMain --java_args "-Dgradle.home=${gradle_home}"
}


Update (2-Aug-10): I'm getting a NoClassDefError when trying to run JUnit tests. I've switched to the stable 0.8, which seems to work fine (just renamed the ebuild).

Update (27-Aug-10): I found a workaround for this issue. Adding the following lines to the build.gradle file fixes it:
test.bootstrapClasspath('/opt/sun-jdk-1.6.0.20/jre/lib/rt.jar')
test.bootstrapClasspath('/usr/share/gradle-bin/lib/commons-lang-2.5.jar')
Also updated the ebuild to 0.9_rc1.

Update (3-Nov-10): I've added additional enhancements to the ebuild but decided that keeping the blog up to date is the wrong way to go about it so I'm doing all ebuild maintenance in github from now on. My portage repository is here (and this ebuild is under dev-java/gradle-bin).

Sunday, May 30, 2010

My /boot kernel management (2)

In the last post I described my /boot kernel scheme and eselect-based management tool. Another piece of that is the script to actually install a new kernel to that fancy structure.

Here it is:


#!/bin/sh

#
# "make install" script for i386 architecture
#
# Arguments:
# $1 - kernel version
# $2 - kernel image file
# $3 - kernel map file
# $4 - default install path (blank if root directory)
#

KERNEL_VERSION="$1"
KERNEL_IMAGE="$2"
KERNEL_MAP="$3"
BASE_INSTALL_PATH="$4"
KERNEL_BASE="$BASE_INSTALL_PATH/installkernel"

die () {
ERR="$1"
shift

if [ -z "$1" ]
then
echo Aborting 1>&2
else
echo $* 1>&2
fi

exit $ERR
}


verify () {
if [ ! -f "$1" ]; then
echo "" 1>&2
echo " *** Missing file: $1" 1>&2
echo ' *** You need to run "make" before "make install".' 1>&2
echo "" 1>&2
die 1
fi
}

# Make sure the files actually exist
verify "$KERNEL_IMAGE"
verify "$KERNEL_MAP"

# check if the version already exists in /boot and find the appropriate p-level
KERNEL_BASE_DIR="$KERNEL_BASE/$KERNEL_VERSION"
KERNEL_PLEVEL="0"

while [ -e "$KERNEL_BASE_DIR/p$KERNEL_PLEVEL" ]
do
KERNEL_PLEVEL="$(expr $KERNEL_PLEVEL + 1)"
done

INSTALL_PATH="$KERNEL_BASE_DIR/p$KERNEL_PLEVEL"

# backup old modules if needed
#TODO warn before overwriting existing backup?
#TODO check if the previous plevel is identical?

if [ $KERNEL_PLEVEL != 0 ]
then
OLD_PLEVEL="$(expr $KERNEL_PLEVEL - 1)"
MODULES_BACKUP_FILE="/lib/modules/$KERNEL_VERSION-p$OLD_PLEVEL.tgz"
echo "Creating modules backup for previous kernel: $MODULES_BACKUP_FILE"
tar czf "$MODULES_BACKUP_FILE" -C /lib/modules $KERNEL_VERSION || die 4
fi


# make the new kernel dir
echo "Creating new kernel dir: $INSTALL_PATH"
mkdir -p $INSTALL_PATH || die 2

# copy the file to the new kernel dir
echo "Copying kernel files"
cp "$KERNEL_IMAGE" $INSTALL_PATH/ || die 3
cp "$KERNEL_MAP" $INSTALL_PATH/ || die 3
cp .config $INSTALL_PATH/ || die 3

#TODO run eselect and make modules_install?
echo ""
echo "Done. You should probably do the following now:"
echo "1. eselect the new kernel"
echo "2. run make modules_install"
echo "3. run modules-rebuild"
echo "4. update the ChangeLog"
echo ""


In order to hook this to the standard make install command run at kernel build, this needs to be placed in /sbin/installkernel.
Alas, that position is already taken by a file belonging to the debianutils package. Arrgghhh!!
I opened a bug (and provided a patch) to make this optional.

For now the ebuild for installing the script (myinstallkernel-0.1.ebuild) must block debianutils:

EAPI="2"

LICENSE="GPL"
SLOT="0"
KEYWORDS="x86"
IUSE="+symlink"

DEPEND="symlink? ( sys-apps/debianutils[-installkernel] )"

src_install() {
newsbin ${FILESDIR}/${P} ${PN}

if use symlink; then
dosym /usr/sbin/${PN} /sbin/installkernel
fi

insinto /usr/share/eselect/modules
newins ${FILESDIR}/mykernel.eselect-${PV} mykernel.eselect
}


Update 03-Jun-2010:
1. Updated myinstallkernel script to version 0.3.
2. The bug wasn't accepted by gentoo, but they suggested using CONFIG_PROTECT="/sbin/installkernel" in /etc/make.conf. This kinda works, so I've removed the block from the ebuild.

My /boot kernel management

Some linux distribution simply put the kernel image at /boot/vmlinuz and maybe a backup version as /boot/vmlinuz.old. Same goes for a System.map file.

I prefer to store multiple kernel versions in a hierarchical structure with symlink pointing to the current kernel (which are in turn referenced by grub's menu).

For example, my current kernel is minigen32 (mini since it's my mac mini kernel, gen for gentoo and 32... you can guess :) ).

Under /boot/kernels I have a subdirectory for minigen32 and under that a subdir for each kernel version. I also put another subdir level for local build number, since I might have several builds of the same kernel version.

So I have:
/boot/kernels/minigen32/2.6.32-gentoo-r7/p0
/boot/kernels/minigen32/2.6.32-gentoo-r7/p1

etc., etc.

Each such directory contains the same files. The good 'ol bzImage, System.map and .config.

Then I have symlinks for stable, testing, current, previous etc. pointing to these subdirs, and a simple grub file can be written (kernel /testing/bzImage). When I want to switch kernels I just need to update the symlinks. No need to touch the grub configuration (unless of course I need to change the kernel command line).

Using gentoo's handy eselect utility i've built a module to handle this scheme for me.

$ eselect mykernel list
Available kernel symlink targets:
[1] /boot/kernels/minigen32/2.6.32-gentoo-r7/p0 stable
[2] /boot/kernels/minigen32/2.6.32-gentoo-r7/p1 testing
[3] /boot/kernels/minigen32/2.6.32-gentoo-r7/p2

$ eselect mykernel set testing 3
$ eselect mykernel set testing 2

$ eselect mykernel list
Available kernel symlink targets:
[1] /boot/kernels/minigen32/2.6.32-gentoo-r7/p0
[2] /boot/kernels/minigen32/2.6.32-gentoo-r7/p1 stable
[3] /boot/kernels/minigen32/2.6.32-gentoo-r7/p2 testing

Code for the module (just drop it in ~/.eselect/modules/mykernel.eselect):

DESCRIPTION="Manage the /boot kernel symlinks"
VERSION="0.3"

local BASE_DIR="/boot"
local KERNELS_BASE="$BASE_DIR/kernels"
local TAGS=( stable testing )

# find a list of kernel symlink targets
find_targets() {
local f
for f in $KERNELS_BASE/*/*/p* ; do
#[[ -d ${f} ]] && basename "${f}"
#[[ -d ${f} ]] && echo "${f#${BASE_DIR}/}"
[[ -d ${f} ]] && echo "${f}"
done
}


### show action ###

describe_show() {
echo "Show the current tagged kernels"
}

do_show() {
local TAGS_TO_SHOW=( "${TAGS[@]}" )
has $1 ${TAGS[@]} && TAGS_TO_SHOW=( $1 )

for TAG in ${TAGS_TO_SHOW[@]}
do
my_show $TAG
done
}

my_show() {
local TAG=$1

write_list_start "Current ${TAG} kernel"
if [[ -L $BASE_DIR/${TAG} ]]
then
write_kv_list_entry $BASE_DIR/$(readlink "${BASE_DIR}/${TAG}") ""
else
write_kv_list_entry "(unset)" ""
fi
}

### list action ###

describe_list() {
echo "List Available Kernels in $BASE_DIR"
}

do_list() {
local i j SYMLINKS TAG targets=( $(find_targets) )
write_list_start "Available kernel symlink targets:"

for (( j = 0; j < ${#TAGS[@]}; j++ ))
do
[[ -L $BASE_DIR/${TAGS[$j]} ]] && SYMLINKS[$j]=$BASE_DIR/$(readlink "${BASE_DIR}/${TAGS[$j]}")
done

for (( i = 0; i < ${#targets[@]}; i++ ))
do
local mark=""

for (( j = 0; j < ${#TAGS[@]}; j++ ))
do
if [[ ${targets[${i}]} == ${SYMLINKS[$j]} ]]
then
mark="${mark} $(highlight ${TAGS[$j]})"
fi
done

targets[${i}]="${targets[${i}]} ${mark}"
done

write_numbered_list -m "(none found)" "${targets[@]}"
}

### set action ###

describe_set() {
echo "Tag a kernel"
}

do_set() {
local usage="Usage [${TAGS[@]}] [kernel]" tag=$1 target=$2 symlink
[[ ${#} != 2 ]] && die -q ${usage}
has $tag ${TAGS[@]} || die -q ${usage}

symlink=$BASE_DIR/$tag
if [[ -L "${symlink}" ]] ; then
set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink"

elif [[ -e "${symlink}" ]] ; then
die -q "Target file already exists and is not a symlink: ${symlink}"

else
set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink"
fi
}


set_symlink() {
local target=${1} symlink=${2}
if is_number "${target}" ; then
targets=( $(find_targets) )
target=${targets[$(( ${target} - 1 ))]}
fi
if [[ -z ${target} ]] ; then
die -q "Target \"${1}\" doesn't appear to be valid!"
elif [[ -d "${target}" ]] ; then
local sym_dir=$(dirname ${symlink})
if [[ ! -d ${sym_dir} ]]; then
mkdir -p ${sym_dir} || die -q "Could not create ${my_dir}"
fi
ln -snf "${target#${BASE_DIR}/}" "${symlink}"
else
die -q "Target \"${1}\" doesn't appear to be valid!"
fi
}


Update 3-Jun-2010: Updated eselect module to version 0.3

Sunday, October 11, 2009

Mysterious VMware error in gentoo solved

A while ago I've encountered some errors on vmware startup after an upgrade. One of them was:

/opt/vmware/workstation/lib/vmware/bin/vmware: /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/libstdc++.so.6: version `CXXABI_1.3.1' not found (required by /opt/vmware/workstation/lib/vmware/lib/libvmwareui.so.0/libvmwareui.so.0)

This is probably harmless, and the solution was easy:
$ VMWARE_USE_SHIPPED_GTK=yes vmware

The other one was more mystifying. After starting the UI and clicking the play button I get the familiar "find and run vmware-config.pl" message, which usually means the kernel modules haven't been compiled.

By the vmware-config.pl file has been removed, and besides the modules seemed to load fine.

Today I've upgraded again (after a kernel upgrade as well that solved some vmware-modules compilation problems) and got this again.
Luckily I found the solution here. Just remove a pesky /etc/vmware/not_configured file and you're good to go.

Since I knew I would probably forget about it by the time I encountered this problem again, I renamed it to something very descriptive: not_configured.this_file_makes_vmware_puke.
In second thought, I realized I should probably put it in the blog if I'd ever want to find it again.

Arrrgghh...

Wednesday, August 12, 2009

Adobe AIR on Gentoo

Balsamiq Mockups for the desktop (www.balsamiq.com) is a nice tool for generating nice looking mockups real fast (much faster than visio, for example).
I've been using the web based trial version until today, when I got my license.

Running Balsamiq locally requires installing Adobe AIR on my machine, something I haven't got to doing until now. Installing the linux version of the AIR on gentoo didn't work at all (the installer binary just exits without any message).

Trying to resolve this, one of the first google search results was a nice guide for gentoo. And it worked flawlessly - basically you need to unpack the AIR SDK instead of using the installer.

I've also written a slightly more sophisticated shell script for running AIR apps, which allows specifying the app on the command line as well as symlinking.

/usr/local/bin/air:

#!/bin/sh

SDK_DIR="/usr/local/air_1.5_sdk"
APPS_DIR="/usr/local/air_apps"

BASE="$(basename $0)"


if [ -n "$1" ]
then
APP_NAME="$1"
if [ ! -d "$APPS_DIR/$APP_NAME" ]
then
echo "App $APP_NAME not found in $APPS_DIR" > /dev/stderr
exit 1
fi

else
APP_NAME="$BASE"
if [ ! -d "$APPS_DIR/$APP_NAME" ]
then echo "App $APP_NAME not found in $APPS_DIR" > /dev/stderr
echo "Usage: $(basename $0) " > /dev/stderr
exit 1
fi
fi

exec "$SDK_DIR/bin/adl" -nodebug "$APPS_DIR/$APP_NAME/META-INF/AIR/application.xml" "$APPS_DIR/$APP_NAME"


Now simply unpack balsamiq in /usr/local/air_apps/balsamiq, symlink and you're ready to go:
$ mkdir /usr/local/air_apps/balsamiq && unzip MockupsForDesktop.air -d /usr/local/air_apps/balsamiq
$ ln -s air /usr/local/bin/balsamiq
$ balsamiq &


Update: Support passing command line arguments to the air application (note that for balsamiq to open a file given on the command line, a full absolute path needs to be given)

#!/bin/sh

SDK_DIR="/usr/local/air_1.5_sdk"
APPS_DIR="/usr/local/air_apps"

BASE="$(basename $0)"

if [ "$BASE" = air -a -n "$1" ]
then
APP_NAME="$1"
if [ ! -d "$APPS_DIR/$APP_NAME" ]
then
echo "App $APP_NAME not found in $APPS_DIR" > /dev/stderr
exit 1
fi

shift

else
APP_NAME="$BASE"
if [ ! -d "$APPS_DIR/$APP_NAME" ]
then
echo "App $APP_NAME not found in $APPS_DIR" > /dev/stderr
echo "Usage: $(basename $0) " > /dev/stderr
exit 1
fi
fi

exec "$SDK_DIR/bin/adl" -nodebug "$APPS_DIR/$APP_NAME/META-INF/AIR/application.xml" "$APPS_DIR/$APP_NAME" -- "$@"

Sunday, August 9, 2009

Doing More For Gentoo

Last week I needed to dump a remote svn repository without local access. After searching for the best way to do it I finally chose rsvndump (because it allows dumping a subdirectory of the repository).

As usual, I created an ebuild in order to install it, and posted it in a bug. As some of my bugs are pretty much ignored for a long period, I took the advice to post it to the sunrise overlay.

A week later, after multiple reviews and touch ups (those guys are strict!) the ebuild is now available in the sunrise overlay.

This took a little more effort than just posting the bug, but the ebuild is now of much higher quality (and I learned quite a bit more about ebuilds). It should be easier for the devs to include it in portage this way.

Wednesday, June 10, 2009

Archive portage logs

Just dump the following script in /etc/cron.daily to compress old portage logs and delete ancient ones, without using logrotate or tmpwatch/tmpreaper. After a year of running lappy, my /var/log/portage dir got to almost 1GB.


#!/bin/sh

## remove really old logs (180 days)
find /var/log/portage -name '*.log*' -mtime +180 -print0 | xargs --null --no-run-if-empty rm

## compress big logs (over 10 KB)
find /var/log/portage -name '*.log' -mtime +3 -size +10k -print0 | xargs --null --no-run-if-empty gzip

Tuesday, May 19, 2009

Unpack just what you need

The other day I thought it would be interesting to emerge mtree. mtree is an application that generates a detailed file listing, but that's not the interesting part of today's post. I typed emerge mtree and I see 18 MB need to be downloaded. That sounds funny, should be a small utility. Then I saw it was downloading a big pkgsrc archive from BSD. Okay, that figures they distribute everything in one big archive.

So I let it download, now it's in the unpack phase... and still unpacking... and still unpacking. Hey, what's going on? It's already unpacked 500 MB (kudos bzip2!). I know disk space is cheap today and maybe blackbird is showing its age, but unpacking hundreds of megs for this utility seems really inefficient.

I figured I could modify the ebuild to unpack only the relevant directories of the archive. I was right - a small change to the ebuild (well, fix a typo and then try again) and it works... Hardly any disk space used and I also shaved some time off the emerge.

I don't know if this would be accepted as a bug but I decided to share my optimized ebuild anyway in this bug.

Friday, April 10, 2009

ALSA, oh, ALSA

A week a two ago a hal update broke alsa on blackbird. After a few reboots I managed to get sound back, I believe it was fixed by downgrading hal-info to 20080508.

Yesterday I upgraded the kernel to 2.6.29-r1, and after the first reboot, again no sound (I also got the messages about /etc/modules.d in the boot messages as I got the last time this was b0rked).
So, I tried upgrading hal-info back to 20081219 (latest stable) and rebooted. Now it works (and no warning messages).

I'm assuming it's hal-info (maybe there is some dependency between the new hal version and new kernel version?) but maybe it has something to do with the reboot itself. We'll see next time.

Tuesday, April 7, 2009

GCC 4.3.2

GCC 4.3.2 just got stable on Gentoo a few days ago. For a full, clean, upgrade I need to recompile the whole system. Maybe this weekend (a long one).
I'm wondering, if I'm already recompiling everything, I should consider installing from scratch in 64bit instead of 32bit. Flash has had a 64 bit plugin for a while already, and it seems that sun's JDK is also now sporting a 64 bit plugin. That doesn't leave a lot of remaining objections to 64 bit since the last time I tried.
What about wine, does it work well in 64bit? What other binary blobs do I have that I should worry about?
I recently switched my wireless driver to net-wireless/broadcom-sta, which should work with 64bit.
Let's see... what else... I guess I would need to reinstall oracle-xe. Wait, let's just see what's in my /opt and /usr/local:

VMware, googleearth, sqldeveloper, ...

hmmm... need to think about it some more.

Update: Arrgrggg... Oracle Express doesn't come in 64 bit... Will need multilib after all.