Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # fileBoomUploader.sh
- version="2.014.07.04";
- ####################################################################################################
- # Uploads all files in a directory to FileBoom
- #
- # Dependencies:
- # 1. jq - Command-line JSON processor
- # To install on Ubuntu:
- # cd ~; git clone https://github.com/stedolan/jq.git; cd jq; autoreconf -i; ./configure; \
- # make && make install;
- # 2. curl - client-side URL transfer library
- # To install on Ubuntu:
- # apt-get install libcurl3
- ####################################################################################################
- # CONFIGURATION SETTINGS #
- ####################################################################################################
- # Configure the following with your credentials between the " " marks.
- # user is in the form of the email address used for your FileBoom account.
- user=""
- # FileBoom password must contain only alphanumeric characters (No special characters: !@#$%^&*)
- password=""
- # In either the FileBoom, Keep2Share,MoneyPlatform.biz, or Publish2.me click tab entitled My Files.
- # Then open the FileBoom folder you wish to upload into in a new tab.
- # The new tab's URL bar displays the 13 character folder_id value, such as: ..."?folder=abcdefghijklm"
- # Insert this 13 character folder_id between the "" marks below.
- folder="";
- # Enable/Disable scrambleChecksumHashValues (one of the following must be #commented out):
- scrambleChecksumHashValues="0"; # Enable md5 checksum hash scrambling of all files
- #scrambleChecksumHashValues="1"; # Disable md5 checksum hash scrambling of all files
- # Specify the number of attempts to try to re-upload files if they fail to upload. (default=5)
- uploadRetryLimit=5;
- ####################################################################################################
- # SCRIPT #
- ####################################################################################################
- clear; yellow=$(tput setaf 3); green=$(tput setaf 2); red=$(tput setaf 1); cyan=$(tput setaf 6); textreset=$(tput sgr0); STARTTIME=$(date +%s);
- echo $cyan"################################################"${textreset};
- echo $cyan"# Bash File Upload For FileBoom v"$version" #"${textreset};
- echo $cyan"################################################"${textreset};
- echo $cyan"***********************************************************************************************************************************************************************************************"${textreset};
- url="http://keep2share.cc/api/v1/"
- ####################################################################################################
- # Check if script is already running in directory or failed to exit gracefully on last run
- if [[ -f FileBoomLinks.txt ]] || [[ -f .fileBoom.tmp ]]; then
- echo $yellow"WARNING! "${textreset}$cyan"The file FileBoomLinks.txt and/or .fileBoom.tmp have been found in this directory which indicates that this script has"${textreset};
- echo $cyan"either been run in this directory before or previously failed to complete running."${textreset};
- echo $cyan"Would you like to:"${testreset};
- echo $cyan" i - Ignore this warning (Script will append existing FileBoomLinks.txt with any new links it creates."${textreset};
- echo $cyan" d - Delete the existing FileBoomLinks.txt/.fileBoom.tmp file and continue to run this script."${textreset};
- echo $cyan" q - Quit this script altogether."${textreset};
- read -r -p $yellow"Select (i/d/q):"${textreset} userSelection;
- userSelection=${userSelection,,}
- if [[ $userSelection =~ ^(i| ) ]]; then
- echo $cyan"**************************************************************************************************************"${textreset};
- fi
- if [[ $userSelection =~ ^(d) ]]; then
- echo $cyan"Removing FileBoomLinks.txt"${textreset};
- rm FileBoomLinks.txt 2>/dev/null;
- echo $cyan"**************************************************************************************************************"${textreset};
- fi
- if [[ $userSelection =~ ^(q) ]]; then
- exit 0;
- fi
- fi
- ####################################################################################################
- # File Upload Process
- for file in ./*; do
- uploadSessionStatus="0";
- fileExtension=`echo ${file: -4} | sed 's/.*[\.]//;'`;
- fileName=`ls $file | sed 's/\.\///'`;
- while [[ $uploadSessionStatus == "0" ]]; do
- if [[ $fileExtension == "txt" ]] || [[ $fileExtension == "png" ]] || [[ $fileExtension == "jpeg" ]] || [[ $fileExtension == "jpg" ]] || [[ $fileExtension == "sh" ]]; then
- echo $yellow"SKIPPED! "${textreset}$cyan"The following file has been skipped as the file's extension is either .txt, .png, .jpg, .jpeg, or .sh:"${textreset};
- echo $cyan"$fileName"${textreset};
- echo $cyan"***********************************************************************************************************************************************************************************************"${textreset};
- uploadSessionStatus="1";
- break;
- fi
- if [[ $fileExtension != "txt" ]] && [[ $fileExtension != "png" ]] && [[ $fileExtension != "jpeg" ]] && [[ $fileExtension != "jpg" ]] && [[ $fileExtension != "sh" ]]; then
- cmd="curl -d '{\"username\":\"$user\",\"password\":\"$password\"}' "$url"login 2> .fileBoom.tmp"
- resLogin=`eval $cmd`
- function checkStatus(){
- local json=$1
- local action=$2
- status=$(echo "$json" | jq -r ".status")
- if [ "$status" == "success" ]; then
- uploadSessionStatus=1;
- else
- uploadSessionStatus=0;
- fi
- }
- auth_token=$(echo "$resLogin" | jq -r ".auth_token")
- fileExtension=`echo ${file: -4} | sed 's/.*[\.]//;'`;
- fileName=`ls $file | sed 's/\.\///'`;
- #Scrambles the md5 checksum hash values for the being uploaded (only if enabled in the configuration settings above)
- if [[ $scrambleChecksumHashValues == "0" ]]; then
- originalMD5Checksum=`md5sum $file | awk {'print $1'}`;
- echo $RANDOM >> "$file";
- newMD5Checksum=`md5sum $file | awk {'print $1'}`;
- echo $green"SUCCESS! "${textreset}$cyan"The checksum hash value for "$fileName" has been changed from "${textreset}$green$originalMD5Checksum${textreset}" to "$green$newMD5Checksum${textreset};
- fi
- fboomFileUploadAttempt=0;
- while [[ $fboomFileUploadAttempt -lt $uploadRetryLimit ]]; do
- cmd="curl -d '{\"username\":\"$user\",\"password\":\"$password\"}' "$url"login 2> .fileBoom.tmp"
- resLogin=`eval $cmd`
- checkStatus "$resLogin" "Authentacation"
- auth_token=$(echo "$resLogin" | jq -r ".auth_token");
- echo $cyan"Uploading $fileName..."${textreset};
- cmd="curl -d '{\"auth_token\":\"$auth_token\"}' "$url"GetUploadFormData 2>.fileBoom.tmp";
- resForm=`eval $cmd`;
- checkStatus "$resForm" "Getting form data";
- fileName=$file;
- form_action=$(echo "$resForm" | jq -r ".form_action");
- file_field=$(echo "$resForm" | jq -r ".file_field");
- nodeName=$(echo "$resForm" | jq -r ".form_data.nodeName");
- userId=$(echo "$resForm" | jq -r ".form_data.userId");
- expires=$(echo "$resForm" | jq -r ".form_data.expires");
- hmac=$(echo "$resForm" | jq -r ".form_data.hmac");
- api_request=$(echo "$resForm" | jq -r ".form_data.api_request");
- cmd="curl -F '$file_field=@$fileName' -F 'hmac=$hmac' -F 'expires=$expires' -F 'userId=$userId' -F 'nodeName=$nodeName' -F 'api_request=$api_request' -F 'parent_id=$folder' "$form_action" 2> .fileBoom.tmp";
- resUpload=`eval $cmd`;
- checkStatus "$resUpload" "Uploading file to server";
- fileName=`ls $file | sed 's/\.\///'`;
- fileSize=`ls -lha $file | awk {'print $5'} | sed 's/K/\ KB/;s/M/\ MB/;s/G/\ GB/;';`;
- fboomURL=`echo $resUpload | sed 's/.*user_file_id\"\:\"//;s/\".*//;s/^/http:\/\/FileBoom\.me\/file\//;'`;
- fboomFileUploadStatus="${#fboomURL}";
- fboomFileUploadAttempt=$(($fboomFileUploadAttempt +1));
- fboomFileUploadAttemptTrailing=`echo $fboomFileUploadAttempt | rev | cut -c-1 | rev`;
- if [[ $fboomFileUploadAttemptTrailing -eq 1 ]] && [[ $fboomFileUploadAttempt -lt 10 ]] || [[ $fboomFileUploadAttempt -gt 19 ]]; then
- fboomFileUploadAttemptOrdinal=`echo $fboomFileUploadAttempt | sed 's/$/st/';`;
- elif [[ $fboomFileUploadAttemptTrailing -eq 2 ]] && [[ $fboomFileUploadAttempt -lt 10 ]] || [[ $fboomFileUploadAttempt -gt 19 ]]; then
- fboomFileUploadAttemptOrdinal=`echo $fboomFileUploadAttempt | sed 's/$/nd/';`;
- elif [[ $fboomFileUploadAttemptTrailing -eq 3 ]] && [[ $fboomFileUploadAttempt -lt 10 ]] || [[ $fboomFileUploadAttempt -gt 19 ]]; then
- fboomFileUploadAttemptOrdinal=`echo $fboomFileUploadAttempt | sed 's/$/rd/';`;
- else
- fboomFileUploadAttemptOrdinal=`echo $fboomFileUploadAttempt | sed 's/$/th/';`;
- fi
- if [[ $fboomFileUploadStatus -eq "37" ]]; then
- echo $green"SUCCESS! "${textreset}$cyan$fileName" has been successfully uploaded on the $fboomFileUploadAttemptOrdinal attempt"${textreset};
- fboomFileUploadAttempt=`echo $uploadRetryLimit`;
- echo $cyan$fboomURL${textreset};
- rm .fileBoom.tmp 2>/dev/null;
- # Parse DDL, Filename, & Filesize into [BBCode]
- echo "[B]FileBoom: [/B][URL="$fboomURL"]"$fileName" - "$fileSize"[/URL]" >> FileBoomLinks.txt;
- fi
- if [[ $fboomFileUploadStatus -ne "37" ]]; then
- echo $red"FAILURE! "${textreset}$cyan$fileName" failed to upload "${textreset}$red$fileName${textreset}" on the "${textreset}$red$fboomFileUploadAttemptOrdinal" of "$fboomFileUploadAttempt${textreset}$cyan" attempts."${textreset};
- echo $yellow" Will re-attempt to upload "$fileName" in 15 seconds..."${textreset};
- sleep 15s;
- rm .fileBoom.tmp 2>/dev/null;
- fi
- echo $cyan"***********************************************************************************************************************************************************************************************"${textreset};
- done;
- fi
- done;
- done;
- echo $cyan"***********************************************************************************************************************************************************************************************"${textreset};
- cat FileBoomLinks.txt;
- ####################################################################################################
- #Counts the number of links generated and display with number of files in current directory.
- numFiles=`ls ./* | grep -v \.txt$ | grep -v \.png$ | grep -v \.jpg$ | grep -v \.jpeg$ | grep -v \.sh$ | wc -l`;
- if [[ -f FileBoomLinks.txt ]]; then
- numLinks=`cat ./FileBoomLinks.txt | wc -l`; ENDTIME=$(date +%s);
- fi
- if [[ ! -f FileBoomLinks.txt ]]; then
- numLinks=0;
- fi;
- echo "Number of files in this directory: "$numFiles;
- echo "Total # FileBoom URLs generated: "$numLinks;
- echo "Number of seconds this script ran for: "$(($ENDTIME - $STARTTIME));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement