Tag Archives: script

Newsmangler Support in Rarnpar

Many people have asked me to add the option to upload files automatically with newsmangler. I thought that this is a great idea and decided to implement it in the next release. So, in the new(0.80) version, you’ll see two new options -U(upload) and -X(path to newsmangler executable). They should not cause any problems, if you are familiar with the script already. In case you aren’t, you could always check the detailed guide prepared by my friend. Continue reading Newsmangler Support in Rarnpar

Sending encrypted attachments via sendmail

If you are like me, you have some scripts which report to you via email. Most of the time the report is just a simple text, but sometimes you will want to receive a file(f.e. a screenshot).

It isn’t the bad idea per se, but emails travel unencrypted through the Internet. As you know, NSA and other bastards are there to gather all the data which passes through. Therefore it’s a good idea to encrypt everything you send. I won’t tell you how to encrypt your personal email. It’s kinda simple task and multiple guides exist. I would like to share with you a way to encrypt an output from your script, which will be passed to sendmail.

I am using sendmail, not mailx, because you can find it on almost every system, much like vi. This how-to is based on following post: http://backreference.org/2013/05/22/send-email-with-attachments-from-script-or-command-line/ . So I will tackle two problems at once here: files and encryption. Of course, if attachments aren’t needed, it is even simpler. Continue reading Sending encrypted attachments via sendmail

Random passwords in rarnpar

When I was asked to add an option to generate random passwords during the raring process, I was quite sceptical. It didn’t appear to me that someone would use such a feature, but after reading the following explanation, I decided to add this option and now it’s up to you, if you will use it or not.

By the way, there is also a small bug fix. Some users were complaining that directories in –subdir mode have .tmp suffix. You shouldn’t see this suffix now. Continue reading Random passwords in rarnpar

Fine-tuning par- and rar- sets

After getting some feedback for my previous rarnpar release(version 0.7), I was actively implementing new features and fixing some old bugs. There were some releases during that time, which were accessible to anyone via the most recent version link.

If you did get the version 0.71-0.74 during this time, you could download the updated script(v0.75) now.

I have fixed the bug with unnecessary .nfo file creation and I have added two additional options: –par and –rar. You will be able to add some additional files for raring and/or paring. Like, for example, –par *.sfv to add a dynamically created .sfv file(keep in mind that you won’t be able to add dynamically created files to a rarset as it makes no sense in almost all cases).
Full diff looks like this: Continue reading Fine-tuning par- and rar- sets

Writing Upstart Script for Forky Java Application

As you probably know, Canonical replaced traditional init scripts with Upstart jobs in Karmic Koala(9.10). Although you can still run “old school” scripts, it is encouraged to write a proper upstart config for your application.
Maybe Upstart can start daemons asynchronously, but it has currently one major disadvantage – you can’t specify a pid file and it can’t track PIDs, if a program forked/cloned itself more than twice during launch. I needed to write a upstart script for such app and it took me some time to figure a workaround, which I will describe here. Continue reading Writing Upstart Script for Forky Java Application

Version 0.7

I haven’t posted for a few days, although anybody, who has downloaded rarnpar from the “most recent version” link, should has seen that I have updated the script. Recent changes include an ability to change file/directory name, an additional, default header to the NFO files and some small bugfixes(f.e. default suffix isn’t used anymore, if you have specified a prefix or a suffix).

3a4,8
> # 2013-07-19: Added option to set custom names directly via script; version 0.7
> # 2013-07-19: Autogenerated SFV file will use crypto-name when needed; version 0.69
> # 2013-07-18: Added rarnpar header to the nfos; version 0.68
> # 2013-07-17: Now script displays help if launched without options; version 0.67
> # 2013-07-17: Default suffix isn't needed if prefix is specified; version 0.66
15,88c20
< ############################
< #
< # Variables
< ############################
< # File name prefix
< NAME_PREFIX=
< # File name suffix
< NAME_SUFFIX=
< # Rar volume size in megabytes 
< VOLUME_SIZE=50
< # Par block size
< BLOCK_SIZE=384000
< # Par block count; unusable together with size
< BLOCK_COUNT=0
< # Par recovery %
< PAR_RECOVERY=10
< # Move new files to subdirectories or not?
< DIRECTORIES=0
< # Rar command
< RARC=
< # Par2 command
< PAR2C=
< # File which will be processed by script next
< FILE_TO_PROCESS=
< # Directory which will be processed in subdirectory mode
< DIRECTORY_TO_PROCESS=
< # FILENAME=prefix+(actual_file_name - extension)+suffix
< FILENAME=
< # Use rar names of the new type?
< OLDRAR=0
< # Rar compression level
< COMPRESSION=0
< # Uniform par file size
< UNIFORM=0
< # Subdirectory preparation mode flag
< SUBDIRECTORIES=0
< # Limit size of par2 recovery files. Can't be used with UNIFORM=1
< LIMIT=0
< # Process files larger than minimum size
< MINIMUMS=0
< # Verbosity
< VERBOSE=0
< # Crypto-renaming mode
< CRYPTMODE=0
< # Algorithm to use; sha1, sha224, sha256, sha384, sha512, md5
< ALGO=
< # Original directory name, before renaming in crypto mode
< ORIGINAL_DIR=
< # Original FILENAME, before cryptorenaming
< ORIGINAL_NAME=
< # Original file name, with extension, before renaming in crypto mode
< ORIGINAL_FILE_EXT=
< # Same as above, only without extension
< ORIGINAL_FILE=
< # File extension from ORIGINAL_FILE_EXT
< EXT=
< # Create nfo?
< NFO=0
< # Filetypes to check by mediainfo
< SUPPORTED_BY_MINFO=("mkv" "avi" "wmv" "mp4" "mov" "ogg" "ogm" "wav" "mka" "mks" "mpeg" "mpg" "vob" "mp3" "asf" "ape" "flac")
< # Starting directory; by default script runs in ./
< STARTING_DIR=
< # Output directory; by default script dumps everything in ./
< OUTPUT_DIR=
< # Recursive mode. Off by default.
< RECURSIVE=0
< # Depth string. Modified in recursive mode.
< MAXDEPTH="-maxdepth 1"
< # Create SFV?
< CREATE_SFV=0
< # Filenames to exclude
< EXCLUDE_LIST=
< # Password for rar encryption
< PASSWORD=
---
> # TODO: remove the need of default suffix and fix the problems with a processing of files without extension
100a33,118
> # Function to set variables to default values
> defaults() {
> 	############################
> 	#
> 	# Variables
> 	############################
> 	# File name prefix
> 	NAME_PREFIX=
> 	# File name suffix
> 	NAME_SUFFIX=
> 	# Rar volume size in megabytes 
> 	VOLUME_SIZE=50
> 	# Par block size
> 	BLOCK_SIZE=384000
> 	# Par block count; unusable together with size
> 	BLOCK_COUNT=0
> 	# Par recovery %
> 	PAR_RECOVERY=10
> 	# Move new files to subdirectories or not?
> 	DIRECTORIES=0
> 	# Rar command
> 	RARC=
> 	# Par2 command
> 	PAR2C=
> 	# File which will be processed by script next
> 	FILE_TO_PROCESS=
> 	# Directory which will be processed in subdirectory mode
> 	DIRECTORY_TO_PROCESS=
> 	# FILENAME=prefix+(actual_file_name - extension)+suffix
> 	FILENAME=
> 	# Use rar names of the new type?
> 	OLDRAR=0
> 	# Rar compression level
> 	COMPRESSION=0
> 	# Uniform par file size
> 	UNIFORM=0
> 	# Subdirectory preparation mode flag
> 	SUBDIRECTORIES=0
> 	# Limit size of par2 recovery files. Can't be used with UNIFORM=1
> 	LIMIT=0
> 	# Process files larger than minimum size
> 	MINIMUMS=0
> 	# Verbosity
> 	VERBOSE=0
> 	# Crypto-renaming mode
> 	CRYPTMODE=0
> 	# Algorithm to use; sha1, sha224, sha256, sha384, sha512, md5
> 	ALGO=
> 	# Original directory name, before renaming in crypto mode
> 	ORIGINAL_DIR=
> 	# Original FILENAME, before cryptorenaming
> 	ORIGINAL_NAME=
> 	# Original file name, with extension, before renaming in crypto mode
> 	ORIGINAL_FILE_EXT=
> 	# Same as above, only without extension
> 	ORIGINAL_FILE=
> 	# File extension from ORIGINAL_FILE_EXT
> 	EXT=
> 	# Create nfo?
> 	NFO=0
> 	# Filetypes to check by mediainfo
> 	SUPPORTED_BY_MINFO=("mkv" "avi" "wmv" "mp4" "mov" "ogg" "ogm" "wav" "mka" "mks" "mpeg" "mpg" "vob" "mp3" "asf" "ape" "flac")
> 	# Starting directory; by default script runs in ./
> 	STARTING_DIR=
> 	# Output directory; by default script dumps everything in ./
> 	OUTPUT_DIR=
> 	# Recursive mode. Off by default.
> 	RECURSIVE=0
> 	# Depth string. Modified in recursive mode.
> 	MAXDEPTH="-maxdepth 1"
> 	# Create SFV?
> 	CREATE_SFV=0
> 	# Filenames to exclude
> 	EXCLUDE_LIST=
> 	# Password for rar encryption
> 	PASSWORD=
> 	# Rename to this string
> 	RENAME_TO=
> }
> # Generate .nfo header
> generate_nfo_header() {
> 	echo "Generated using rarnpar"
> 	echo "To get rarnpar please visit: http://tad-do.net/tag/rarnpar/"
> 	echo
> }
> 
103c121
< 	echo "Rar&Par script version 0.65. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
---
> 	echo "Rar&Par script version 0.7. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
108a127
> 	echo -e "OR (to start with \033[1mdefault\033[0m options): $0 --defaults\n"
112a132
> 	echo -e "\t--defaults\tLaunch the script with default options."
121a142
> 	echo -e "\t-NN <string>\tNew name. Rename file/directory during processing. Shouldn't be used with multiple items. Disabled in recursive mode."
133a155,162
> # Display help if no options were provided
> if [ "$#" == "0" ]
> then
> 	show_help
> 	exit
> fi
> # Initialize variables and set them to the default values
> defaults
152a182,185
> 		--defaults)
> 		 DEFAULTS=yes
> 		 break
> 		 ;;
189a223,226
> 		-NN)
> 		 RENAME_TO="$2"
> 		 shift 2
> 		 ;;
240a278,282
> # Run a script with default settings if a user wants it.
> if [ "$DEFAULTS" = "yes" ]
> then
> 	defaults
> fi
322c364,365
< 	if [ -z $NAME_SUFFIX ]; then NAME_SUFFIX="-rnp"; fi
---
> 	# We need some other directory name, beucause otherwise we will encounter conflicts
> 	if [ -z $NAME_SUFFIX ] && [ -z $NAME_PREFIX ]; then NAME_SUFFIX="-rnp"; fi
326c369,374
< 			FILENAME="$NAME_PREFIX""$DIRECTORY_TO_PROCESS""$NAME_SUFFIX"
---
> 			if [ -n "$RENAME_TO" ] && [ "$RECURSIVE" == "0" ]
> 			then
> 				FILENAME="$NAME_PREFIX""$RENAME_TO""$NAME_SUFFIX"
> 			else
> 				FILENAME="$NAME_PREFIX""$DIRECTORY_TO_PROCESS""$NAME_SUFFIX"
> 			fi
341c389
< 			[ "$CRYPTMODE" = "1" ] && touch "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
---
> 			[ "$CRYPTMODE" = "1" ] && generate_nfo_header > "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
352c400
< 			(( $CREATE_SFV == 1 )) && cksfv -b "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}"*.r* > "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.sfv"
---
> 			(( $CREATE_SFV == 1 )) && cksfv -b "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}"*.r* > "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}.sfv"
376c424,429
< 			FILENAME="$NAME_PREFIX""${FILE_TO_PROCESS%.*}""$NAME_SUFFIX"
---
> 			if [ -n "$RENAME_TO" ] && [ "$RECURSIVE" == "0" ]
> 			then
> 				FILENAME="$NAME_PREFIX""$RENAME_TO""$NAME_SUFFIX"
> 			else
> 				FILENAME="$NAME_PREFIX""${FILE_TO_PROCESS%.*}""$NAME_SUFFIX"
> 			fi
385c438,439
< 						mediainfo "$FILE_TO_PROCESS" > /tmp/rarnpar_nfo.tmp
---
> 						generate_nfo_header > /tmp/rarnpar_nfo.tmp
> 						mediainfo "$FILE_TO_PROCESS" >> /tmp/rarnpar_nfo.tmp
411c465
< 				touch "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
---
> 				generate_nfo_header > "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
416c470
< 				touch "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
---
> 				generate_nfo_header > "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.nfo"
429c483
< 			(( $CREATE_SFV == 1 )) && cksfv -b "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}"*.r* > "${OUTPUT_DIR}${FILENAME}"/"${ORIGINAL_NAME}.sfv"
---
> 			(( $CREATE_SFV == 1 )) && cksfv -b "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}"*.r* > "${OUTPUT_DIR}${FILENAME}"/"${FILENAME}.sfv"

You can download the most up-to-date version from the same link or from the version specific, dedicated links:

As always, any feedback is welcome.

Password protection – Now in Rarnpar!

Ever wanted to create password protected files with rarnar? Now it’s finally possible. In the version 0.65 I have added the -P option, which allows you to specify password to be used during rar file creation. Keep in mind that cryptorenaming mode was modified slightly – only final files will be renamed(as it makes no sense to rename contents of rared files, if the contents are not visible without a right password).

Diff:

3a4
> # 2013-07-15: Added option to encrypt rar with password; version 0.65
85a87,88
> # Password for rar encryption
> PASSWORD=
100c103
< 	echo "Rar&Par script version 0.6. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
---
> 	echo "Rar&Par script version 0.65. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
120a124
> 	echo -e "\t-P <string>\tProtect files with <string> as password."
193a198,201
> 		-P)
> 		 PASSWORD="$2"
> 		 shift 2
> 		 ;;
290a299,303
> # Do we need to password protect files?
> if [ -n "$PASSWORD" ]
> then
> 	RARC="${RARC} -hp${PASSWORD}"
> fi
320,321c333,338
< 				mv "$DIRECTORY_TO_PROCESS" "$FILENAME.tmp"
< 				DIRECTORY_TO_PROCESS="$FILENAME.tmp"
---
> 				# We don't need to rename directories if we encypt rar with password
> 				if [ -z $PASSWORD ]
> 				then
> 					mv "$DIRECTORY_TO_PROCESS" "$FILENAME.tmp"
> 					DIRECTORY_TO_PROCESS="$FILENAME.tmp"
> 				fi
341c358
< 			[ "$CRYPTMODE" = "1" ] && mv "$DIRECTORY_TO_PROCESS" "$ORIGINAL_DIR"
---
> 			[ "$CRYPTMODE" = "1" ] && [ -z "$PASSWORD" ] && mv "$DIRECTORY_TO_PROCESS" "$ORIGINAL_DIR"
380,381c397,402
< 				mv "$FILE_TO_PROCESS" "${FILENAME}.${EXT}"
< 				FILE_TO_PROCESS="${FILENAME}.${EXT}"
---
> 				# We don't need to rename files if we encypt rar with password
> 				if [ -z $PASSWORD ]
> 				then
> 					mv "$FILE_TO_PROCESS" "${FILENAME}.${EXT}"
> 					FILE_TO_PROCESS="${FILENAME}.${EXT}"
> 				fi
414c435
< 			[ "$CRYPTMODE" = "1" ] && mv "$FILE_TO_PROCESS" "$ORIGINAL_FILE_EXT"
---
> 			[ "$CRYPTMODE" = "1" ] && [ -z "$PASSWORD" ] && mv "$FILE_TO_PROCESS" "$ORIGINAL_FILE_EXT"

Permanent link to the version 0.65.
Link to the latest version.

Exclusions in rarnpar

Thank you readers for providing me with ideas for features for rarnpar script. Exclusion list is a quite simple feature, but yet it was lacking in all the previous versions.

To use it, you need to specify -e option together with a list of file names/expressions to exclude. For example: -e “*avi”,”*mp3″ to exclude all avi and mp3 files from processing. It should help you automatize your file preparation process even more.

And, as always, here is the diff since the last version:

4c4,5
< # 2013-02-28: Fixed the bug, when .nfo/.sfv files were not properly created in normal model; version 0.52
---
> # 2013-06-17: Added exclusion list option for file mode; version 0.6
> # 2013-02-28: Fixed the bug, when .nfo/.sfv files were not properly created in normal mode; version 0.52
82a84,85
> # Filenames to exclude
> EXCLUDE_LIST=
97c100
< 	echo "Rar&Par script version 0.52. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
---
> 	echo "Rar&Par script version 0.6. Copyright (C) 2011-2013 Tadeus Dobrovolskij."
107a111
> 	echo -e "\t-e <expr>\tComma separated list of expressions to exclude. Example: \"*avi\",\"*mpg\" to exclude all avi and mpg files. File mode only."
148a153,156
> 		-e)
> 		 EXCLUDE_LIST="$2"
> 		 shift 2
> 		 ;;
271a280,285
> # Exclusions
> if [ -n "$EXCLUDE_LIST" ]
> then
> 	EXCLUDE_LIST=$(echo "$EXCLUDE_LIST" | sed -e 's/^/! -iname \"/' -e 's/,/\" ! -iname \"/g' -e 's/$/\" /')
> fi
> 
336c350
< 	if (($(find . ${MAXDEPTH} -type f \( ! -iname ".*" \) -size +${MINIMUMS}M | wc -l) > 0)); then
---
> 	if (($(find . ${MAXDEPTH} -type f \( ! -iname ".*" ${EXCLUDE_LIST}\) -size +${MINIMUMS}M | wc -l) > 0)); then
405c419
< 		done < <(find . ${MAXDEPTH} -type f \( ! -iname ".*" \) -size +${MINIMUMS}M | sed -e 's/^\.//g' -e 's/^\///g')
---
> 		done < <(find . ${MAXDEPTH} -type f \( ! -iname ".*" ${EXCLUDE_LIST}\) -size +${MINIMUMS}M | sed -e 's/^\.//g' -e 's/^\///g')

You can use either permanent link to version 0.6, or the link to the latest version to check out the new feature.