Find the answer to your Linux question:
Page 4 of 4 FirstFirst 1 2 3 4
Results 31 to 33 of 33
I assume you are sure that the destination .exe files (or whatever the .lnk's point to) do exist under the correct location....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #31
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513

    I assume you are sure that the destination .exe files (or whatever the .lnk's point to) do exist under the correct location.

  2. #32
    Just Joined!
    Join Date
    Nov 2010
    Location
    Philippines
    Posts
    29
    But these targets certainly do exist.
    Another sed target issue?

    ./lnk2sym ~/.wine/dosdevices/g:/lnks Test ~/.wine/dosdevices/g:/

    Where to look for .lnk files:
    "/home/scribe/.wine/dosdevices/g:/lnks"
    Where to look put symlinks:
    "Test"
    The DOS base drive is:
    "/home/scribe/.wine/dosdevices/g:/"

    Finding files, this may take a while...
    [*] Found: "/home/scribe/.wine/dosdevices/g:/lnks/ExecDirectNewProj (on I).lnk"
    [i] The candidate file string is:
    [i] "/home/scribe/.wine/dosdevices/g://
    /home/scribe/.wine/dosdevices/g://I/Tim/FB/Exec. Direct/Projects/New"
    [E] This .lnk file points to a file that doesn't exist.
    [E] Couldn't create this symlink, sorry.[*] Found: "/home/scribe/.wine/dosdevices/g:/lnks/I (Gold).lnk"
    [i] The candidate file string is:
    [i] "/home/scribe/.wine/dosdevices/g://
    /home/scribe/.wine/dosdevices/g://I"
    [E] This .lnk file points to a file that doesn't exist.
    [E] Couldn't create this symlink, sorry.[*] Found: "/home/scribe/.wine/dosdevices/g:/lnks/Images 2009.lnk"
    [i] The candidate file string is:
    [i] "/home/scribe/.wine/dosdevices/g://"
    [i] Running: ln -nfs "/home/scribe/.wine/dosdevices/g://" "Test/g:"[*] Found: "/home/scribe/.wine/dosdevices/g:/lnks/J (installs).lnk"
    [i] The candidate file string is:
    [i] "/home/scribe/.wine/dosdevices/g://
    /home/scribe/.wine/dosdevices/g://J/Installs/_shortcuts"
    [E] This .lnk file points to a file that doesn't exist.
    [E] Couldn't create this symlink, sorry.[*] Found: "/home/scribe/.wine/dosdevices/g:/lnks/K (mp3).lnk"
    [i] The candidate file string is:
    [i] "/home/scribe/.wine/dosdevices/g://
    /home/scribe/.wine/dosdevices/g://K/_MP3 Genre'"
    [E] This .lnk file points to a file that doesn't exist.
    [E] Couldn't create this symlink, sorry.

  3. #33
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    There were a few issues here, mostly minor ones. The biggest one was that when you specify relative paths the links are not correct unless they go in the current directory (no wonder). I solved that by using the realpath tool.

    The other issue is NOT solved, and it is probably what is hitting you. Windows is case recordable but ISN'T case sensitive. Linux IS.

    That's a problem because the paths in the lnk files might be written as "c:\myPath\", but the real path in the disk is "C:\mypath\". In linux, these are different strings. So, I am not sure the issue is solvable in a clean way. The script already makes a few assumption (something that I really dislike when programming).

    Here you are the new version nonetheless. If it fails, please, attach the bash -x output as in the other posts, so I can take a look. And, when a given path can't be found, please, also attach the "ls -l" output for that file so I can be sure it's not a case-sensivity issue.

    Code:
    #!/bin/bash
    
    ######################################################################
    #                                                                    #
    # lnk2symlink by jesus.guerrero.botella at gmail dot com,            #
    # search for windows .lnk files on a given directory, and creates    #
    # symlinks according to the info contained on those files            #
    #                                                                    #
    # This script is provided without any kind of implicit or explicit   #
    # guarantee, and is licensed under the GNU General Public License v3 #
    # or later if available. More about licenses on the following URL:   #
    #                                                                    #
    # http://www.gnu.org/licenses/licenses.html                          #
    #                                                                    #
    ######################################################################
    
    VERSION=20101220
    PROGRAM_NAME=$(basename $0)
    
    die() {
    	case $1 in
    		non_linkable_fs)
    			echo "The target filesystem doesn't support symlinks."
    			exit 11
    			;;
    		ln_error)
    			echo "Undefined error while symlinking."
    			exit 10
    			;;
    		number_of_args)
    			echo
    			echo "[E] Incorrect number of arguments."
    			echo "Usage: $0 origin_dir destination_dir dos_drive_basedir"
    			echo
    			echo " origin_directory is the directory containing the .lnk"
    			echo " files. It will be recursed."
    			echo
    			echo " destination_directory is the directory where you want"
    			echo " the symlinks to be created."
    			echo
    			echo " dos_drive_basedir is the linux directory that will be"
    			echo " used in place of \"C:\\\" (or whatever drive) when looking"
    			echo " for the link destination."
    			echo
    			echo "Typical usage case:"
    			echo " "$(basename $0)" ~/Desktop/ ~/bin/ ~/.wine/drive_c/"
    			echo
    			exit 12
    			;;
    		could_not_create_dest)
    			echo "Couldn't create destination directory."
    			exit 13
    			;;
    		orig_not_found)
    			echo "Origin directory not found or not readable."
    			exit 14
    			;;
    		could_not_create_symlink)
    			echo "Couldn't create symlink."
    			exit 15
    			;;
    		*)
    			echo "Undefined error."
    			exit 20
    			;;
    	esac
    }
    
    case $# in
    	3)
    		ORIG="$1"
    		DEST="$2"
    		DOS_DRIVE="$3"
    		;;
    	*)
    		die number_of_args
    		;;
    esac
    
    # Test for the existence of the required directories
    [ ! -d "$DEST" ] && mkdir "$DEST"
    [ ! -d "$DEST" ] && die could_not_create_dest
    [ ! -d "$ORIG" ] && die orig_not_found
    
    # Test the symlinking tool, if it fails then probably
    # your FS doesn't support soft links.
    TESTLN="$DEST/test-$RANDOM$RANDOM$RANDOM$RANDOM"
    ln -s "$HOME" "$TESTLN" > /dev/null 2>&1 || die non_linkable_fs
    rm -f "$TESTLN"
    
    echo
    echo "Where to look for .lnk files:"
    echo "  \"$ORIG\""
    echo "Where to look put symlinks:"
    echo "  \"$DEST\""
    echo "The DOS base drive is:"
    echo "  \"$DOS_DRIVE\""
    echo
    echo "Finding files, this may take a while..."
    echo
    
    find "$ORIG" -iname '*.lnk' | while read LNK_FILE
    do
    	echo
    	echo "[*] Found: \"$LNK_FILE\""
    
    	CANDIDATE_STRING=$(strings "$LNK_FILE" | grep ':\\')
    	LINUX_PATH_TO_EXE_FILE=$(echo "$CANDIDATE_STRING" | \
    		tail -n1 | \
    		sed -e 's#.*[a-zA-Z]:\\#'"$DOS_DRIVE"'/#' | \
    		sed -e 's#\\#/#g' | \
    		sed -e 's#//#/#g' )
    	LINUX_PATH_TO_EXE_FILE=$(realpath "$LINUX_PATH_TO_EXE_FILE")
    		echo "[i] The candidate file string is:"
    		echo "[i] \"$LINUX_PATH_TO_EXE_FILE\""
    
    	SYMLINK_NAME="$DEST"/$(basename "$LINUX_PATH_TO_EXE_FILE")
    	if [ ! -L "$SYMLINK_NAME" ]; then
    		if [ -r "$SYMLINK_NAME" ]; then
    			echo "[i] File with the same name detected, but it's not a symlink."
    			echo "[i] I will add a RANDOM suffix to the symlink name."
    			SYMLINK_NAME="${SYMLINK_NAME}-${RANDOM}"
    		fi
    	fi
    	if [ -r "$LINUX_PATH_TO_EXE_FILE" ]; then
    		echo "[i] Running: ln -nfs \"$LINUX_PATH_TO_EXE_FILE\" \"$SYMLINK_NAME\""
    		ln -nfs "$LINUX_PATH_TO_EXE_FILE" "$SYMLINK_NAME" || die could_not_symlink
    	else
    		echo "[E] This .lnk file points to a file that doesn't exist."
    		echo "[E] Couldn't create this symlink, sorry."
    	fi
    done

  4. $spacer_open
    $spacer_close
Page 4 of 4 FirstFirst 1 2 3 4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •