#!/bin/sh # vim: set syn=sh et ai cin sw=2 ts=2 tw=0: VER=0.2 LICENCE=GPLv2+ AUTHOR="Cyrille Pontvieux " REAL_UNAME=/bin/uname BAK_UNAME=/bin/uname.orig fail() { echo "$@" >&2 exit 1 } check_root() { if [ $(id -u) -ne 0 ]; then fail "You should be root to install or uninstall fake uname." fi } version() { echo "Version: $VER" echo "Licence: $LICENCE" echo "Author: $AUTHOR" exit 0 } is_installed() { [ -e $BAK_UNAME ] && file $REAL_UNAME | grep -q 'shell script' } # $1 = kernel name # $2 = hostname # $3 = kernel release # $4 = kernel version # $5 = machine type name # $6 = processor # $7 = platform # $8 = OS install() { if is_installed; then fail "fake-uname already installed, please use reinstall." else mv $REAL_UNAME $BAK_UNAME cat < $REAL_UNAME && chmod +x $REAL_UNAME #!/bin/sh S="$1" N="$2" R="$3" V="$4" M="$5" P="$6" I="$7" O="$8" [ "\$P" = "unknown" ] && P="" [ "\$I" = "unknown" ] && I="" U="" add() { [ -n "\$U" ] && U="\$U \$1" || U="\$1" } while [ -n "\$1" ]; do case "\$1" in -s|--kernel-name) add "\$S" ;; -n|--nodename) add "\$N" ;; -r|--kernel-release) add "\$R" ;; -v|--kernel-version) add "\$V" ;; -m|--machine) add "\$M" ;; -p|--processor) add "\$P" ;; -i|--hardware-platform) add "\$I" ;; -o|--operating-system) add "\$O" ;; -a|--all) U="\$S \$N \$R \$V \$M \$P \$I \$O" ;; --verion) $BAK_UNAME --version exit 0 ;; --help) $BAK_UNAME --help exit 0 ;; esac shift done [ -z "\$U" ] && U="\$S" echo \$U EOF fi } uninstall() { if is_installed; then mv $BAK_UNAME $REAL_UNAME else fail "fake_uname already uninstalled." fi } usage() { cat <<'EOF' Usage: fake-uname [CMD] [OPTION] CMD could be: install: install the fake uname with the following overriding options. reinstall: same as install but could be used if an already fake-uname is installed. uninstall: uninstall the fake uname. No option needed. OPTION could be one or more of the following -s kernel-name -n nodename -r kernel-release -v kernel-version -m machine -p processor -i hardware-platform -o operating-system EOF exit 0 } CMD='' if [ -n "$1" ]; then case "$1" in -v|--version) version ;; -h|--help) usage ;; install|reinstall|uninstall) CMD=$1 shift ;; *) fail "The command $1 is not supported." ;; esac else usage fi check_root if [ "$CMD" = "reinstall" ] || [ "$CMD" = "uninstall" ]; then uninstall fi if [ "$CMD" = "reinstall" ] || [ "$CMD" = "install" ]; then S="$($REAL_UNAME -s)" N="$($REAL_UNAME -n)" R="$($REAL_UNAME -r)" V="$($REAL_UNAME -v)" M="$($REAL_UNAME -m)" P="$($REAL_UNAME -p)" I="$($REAL_UNAME -i)" O="$($REAL_UNAME -o)" while [ -n "$1" ]; do case "$1" in -v|--version) version ;; -h|--help) usage ;; -s) shift S="$1" ;; -n) shift N="$1" ;; -r) shift R="$1" ;; -v) shift V="$1" ;; -m) shift M="$1" ;; -p) shift P="$1" ;; -i) shift I="$1" ;; -o) shift O="$1" ;; *) fail "The option $1 is not supported." ;; esac shift done install "$S" "$N" "$R" "$V" "$M" "$P" "$I" "$O" fi uname -a