Advertisement
Guest User

SrcDS-Linker.sh

a guest
Jan 26th, 2011
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.21 KB | None | 0 0
  1. #!/bin/bash
  2. LOGDIR="${HOME}/SrcDS_Ln_Log";
  3. while getopts "d:" optname
  4. do
  5.     case "$optname" in
  6.         "d")
  7.             LOGDIR="$OPTARG";
  8.         ;;
  9.         "?")
  10.             echo "Unknown option $OPTARG";
  11.         ;;
  12.     esac
  13. done
  14. LOGFILE="${LOGDIR}/SrcDS_Linker_$(date +"%F")-$(date +"%T").log";
  15. args=("$@");
  16. nr=$#-1;
  17. MAKE=${args[$nr]};
  18. if [ ! -d "$LOGDIR" ]; then
  19.     mkdir -p $LOGDIR;
  20. fi
  21.  
  22. echo "Logfile:  ${LOGFILE}";
  23. echo "===LOG START===" >> $LOGFILE;
  24. self=`basename "$0"`;
  25. case $MAKE in
  26.     "create")
  27.         find ./* |while read FILENAME
  28.         do
  29.             i=${FILENAME};
  30.             o=`echo ${i}|rev`;
  31.             l=`echo ${o%.}|rev`;
  32.             j=`echo ${l}|rev`;
  33.             k=`echo ${j%.*}|rev`;
  34.             c=`basename "$l"`;         
  35.             case $l in
  36.             "/$self")
  37.                                 echo -e '\E[32;40m'"Omitting $self";tput sgr0;
  38.                 echo "Omitting $self" >> $LOGFILE;
  39.                         ;;
  40.             *.*)
  41.                 #Commented out for a little lett console print, will still be logged.
  42.                 #echo "Make Symlink from FILE- $i ---> .$(echo ${l%.*} | tr [:lower:] [:upper:]).$k";
  43.                 ln -s "./$c" ".$(echo ${l%.*} | tr [:lower:] [:upper:]).$k";
  44.                 echo "./$c .$(echo ${l%.*} | tr [:lower:] [:upper:]).$k" >> $LOGFILE;
  45.             ;;
  46.             *)
  47.                 echo -e 'Make Symlink from \E[34m\E[34mDIR--'`tput sgr0` "$i ---> .`echo "$l" | tr [:lower:] [:upper:]`";
  48.                 ln -s "./$c" "`echo .$l | tr [:lower:] [:upper:]`";
  49.                 echo "./$c `echo .$l | tr [:lower:] [:upper:]`" >> $LOGFILE;
  50.             ;;
  51.             esac
  52.        
  53.         done
  54.         echo "===LOG END===" >> $LOGFILE;
  55.     ;;
  56.     "test")
  57.         echo "Test Run!!!!!!" >> $LOGFILE;
  58.         find ./* |while read FILENAME
  59.             do
  60.             i=${FILENAME};
  61.             o=`echo ${i}|rev`;
  62.                     l=`echo ${o%.}|rev`;
  63.             j=`echo ${l}|rev`;
  64.                     k=`echo ${j%.*}|rev`;
  65.                     c=`basename "$l"`;
  66.                     case $l in
  67.                     "/$self")
  68.                                 echo -e '\E[32;40m'"Omitting $self";tput sgr0;
  69.                                 echo "Omitting $self" >> $LOGFILE;
  70.                         ;;
  71.  
  72.                 *.*)
  73.                                 echo "FILE- $i" ".$(echo ${l%.*} | tr [:lower:] [:upper:]).$k";
  74.                     echo "./$c .$(echo ${l%.*} | tr [:lower:] [:upper:]).$k" >> $LOGFILE;
  75.                    
  76.                 ;;
  77.                 *)
  78.                                 echo -e  '\E[34m\E[34mDIR--'`tput sgr0` "$i .`echo "$l" | tr [:lower:] [:upper:]`";
  79.                     echo "./$c $(echo .$l | tr [:lower:] [:upper:])" >> $LOGFILE;
  80.                         ;;
  81.                     esac
  82.             done
  83.         echo "===LOG END===" >> $LOGFILE;
  84.     ;;
  85.     *)
  86.         echo -e "\v";
  87.         echo '****************************************************************************************'
  88.         echo "Usage: ./`basename "$0"` create|test [-d FILE]";
  89.         echo -e "\n\n\"create\" starts the creation of symbolic links in current directory.";
  90.         echo "It will go into subfolders and continue there until all subdirectories are included";
  91.         echo -e "Do no use create without testing first.\v";
  92.         echo "\"test\" will list all the files and folders that will be linked";
  93.         echo "it will show the TARGET and LINK names and placement.";
  94.         echo "Recomended to use before using the create function.";
  95.         echo "Also recomended to read the log output of this before";
  96.         echo -e "using the create function\v\v";
  97.         echo "This is ment for usage with the GNU/Linux and Src Dedicated Server";
  98.         echo "\"Failed to load \$include\" problem. This problem is caused due";
  99.         echo "to Linux being case sensitive and the server looking for files and";
  100.         echo "folders that are in UPPERCASE letters tho they have been downloaded";
  101.         echo "and named in lowercase letters. This means they are not the same files";
  102.         echo -e "as the ones being looked for.\n\n";
  103.         echo "This little script is ment to correct this by making";
  104.         echo "symbolic links with the right name to the oridginale file.";
  105.         echo -e "\n\t*******************************************************************";
  106.         echo -e "\t| Log files will be created in the directory:";
  107.         echo -e "\t| $LOGDIR";
  108.         echo -e "\t| The file will be saved as";
  109.         echo -e "\t| $LOGFILE";
  110.         echo -e "\t| To change this use the \"-d /path/to/logdir\" option.\n\t|";
  111.         echo -e "\t| Make sure you have "'\E[32mwrite permissions' `tput sgr0` "for this folder and file";
  112.         echo '****************************************************************************************'
  113.     ;;
  114. esac
  115. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement