Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Mods lowercase convert is broken #1868

Closed
UltimateByte opened this issue Apr 2, 2018 · 6 comments
Closed

[BUG] Mods lowercase convert is broken #1868

UltimateByte opened this issue Apr 2, 2018 · 6 comments
Assignees
Labels
command: mods type: bug Something isn't working

Comments

@UltimateByte
Copy link
Contributor

Sample output:

/home/terageek/gmodprobuild/lgsm/mods/tmp/extract/ACF-Missiles-master was not renamed
/home/terageek/gmodprobuild/lgsm/functions/mods_core.sh: line 46: /: Is a directory
mv: cannot move '/home/terageek/gmodprobuild/lgsm/mods/tmp/extract' to '/home/terageek/gmodprobuild/lgsm/mods/tmp'$'\n''/home/terageek/gmodprobuild/lgsm/mods/tmp': No such file or directory

Need to find out why
https://github.com/GameServerManagers/LinuxGSM/blob/master/lgsm/functions/mods_core.sh#L37-L66

@UltimateByte UltimateByte added type: bug Something isn't working Status: dev queue labels Apr 2, 2018
@JediNarwals
Copy link

Personally I use the command "convmv" to change the case of all my files. My line goes like this:

convmv --lower -r --replace --notest ~/pathToFolderForConversion/

Note you will need to have the command "convmv" installed before use with "sudo apt install convmv"

@Chillstice
Copy link

Chillstice commented Dec 18, 2018

Please expedite this fix. It took me a couple days to realize that my offline (non-repository) addons weren't loading due to uppercase letters in the filenames. I would also like to suggest adding this knowledge to the FAQ or in the guides to prevent future headaches.

Throwing an exception/error might also be a good idea.

@dgibbs64 dgibbs64 removed type: bug Something isn't working status: hold labels Feb 1, 2019
@dgibbs64 dgibbs64 added command: mods type: feature request New feature or request type: bug Something isn't working and removed type: feature request New feature or request labels Jun 21, 2019
@UltimateByte
Copy link
Contributor Author

UltimateByte commented Dec 17, 2021

Rewrote the function and seems to work mostly fine.

# Convert mod files to lowercase if needed.
fn_mod_lowercase(){
        if [ "${modlowercase}" == "LowercaseOn" ]; then
                echo -en "converting ${modprettyname} files to lowercase..."
                fn_sleep_time
                fn_script_log_info "Converting ${modprettyname} files to lowercase"
                # Total files and directories
                fileswc=$(find "${extractdir}" | wc -l)
                # Total uppercase files and directories
                filesupperwc=$(find "${extractdir}" -name '*[[:upper:]]*' | wc -l)
                fn_script_log_info "Found ${filesupperwc} uppercase files out of ${filesupperwc}"
                fn_print_dots_nl "Converting ${filesupperwc} uppercase files out of ${filesupperwc}"
                echo -en "\r"
                # Convert files and directories starting from the deepest to prevent issues (-depth argument)
                while read -r src; do
                        # 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
                        # Print latest path
                        latestpath=$(echo "${src}" | awk -F '/' '{print ($NF)}')
                        # Convert latest path to lowercase
                        latestpathlc=$(echo "${latestpath}" | tr [:upper:] [:lower:])
                        # Use sed to set our destination by replacing latest occurrence of latestpath to lowercase latestpathlc
                        dst=$(echo "${src}" | sed -e "s:${latestpath}\([^${latestpath}]*\)$:${latestpathlc}\1:")
                        # 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=$?
                                if [ "${exitcode}" != 0 ]; then
                                        fn_print_fail_eol_nl
                                        core_exit.sh
                                fi
                        fi
                done < <(find "${extractdir}" -depth -name '*[[:upper:]]*')
                fn_print_ok_eol_nl
        core_exit.sh
        fi
}

Only problem is it fails with files with "-" dashes characters.

Example:

# mkdir "/home/youruser/TEST-master"
# source="TEST-master" ; dest="test-master" ; find /home/youruser/ -depth -type d -name '*[[:upper:]]*' | grep "TEST" | sed -e "s:${source}([^${source}]*)$:${dest}\1:"
sed: -e expression #1, char 46: Invalid range end

No idea how to resolve this for now, been trying for an hour.
I'll have to see later. If anyone has an idea, you're welcome to help.

@UltimateByte
Copy link
Contributor Author

Can't figure this out without extended practice with sed.
Stackoverflow question: https://stackoverflow.com/questions/70400408/sed-cant-replace-latest-text-occurrence-including-dashes-using-variables

@UltimateByte
Copy link
Contributor Author

Lesson of the day:
If strugling with sed, there must be an easier way without sed.
Pull request incoming.

UltimateByte added a commit to UltimateByte/LinuxGSM that referenced this issue Dec 18, 2021
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
jusito pushed a commit to jusito/LinuxGSM that referenced this issue Aug 24, 2022
…agers#3717)

* Finally fixes GameServerManagers#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
@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
command: mods type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants