Thread: Bash Uploader For LuckyShare v1.31023

Status
Not open for further replies.

Peter South

Active Member
607
2013
360
1,690
This is an updated version of my previously shared LuckyShare Bash Upload script that I posted in this post: Thread: Bash Uploader For LuckyShare v1.30923

This new version handles files that exceed the max file size limit by creating a Split RAR archive of them. In the configuration settings you can specify the max file size limit (default is left at 2048MB, 2GB which is the limit for Premium Uploaders). When the script encounters a file > 2GB in size it rars it into 2GB split parts and deletes the original file, it then uploads the parts.

Also integrated is the same code from my post "Bash Script: Scramble checksum hash values of all files in current directory". This automatically changes the checksum hash value of file(s) being uploaded to prevent blocked files from future uploads. It does not impact the integrity of any type of file including split RAR archives as it simply echos a random 5 digit integer into the end of the files.

Lastly, this version of the script provides some integration for both of my two versions of the Video Contact Sheet Generator & ImgChili Uploader Scripts. So if you're using those scripts as well it will display Video's [BBCode] in the terminal shell above the [BBCode] generated for the LuckyShare links.

Please Note: My Contact Sheet Generator & ImgChili Uploader Scripts are not a dependency for this script as the script checks to see if there is a ImgChiliLinks.txt file left over from the other script and only works with it if it exists, otherwise it keeps running as normal.

Code:
#!/bin/bash# Bash Uploader For LuckyShare v1.31023
# /usr/local/bin/luckyShareUploader.sh
# Dependencies:
#   1. cURL | Ubuntu 12.04LTS: apt-get install libcurl3 -y;
#   2. rar  | Ubuntu 12.04LTS: apt-get install rar -y;
# Scope:
#   1. Randomly scrambles the checksum hash values of all files in current directory
#   2. Uploads all files in a directory to an account on LuckyShare.net
####################################################################################################
#                                      CONFIGURATION SETTINGS                                      #
####################################################################################################
# Configure the following with your credentials between the ' ' marks.
user='';
pass='';
# Configure file size limitation in value of MBs, for premium accounts use: fileSizeLimit=2048;
fileSizeLimit=2048;
####################################################################################################
#                                              SCRIPT                                              #
####################################################################################################
echo "############################################";
echo "# Bash File Upload For LuckyShare v1.31023 #";
echo "# Written by SpecialEd @ irc.fileguide.org #";
echo "############################################";
####################################################################################################
#Scrambles the md5 checksum hash values for all files in directory.
touch ./'$filename'
for filename in ./*; do
  if [ "$filename" != "$0" ]
  then
    if [ "$filename" != ./imgChiliLinks.txt ]
      then
        echo $RANDOM >> "$filename";
    fi
  fi
done;
rm ./'$filename' 2> /dev/null;
####################################################################################################
#Checks for file sizes > LuckyShare's File Size Limit (configured above) and splits them into parts.
for file in ./*; do
  fileExtension=`ls $file | cut -c3-`;
  fileName=`ls $file | sed 's/\.\///'`;
  if [[ $fileExtension == *.txt ]]; then
    echo " " 2> /dev/null;
  fi
  if [[ $fileExtension != *.txt ]]; then
    fileSize=$(stat -c%s $file);
    if [[ $fileSize -gt 2147483648 ]]; then
      echo $fileName" exceeds the size limit of "$fileSizeLimit"MB, splitting file 2GB parts...";
      rar a $file.rar $file -v2048M; rm $file;
    fi
        if [[ $fileSize -lt 2147483648 ]]; then
      echo $fileName" is less than max file size of "$fileSizeLimit"MB, continuing...";
        fi
  fi
done;
####################################################################################################
#Uploads the files
touch .ls.tmp;
for file in ./*; do
  fileExtension=`ls $file | cut -c3-`;
  fileName=`ls $file | sed 's/\.\///'`;
  if [[ $fileExtension == *.txt ]]; then
    echo "Skipping "$fileName"...";
  fi
  if [[ $fileExtension != *.txt ]]; then
    uploadTicket=`curl -s http://luckyshare.net/api/getuploadurl/user/$user/pass/$pass`;
    ls -lh $file | awk {'print $9'} | xargs -n1 -i curl -s -F "file=@./{}" $uploadTicket>>.ls.tmp;
        # Stops the script if an upload fails
    if grep -Fxq "Application Error: Failed to contact core server." ./.ls.tmp; then
      echo "Upload of "$file" failed, trying again...";
      uploadTicket=`curl -s http://luckyshare.net/api/getuploadurl/user/$user/pass/$pass`;
      ls -lh $file | awk {'print $9'} | xargs -n1 -i curl -s -F "file=@./{}" $uploadTicket>>.ls.tmp;
      if grep -Fxq "Application Error: Failed to contact core server." ./.ls.tmp; then
        echo "Upload of "$file" failed, moving to ./failedUploads/";
        mkdir failedUploads 2> /dev/null;
        mv $file ./failedUploads/;
      fi;
    fi;
  fi;
  # Parses the .ls.tmp file and outputs [BBCode] formatted links to the terminal shell.
  cat .ls.tmp >> .ls.swp;
  cat .ls.swp \
  | sed 's/./&\ /33;s/./]/34;s/^/\[B\]LuckyShare\:\ \[\/B\]\[URL\=/;s/$/\[\/URL\]/;s/$/\n/' \
  >> LuckyShareLinks.txt; rm .ls.swp .ls.tmp 2> /dev/null;
done;
####################################################################################################
# Displays the [BBCode] links in the terminal shell
for file in ./*; do
  bbCodeFileName=`ls $file | sed 's/\.\///'`;
  if [[ $bbCodeFileName == "imgChiliLinks.txt" ]]; then
    cat imgChiliLinks.txt;
  fi
done;
cat LuckyShareLinks.txt
#Counts the number of links generated and display with number of files in current directory.
numFiles=`ls ./* | grep -v \.txt | wc -l`;
numLinks=`cat ./LuckyShareLinks.txt | wc -l`;
echo "Number of files in this directory: "$numFiles;
echo "Total # LuckyShare URLs generated: "$numLinks;

For more of my scripts see: Index of various Bash Script Threads contributed by Eddie Johnson.
 
Last edited:
Status
Not open for further replies.
Back
Top