TritonDataCenter / sdc-imgapi

SDC internal API for managing OS images
Mozilla Public License 2.0
5 stars 18 forks source link

linux-prepare-image needs logic to deal with caps in image names #1

Closed chorrell closed 9 years ago

chorrell commented 9 years ago

The linux-prepare-image script has the following (tools/prepare-image/linux-prepare-image starting on line 209):

TARGET_DISTRO=`grep -w Image $PRODUCT_FILE | awk '{print $2;}'`

# Subtlety: the "Image" line in /etc/product in old ubuntu images has
# "ubuntu" (lowercase). In the new ubuntu-certified images it is "Ubuntu"
# (uppercase).
if [ $TARGET_DISTRO == "centos" ] ; then
    prepare_centos
elif [[ $TARGET_DISTRO == "ubuntu" ||
    $TARGET_DISTRO == "Ubuntu" ||
    $TARGET_DISTRO == "debian" ]] ; then
    prepare_ubuntu
fi

On newer Images, we switched to using proper caps for distro names in the /etc/product file ("CentOS" instead of "centos" for example) so the code on lines 214-219 won't call the appropriate function per distro. Image Management still works, just some extra prepare steps are skipped (the updated guest tools actually take care of a lot of this by the way).

A way to deal with that change would be to convert the distro name to all lowercase first:

TARGET_DISTRO=$(grep -w Image $PRODUCT_FILE | awk '{print $2;}' | tr '[:upper:]' '[:lower:]')

That also allows you to simplify the "elif" block as well so you can just check for "ubuntu".

trentm commented 9 years ago

Cool.

Alternatively, is there a more reliable way to get the distro here? From my Linux days I vaguely recall lsb_release or something like that.

chorrell commented 9 years ago

RE: lsb-release

It's not always installed, depending on the distro (from what I recall), so my inclination is to not explicitly rely on that. We could have it pre-installed, but I would rather keep things as lean as possible.

chorrell commented 9 years ago

Resolved in f997274

trentm commented 9 years ago

See pull #2