Fix bashism/non-POSIX usage of $UID.
authorMichael Prokop <mika@grml.org>
Wed, 28 Apr 2010 22:41:32 +0000 (00:41 +0200)
committerMichael Prokop <mika@grml.org>
Wed, 28 Apr 2010 22:41:32 +0000 (00:41 +0200)
sbin/grml-ap
sbin/grml-bridge
sbin/grml-network
sbin/grml-pptp-inode
sbin/grml-pptp-vcgraz
sbin/grml-pptp-xdsl-students
sbin/grml-router
sbin/grml-vnet
sbin/grml-vpnc-tugraz
sbin/modemlink
sbin/netcardconfig

index a6c4f62..1fc24b1 100755 (executable)
@@ -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."
index 9ee19ab..93e6686 100755 (executable)
@@ -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."
index 617c272..46393a6 100755 (executable)
@@ -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
index 3c61d33..abef059 100755 (executable)
@@ -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"
 
index fc2f6c7..b1fe498 100755 (executable)
@@ -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
index 9a26a6b..e135528 100755 (executable)
@@ -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"
 
index 219ae19..b959f12 100755 (executable)
@@ -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."
index 82aca72..7fa0d95 100755 (executable)
@@ -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()
 {
index 05fa947..0fc6bf3 100755 (executable)
@@ -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
index 6e4599c..fa9c3b1 100755 (executable)
@@ -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)
index 03784a9..40252b7 100755 (executable)
@@ -15,7 +15,7 @@ LANGUAGE=C LANG=C
 export PATH LANGUAGE LANG
 
 . /etc/grml/script-functions
-check4root
+check4root || exit 1
 
 TMP=$(mktemp)