Browse Source

Added check to test if the user is root

Matteo Zeccoli Marazzini 1 year ago
parent
commit
9f8c0b3735
4 changed files with 7 additions and 0 deletions
  1. 1 0
      README
  2. 1 0
      error.sh
  3. 4 0
      newdisk-automator
  4. 1 0
      parse-arguments.sh

+ 1 - 0
README

@@ -42,3 +42,4 @@ Error codes:
 32 Device is smaller than the manually specified size
 
 40 One of the programs called from the script returned a non 0 value. Check the stderr to get the code
+41 The effective user id of the calling user is not 0. Only root can run this tool

+ 1 - 0
error.sh

@@ -17,6 +17,7 @@ BESTSIZE_E=31
 MANUALSIZE_E=32
 
 PROG_E=40
+NOROOT_E=41
 
 fatal()
 {

+ 4 - 0
newdisk-automator

@@ -8,6 +8,10 @@ PROGRAM_NAME="$0"
 . "${DIR}/conversion.sh"
 . "${DIR}/check-device.sh"
 
+if [ ${EUID} -ne 0 ]; then
+    fatal $NOROOT_E "must be root to run this program"
+fi
+
 parse_arguments $@
 
 # removing lvm and other filesystem signatures

+ 1 - 0
parse-arguments.sh

@@ -121,6 +121,7 @@ help()
 			32 Device is smaller than the manually specified size
 			
 			40 One of the programs called from the script returned a non 0 value. Check the stderr to get the code
+			41 The effective user id of the calling user is not 0. Only root can run this tool
 		error-end
 	fi
 }