#!/bin/bash # ------- # File: llxcfg-getboot # Description: Simple script to read variables from kernel boot # cmdline # # July 2006, Luis Garcia # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e PATH="/usr/sbin:/usr/bin:/sbin:/bin" # VARIABLES # FUNCTIONS usage(){ echo "Usage: $0 [--test] VARIABLE_NAME" >&2 exit 1 } test_parameter() { local PARAM_NAME="$1" shift while [ "$1" ]; do echo "$1" |grep -q "^${PARAM_NAME}\(=.*\)\?\$" && return 0 shift done return 1 } get_parameter() { local RET_VALUE="" PARAM_NAME="$1" shift while [ "$1" ]; do if echo "$1" |grep -q "^${PARAM_NAME}=" ; then RET_VALUE="` echo "$1" |sed -ne "s%^${PARAM_NAME}=%%p"`" fi shift done echo "${RET_VALUE}" return 0 } # MAIN PROGRAM # Initial test if [ "$1" = "--test" ] ; then shift [ -z "$1" ] && usage test_parameter $1 `cat /proc/cmdline` || exit 1 else [ -z "$1" ] && usage get_parameter $1 `cat /proc/cmdline` fi exit 0