+UNAME="$(uname -r)"
+PN="$(basename $0)"
+[ -n "$WORKING_DIR" -a -d "$WORKING_DIR" ] || WORKING_DIR=$(pwd)
+VERSION='***UNRELEASED***'
+
+# data collection should not be affected by user locale
+export LANG=C
+export LC_ALL=C
+
+TIMESTAMP='+%F--%H-%M-%S-%Z'
+DATE="$(date $TIMESTAMP)"
+
+echo "$PN ${VERSION} - collect hardware information"
+
+GENERATE_FILE='1'
+GENERATE_DIRECTORY=''
+
+while getopts "hdf" args; do
+ case "$args" in
+ h) echo "
+This tool collects information of the hardware this tool is being executed
+on. It can be executed as normal user to collect some basic information or
+with root permissions to collect as much information as possible. By
+default, a file named grml-hwinfo-TIMESTAMP.tar.bz2 storing all collected
+information will be created in the current working directory. Alternatively,
+you can have it create a directory with all information.
+
+Options:
+
+ -h Display this help message
+ -f Create grml-hwinfo-TIMESTAMP.tar.bz2
+ -d Create grml-hwinfo-TIMESTAMP as a directory
+ -df Create both, the directory and the file
+"
+
+ exit 0;;
+
+ d)
+ GENERATE_FILE=''
+ GENERATE_DIRECTORY='1'
+ ;;
+
+ f) # generating file; default behaviour
+ GENERATE_FILE='1'
+ ;;
+
+ esac
+ done
+
+# Generate output/temporary directory name & path, and output file path
+OUTFILE=""
+OUTDIRNAME="grml-hwinfo-${DATE}"
+OUTDIR="${WORKING_DIR}/${OUTDIRNAME}"
+mkdir "${OUTDIR}" || { echo 'Directory "'${OUTDIR}'" already exists, aborting.'>&2 ; exit 1; }
+
+if [ -n "$GENERATE_FILE" ] ; then
+ OUTFILE_="${OUTDIR}.tar.bz2"
+ [ -e "${OUTFILE_}" ] && { echo 'File "'${OUTFILE_}'" already exists, aborting.'>&2 ; rm -r "${OUTDIR}"; exit 1; }
+ OUTFILE=${OUTFILE_}
+ touch "${OUTFILE}"
+fi
+
+if [ "$(id -u)" != "0" ] ; then
+ NOTROOT=1
+ echo "W: Running without root permissions. Not all data will be collected."