From bc56d430ed4f7eb77355cd3db871d7a7078d051b Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 29 Apr 2010 00:41:32 +0200 Subject: [PATCH] Fix bashism/non-POSIX usage of $UID. --- sbin/grml-ap | 2 +- sbin/grml-bridge | 2 +- sbin/grml-network | 5 ++--- sbin/grml-pptp-inode | 7 +++---- sbin/grml-pptp-vcgraz | 4 ++-- sbin/grml-pptp-xdsl-students | 4 ++-- sbin/grml-router | 5 +---- sbin/grml-vnet | 3 +++ sbin/grml-vpnc-tugraz | 2 +- sbin/modemlink | 5 ++--- sbin/netcardconfig | 2 +- 11 files changed, 19 insertions(+), 22 deletions(-) diff --git a/sbin/grml-ap b/sbin/grml-ap index a6c4f62..1fc24b1 100755 --- a/sbin/grml-ap +++ b/sbin/grml-ap @@ -14,7 +14,7 @@ CONFIG_FILE=/etc/grml/routersetup . /etc/grml/net-functions . /etc/grml/script-functions -check4root +check4root || exit 1 if ! [ -r "$CONFIG_FILE" ] ; then eerror "$CONFIG_FILE could not be read." diff --git a/sbin/grml-bridge b/sbin/grml-bridge index 9ee19ab..93e6686 100755 --- a/sbin/grml-bridge +++ b/sbin/grml-bridge @@ -10,7 +10,7 @@ CONFIG_FILE=/etc/grml/routersetup . /etc/grml/lsb-functions . /etc/grml/script-functions -check4root +check4root || exit 1 if ! [ -r "$CONFIG_FILE" ] ; then eerror "$CONFIG_FILE could not be read." diff --git a/sbin/grml-network b/sbin/grml-network index 617c272..46393a6 100755 --- a/sbin/grml-network +++ b/sbin/grml-network @@ -9,9 +9,8 @@ PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin" export PATH -if [ $UID != 0 ] ; then - echo Error: become root before starting $0 >& 2 - exit 100 +if [ $(id -ru) -ne 0 ] ; then + echo 1>&2 "Error: please run this script with uid 0 (root)." ; exit 1 fi # XDIALOG_HIGH_DIALOG_COMPAT=1 diff --git a/sbin/grml-pptp-inode b/sbin/grml-pptp-inode index 3c61d33..abef059 100755 --- a/sbin/grml-pptp-inode +++ b/sbin/grml-pptp-inode @@ -14,9 +14,8 @@ export LANG=C -if [ $UID != 0 ] ; then - echo Error: become root before starting $0 >& 2 - exit 100 +if [ $(id -ru) -ne 0 ] ; then + echo 1>&2 "Error: please run this script with uid 0 (root)." ; exit 1 fi if [ -z "$FORCE_OLD" ] ; then @@ -46,7 +45,7 @@ EOF echo "${VPNUSERNAME} XDSL ${VPNPASSWORD} *" >> /etc/ppp/pap-secrets chmod 0600 /etc/ppp/pap-secrets -echo -e "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\n" > /etc/init.d/pptp +printf "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\n" > /etc/init.d/pptp cat >> /etc/init.d/pptp << "EOF" diff --git a/sbin/grml-pptp-vcgraz b/sbin/grml-pptp-vcgraz index fc2f6c7..b1fe498 100755 --- a/sbin/grml-pptp-vcgraz +++ b/sbin/grml-pptp-vcgraz @@ -15,7 +15,7 @@ export LANG=C export LC_ALL=C -if [ "$UID" != 0 ]; then +if [ $(id -ru) -ne 0 ] ; then sudo $0 exit fi @@ -51,7 +51,7 @@ chmod 600 /etc/ppp/chap-secrets # don't overwrite existing files - so just append: echo "${VPNUSERNAME} PPTP ${VPNPASSWORD} *" >> /etc/ppp/chap-secrets -echo -e "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\nDORMITORY=\"${DORMITORY}\"" > /etc/init.d/pptp-vcgraz +printf "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\nDORMITORY=\"${DORMITORY}\"" > /etc/init.d/pptp-vcgraz cat >> /etc/init.d/pptp-vcgraz << "EOF" # connect to vc-graz via pptp case "$1" in diff --git a/sbin/grml-pptp-xdsl-students b/sbin/grml-pptp-xdsl-students index 9a26a6b..e135528 100755 --- a/sbin/grml-pptp-xdsl-students +++ b/sbin/grml-pptp-xdsl-students @@ -17,7 +17,7 @@ export LANG=C DIALOG="dialog" -if [ "$UID" != 0 ]; then +if [ $(id -ru) -ne 0 ] ; then sudo $0 exit fi @@ -64,7 +64,7 @@ EOF echo "${VPNUSERNAME} XDSL ${VPNPASSWORD} *" >> /etc/ppp/pap-secrets chmod 0600 /etc/ppp/pap-secrets -echo -e "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\n" > /etc/init.d/pptp +printf "#!/bin/sh\nLANG=C\nVPNSERVER=\"${VPNSERVER}\"\n" > /etc/init.d/pptp cat >> /etc/init.d/pptp << "EOF" diff --git a/sbin/grml-router b/sbin/grml-router index 219ae19..b959f12 100755 --- a/sbin/grml-router +++ b/sbin/grml-router @@ -11,10 +11,7 @@ CONFIG_FILE=/etc/grml/routersetup . /etc/grml/net-functions . /etc/grml/script-functions -if [ $UID != 0 ]; then - eerror "Error: become root before starting $0" - exit 100 -fi +check4root || exit 1 if ! [ -r $CONFIG_FILE ] ; then eerror "$CONFIG_FILE could not be read." diff --git a/sbin/grml-vnet b/sbin/grml-vnet index 82aca72..7fa0d95 100755 --- a/sbin/grml-vnet +++ b/sbin/grml-vnet @@ -16,6 +16,9 @@ OPT_GROUP_='' OPT_BRIDGE_='' OPT_AUTO_='false' +if [ $(id -ru) -ne 0 ] ; then + echo 1>&2 "Error: please run this script with uid 0 (root)." ; exit 1 +fi function printUsage() { diff --git a/sbin/grml-vpnc-tugraz b/sbin/grml-vpnc-tugraz index 05fa947..0fc6bf3 100755 --- a/sbin/grml-vpnc-tugraz +++ b/sbin/grml-vpnc-tugraz @@ -12,7 +12,7 @@ export LANG=C export LC_ALL=C -if [ "$UID" != 0 ]; then +if [ $(id -ru) -ne 0 ] ; then sudo $0 exit fi diff --git a/sbin/modemlink b/sbin/modemlink index 6e4599c..fa9c3b1 100755 --- a/sbin/modemlink +++ b/sbin/modemlink @@ -12,9 +12,8 @@ export PATH # XDIALOG_HIGH_DIALOG_COMPAT=1 # export XDIALOG_HIGH_DIALOG_COMPAT -if [ $UID != 0 ] ; then - echo Error: become root before starting $0 >& 2 - exit 100 +if [ "$(id -u 2>/dev/null)" != 0 ] ; then + echo 1>&2 "Error: please run this script with uid 0 (root)." ; exit 1 fi TMP=$(mktemp) diff --git a/sbin/netcardconfig b/sbin/netcardconfig index 03784a9..40252b7 100755 --- a/sbin/netcardconfig +++ b/sbin/netcardconfig @@ -15,7 +15,7 @@ LANGUAGE=C LANG=C export PATH LANGUAGE LANG . /etc/grml/script-functions -check4root +check4root || exit 1 TMP=$(mktemp) -- 2.1.4