Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Bash Uploader For FileOM
- # fileOMUploader.sh
- version="2.014.07.01";
- # Dependency: cURL | Ubuntu 12.04LTS or 14.04LTS: apt-get install libcurl3 -y;
- # Scope: Uploads all files in a directory to an account on FileOM.com
- ####################################################################################################
- # CONFIGURATION SETTINGS #
- ####################################################################################################
- # Configure the following with your credentials between the " " marks.
- user="";
- pass="";
- # Insert the following line (without the # symbol) into the alias section of your ~/.bashrc file:
- # alias fileom='/path/to/your/directory/with/fileOMUploader.sh'
- ####################################################################################################
- # SCRIPT #
- ####################################################################################################
- 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 FileOM v"$version" #"${textreset};
- echo $cyan"############################################"${textreset};
- ####################################################################################################
- # Check if script is already running in directory or failed to exit gracefully on last run
- if [[ -f .fileOMInfo.swp ]]; then
- echo $red"FAILURE! "${textreset}$cyan"Script is either currently running or did not exit gracefully on last run."${textreset};
- read -r -p $cyan"Would you like to clear the FileOMUploader.sh temp files and try again? (y/n):"${textreset} continue;
- continue=${continue,,}
- if [[ $continue =~ ^(yes|y| ) ]]; then
- clear;
- echo $cyan"Removing .fileOMSessionURL.swp & .fileOMInfo.swp"${textreset};
- rm .fileOMSessionURL.swp .fileOMInfo.swp 2>/dev/null;
- echo $green"SUCCESS! "${textreset}$cyan"All FileOMUploader.sh temp files have been purged, resuming script now..."${textreset};
- echo $green"**************************************************************************************************************"${textreset};
- else
- exit 0;
- fi
- fi
- if [[ -f FileOMLinks.txt ]]; then
- echo $yellow"WARNING! "${textreset}$cyan"The file FileOMLinks.txt was found in this directory which indicates that this script has already"${textreset};
- echo $cyan"been run in this directory before."${textreset};
- echo $cyan"Would you like to:"${testreset};
- echo $cyan" i - Ignore this warning (Script will append existing FileOMLinks.txt with any new links it creates."${textreset};
- echo $cyan" d - Delete the existing FileOMLinks.txt 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 FileOMLinks.txt"${textreset};
- rm FileOMLinks.txt 2>/dev/null;
- echo $cyan"**************************************************************************************************************"${textreset};
- fi
- if [[ $userSelection =~ ^(q) ]]; then
- exit 0;
- fi
- fi
- # Generate the session and upload URL
- rm .fileOMSessionURL.swp 2>/dev/null;
- curl --connect-timeout 3 --silent --data "login=$user&password=$pass&op=login" "http://fileom.com/cgi-bin/cAPI.cgi" > .fileOMSessionURL.swp
- uploadSessionCheck=`cat .fileOMSessionURL.swp` 2>/dev/null;
- uploadSessionCheckLength="${#uploadSessionCheck}";
- if [[ $uploadSessionCheckLength -eq "121" ]]; then
- echo $green"SUCCESS! "${textreset}$cyan"Upload session has been created!"${textreset};
- fi
- if [[ $uploadSessionCheckLength -ne "121" ]]; then
- while [[ $uploadSessionCheckLength -ne "121" ]]; do
- rm .fileOMSessionURL.swp 2>/dev/null;
- curl --silent --data "login=$user&password=$pass&op=login" "http://fileom.com/cgi-bin/cAPI.cgi" > .fileOMSessionURL.swp
- uploadSessionCheck=`cat .fileOMSessionURL.swp` 2>/dev/null; uploadSessionCheckLength=`${#uploadSessionCheck};`;
- if [[ $uploadSessionCheckLength -eq "121" ]]; then
- echo $green"SUCCESS! "${textreset}$cyan"Upload session has been created! Uploading files now."${textreset};
- echo $cyan"***************************************************************************************************************"${textreset};
- fi
- if [[ $uploadSessionCheckLength -ne "121" ]]; then
- echo $red"FAILURE! "${textreset}$cyan"Upload session failed to be created, re-attempting now."${textreset};
- echo $cyan"***************************************************************************************************************"${textreset};
- sleep 10s;
- fi
- done;
- fi
- #Uploads the files
- echo $cyan"Upload process for all files in current directory is starting now..."${textreset};
- echo $green"**************************************************************************************************************"${textreset};
- for f in ./*; do
- file=`echo $f | sed 's/^\.\///;'`;
- fileSize=`ls -lh $file | awk {'print $5'}`;
- # Upload the file
- uploadSuccessCheck=0;
- while [[ $uploadSuccessCheck -ne 1 ]]; do
- fileExtension=`echo ${file: -4} | sed 's/.*[\.]//;'`;
- 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"$file"${textreset};
- echo $cyan"***************************************************************************************************************"${textreset};
- uploadSuccessCheck=1;
- fi
- if [[ $fileExtension != "txt" ]] && [[ $fileExtension != "png" ]] && [[ $fileExtension != "jpeg" ]] && [[ $fileExtension != "jpg" ]] && [[ $fileExtension != "sh" ]]; then
- sessionID=`cat .fileOMSessionURL.swp | sed 's/{\"sess_id\"\:\"//;s/\".*//'`;
- url=`cat .fileOMSessionURL.swp | sed 's/.*\"upload_to_url\":\"//;s/\".*//;'`;
- rm .fileOMInfo.swp 2>/dev/null;
- while [[ $uploadSuccessCheck != "1" ]] && [[ ! -f .fileOMInfo.swp ]]; do
- curl -s --form file=@$file --form utype=prem --form sess_id=$sessionID $url > .fileOMInfo.swp;
- sessionSanityCheck=`cat .fileOMInfo.swp | wc -l`;
- uploadSuccessCheck=1;
- if grep -Fxq "[B]FileOM: [/B][URL=]$file - $fileSizeB[/URL]" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$cyan$file" has failed to upload, re-attempting..."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- fi
- if grep "\&st\=filesize too big$" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" failed to upload due to it's size..."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- fi
- if grep "<h1>Forbidden</h1> <p>" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" FileOM API Server is currently not functional, pausing for 1 min before re-attempting."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- sleep 1m;
- fi
- if grep "504 Gateway Time-out" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" FileOM API Server is currently not functional, pausing for 1 min before re-attempting."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- sleep 1m;
- fi
- if grep "please send mail to the webmaster" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" FileOM API Server is currently not functional, pausing for 1 min before re-attempting."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- sleep 1m;
- fi
- if grep "Software error" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" FileOM API Server is currently not functional, pausing for 1 min before re-attempting."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- sleep 1m;
- fi
- if grep "No file found" .fileOMInfo.swp; then
- echo $red"FAILURE! "${textreset}$yellow$file${textreset}$cyan" FileOM API Server is currently not functional, pausing for 1 min before re-attempting."${textreset};
- rm .fileOMInfo.swp 2>/dev/null;
- uploadSuccessCheck=0;
- sleep 1m;
- fi
- downloadURL=`cat .fileOMInfo.swp | xargs -n1 -i curl -s "{}" | sed 's/.*download_link\":\"//;s/\"\}//;'`;
- downloadURLLength="${#downloadURL}";
- if [[ $downloadURLLength == "0" ]]; then
- uploadSuccessCheck=0;
- fi
- done;
- if [[ $downloadURLength != "0" ]] && [[ $uploadSuccessCheck != "0" ]]; then
- uploadedFileSize=`ls -lh $file | awk {'print $5'}`;
- echo $green"SUCCESS! "${textreset}$cyan$file" has been successfully uploaded:"${textreset};
- echo $cyan$downloadURL ${textreset};
- echo $cyan"***************************************************************************************************************"${textreset};
- echo "[B]FileOM: [/B][URL="$downloadURL"]"$file" - "$fileSize"B[/URL]" >> FileOMLinks.txt;
- uploadSuccessCheck=1;
- fi
- fi
- done;
- done;
- rm .fileOMInfo.swp .fileOMSessionURL.swp 2>/dev/null;
- ####################################################################################################
- # Displays the [BBCode] links in the terminal shell
- if [[ -f FileOMLinks.txt ]];
- then cat FileOMLinks.txt;
- fi
- #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 FileOMLinks.txt ]]; then
- numLinks=`cat ./FileOMLinks.txt | wc -l`; ENDTIME=$(date +%s);
- fi
- if [[ ! -f FileOMLinks.txt ]]; then
- numLinks=0;
- fi;
- echo "Number of files in this directory: "$numFiles;
- echo "Total # FileOM.com URLs generated: "$numLinks;
- echo "Number of seconds this script ran for: "$(($ENDTIME - $STARTTIME));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement