Explorar el Código

fix: #1868 mods lowercase conversion (#3717)

* Finally fixes #1868 mods lowercase conversion 

Sample output:
Installing DarkRP
=================================
creating mod download directory /home/ulti/lgsm/mods/tmp...OK
                                #=#=-  #       #                                                                                                                                                                                                       ################################################################################################################################################################################################################################################ 100.0%   -#O=-   #         #           #                                                                                                                                                                                                                    
extracting darkrp-master.zip...OK
converting DarkRP files to lowercase...Found 19 uppercase files out of 588, converting...OK
building darkrp-files.txt...OK
copying DarkRP to /home/ulti/serverfiles/garrysmod/gamemodes...OK
tidy up darkrp-files.txt...OK
clearing mod download directory /home/ulti/lgsm/mods/tmp...OK
DarkRP installed

* removed unused variable
UltimateByte hace 4 años
padre
commit
de6240fd0c
Se han modificado 1 ficheros con 25 adiciones y 19 borrados
  1. 25 19
      lgsm/functions/mods_core.sh

+ 25 - 19
lgsm/functions/mods_core.sh

@@ -33,33 +33,39 @@ fn_mod_install_files(){
 
 
 # Convert mod files to lowercase if needed.
 # Convert mod files to lowercase if needed.
 fn_mod_lowercase(){
 fn_mod_lowercase(){
+	# Checking lowercase settings from mods array definition
 	if [ "${modlowercase}" == "LowercaseOn" ]; then
 	if [ "${modlowercase}" == "LowercaseOn" ]; then
-
 		echo -en "converting ${modprettyname} files to lowercase..."
 		echo -en "converting ${modprettyname} files to lowercase..."
 		fn_sleep_time
 		fn_sleep_time
 		fn_script_log_info "Converting ${modprettyname} files to lowercase"
 		fn_script_log_info "Converting ${modprettyname} files to lowercase"
-		fileswc=$(find "${extractdir}" -depth | wc -l)
-		echo -en "\r"
+		# Total files and directories for the mod, to output to the user
+		fileswc=$(find "${extractdir}" | wc -l)
+		# Total uppercase files and directories for the mod, to output to the user
+		filesupperwc=$(find "${extractdir}" -name '*[[:upper:]]*' | wc -l)
+		fn_script_log_info "Found ${filesupperwc} uppercase files out of ${fileswc}, converting"
+		echo -en "Found ${filesupperwc} uppercase files out of ${fileswc}, converting..."
+		# Convert files and directories starting from the deepest to prevent issues (-depth argument)
 		while read -r src; do
 		while read -r src; do
-			dst=$(dirname "${src}$(/)basename" "${src}" | tr '[:upper:]' '[:lower:]')
-			if [ "${src}" != "${dst}" ]
-			then
-				[ ! -e "${dst}" ] && mv -T "${src}" "${dst}" || echo -e "${src} was not renamed"
+			# We have to convert only the last file from the path, otherwise we will fail to convert anything if a parent dir has any uppercase
+			# therefore, we have to separate the end of the filename to only lowercase it rather than the whole line
+			# Gather parent dir, filename lowercase filename, and set lowercase destination name
+			latestparentdir=$(dirname "${src}")
+			latestfilelc=$(basename "${src}" | tr '[:upper:]' '[:lower:]')
+			dst="${latestparentdir}/${latestfilelc}"
+			# Only convert if destination does not already exist for some reason
+			if [ ! -e "${dst}" ]; then
+				# Finally we can rename the file
+				mv "${src}" "${dst}"
+				# Exit if it fails for any reason
 				local exitcode=$?
 				local exitcode=$?
-				((renamedwc++))
+				if [ "${exitcode}" != 0 ]; then
+					fn_print_fail_eol_nl
+					core_exit.sh
+				fi
 			fi
 			fi
-			echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..." $'\r'
-			((totalfileswc++))
-		done < <(find "${extractdir}" -depth)
-		echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..."
-
-		if [ "${exitcode}" != 0 ]; then
-			fn_print_fail_eol_nl
-			core_exit.sh
-		else
+			done < <(find "${extractdir}" -depth -name '*[[:upper:]]*')
 			fn_print_ok_eol_nl
 			fn_print_ok_eol_nl
-		fi
-	fi
+        fi
 }
 }
 
 
 # Create ${modcommand}-files.txt containing the full extracted file/directory list.
 # Create ${modcommand}-files.txt containing the full extracted file/directory list.