Browse Source

Updated method init

Paolo Galli 4 years ago
parent
commit
35c5a37c2d
1 changed files with 64 additions and 15 deletions
  1. 64 15
      lcmlog-server-utils

+ 64 - 15
lcmlog-server-utils

@@ -24,7 +24,7 @@ method_help()
 	echo "Usage: $0 [option]"
 	echo
 	echo "Options:"
-	echo "  -i  Initialization of the auth folder structure in default directory ($DIR) (authinit)"
+	echo "  -i  Initialization of the folder structure in default directory ($DIR) (init)"
 	echo "  -l  See who is authorized using getent (authlookup)"
 	echo "  -h  Show this help"
 }
@@ -33,24 +33,73 @@ method_help()
 ######
 
 
-method_authinit()
+method_init()
 {
 	if ! [ -d $DIR ]; then
 		echo "Folder $DIR not present: you should create it first!"
 		exit 0
-	elif [ -d $DIR/auth ]; then
-		echo "Folder $DIR/auth already present. Exit."
-		exit 0
 	else
-		mkdir $DIR/auth
-		touch $DIR/auth/UPDATE
-		mkdir $DIR/auth/150
-		touch $DIR/auth/150/GET
-		touch $DIR/auth/150/POST
-		mkdir $DIR/auth/Admin
-		touch $DIR/auth/Admin/GET
-		touch $DIR/auth/Admin/POST
-		echo "Completed."
+		# auth folder
+		if [ -d $DIR/auth ]; then
+			echo "Folder $DIR/auth already present. Exit."
+		else
+			mkdir $DIR/auth
+			touch $DIR/auth/UPDATE
+			mkdir $DIR/auth/150
+			touch $DIR/auth/150/GET
+			touch $DIR/auth/150/POST
+			mkdir $DIR/auth/Admin
+			touch $DIR/auth/Admin/GET
+			touch $DIR/auth/Admin/POST
+			echo "Completed."
+		fi
+
+		# data folder
+		if [ -d $DIR/data ]; then
+			echo "Folder $DIR/data already present. Exit."
+		else
+			mkdir $DIR/data
+			echo "Completed."
+		fi
+
+		# logs folder
+		if [ -d $DIR/logs ]; then
+			echo "Folder $DIR/logs already present. Exit."
+		else
+			mkdir $DIR/logs
+			echo "Completed."
+		fi
+
+		# chmod to let everyone write their logs
+		echo "To correct run the program, you should set the following permissions:"
+		echo "  755 for $(cd $DIR/.. && pwd) , $DIR and $DIR/auth"
+		echo "  777 for $DIR/data and $DIR/logs"
+
+		echo "Do you want to set these permissions (chmod)? [y|n]"
+
+		read ANSWER
+		while [ -z $ANSWER ]; do
+			echo "Yes (y) or no (n)? "
+			read ANSWER
+		done
+
+		while [ $ANSWER != "y" ] && [ $ANSWER != "n" ]; do
+			echo "Yes (y) or no (n)? "
+			read ANSWER
+
+			while [ -z $ANSWER ]; do
+				echo  "Yes (y) or no (n)? "
+				read ANSWER
+			done
+		done
+
+		if [ $ANSWER == "y" ]; then
+			chmod 755 $DIR/..
+			chmod 755 $DIR
+			chmod 755 $DIR/auth
+			chmod 777 $DIR/data
+			chmod 777 $DIR/logs
+		fi
 	fi
 }
 
@@ -119,7 +168,7 @@ fi
 # Select method from the option
 while getopts ":ilh" o; do
 	case $o in
-		i) method_authinit;;
+		i) method_init;;
 		l) method_authlookup;;
 		h) method_help;;
 		\?) usage && exit 1;;