Category Archives: Linux

HTC Android Splasher

Version: v0.1

Summary: A quick script a threw together to allow Mac or Linux users to create and flash splash screens for their HTC Android phones.

Requirements:

Code:

#!/bin/bash

##Written by Blake Johnson
##Website: http://www.blakeanthonyjohnson.com/
##Script requires ImageMagick and nbimg to be installed and located in $PATH.

#Convert image to 24-bit bitmap.
echo -n "Converting image to 24-bit bitmap...   "
convert "$1" "/tmp/$1.bmp"
convert "/tmp/$1.bmp" +matte "/tmp/$1.bmp"
echo "[Done]"
echo

#Check image dimensions.
echo -n "Verifying image dimensions...   "
ImageInfo=`identify "/tmp/$1.bmp"`
if [[ "$ImageInfo" =~ "480x800" ]]
then
	echo "[Done]"
	echo "Dimensions (480x800) verified for the following phones: HTC Evo, HTC Desire"
elif [[ "$ImageInfo" =~ "320x480" ]]
then
	echo "[Done]"
	echo "Dimensions (320x480) verified for the following phones: HTC Hero"
else
	echo "Unable to verifiy proper dimensions.  Please make sure the image dimensions are correct."
	exit
fi
echo

#Convert to splash image.
echo -n "Converting verified image to splash format...   "
nbimg -F "/tmp/$1.bmp" > /dev/null 2>&1
echo "[Done]"
echo

#Check if they want it flashed via Fastboot, or just copied.
echo "Please select what should be done with the resulting image."
echo "1. Copy image to Desktop."
echo "2. Write image to phone."
echo
read -p "Please select an option. (1, 2)?"
if [[ $REPLY == "1" ]]
then
	echo "You have selected Fastboot mode."
	MODE='write'
elif [[ $REPLY == "2" ]]
then
	echo "You have selected copy-to-Desktop."
	MODE='copy'
else
	echo "Unknown selection.  Exiting."
	exit
fi
echo

##Perform the selected action.
if [[ "${MODE}" == "write" ]]
then
	echo "Launching the Fastboot command...  Please put phone into Fastboot mode."
	fastboot flash splash1 "/tmp/$1.bmp.nb"
	echo "Spash screen has been written successfully."
elif [[ "${MODE}" =~ "copy" ]]
then
	#Copy converted image to Desktop.
	echo -n "Copying converted splash image to Desktop...   "
	cp "/tmp/$1.bmp.nb" "$HOME/Desktop/$1.nb"
	echo "[Done]"
else
	echo "Unknown variable passed to last step."
	exit
fi

Changes:
v0.1: Initial Release

FilenameUnifier

Version: v0.2

Summary: Ever wanted to mass rename a bunch of files into a specific pattern based on their original filenames? Yeah, there are other utilities out there, but this is a simple solution based on my FilenameSanitizer script which locates filenames in a given directory with a specific pattern, and then renames them based on that pattern. As of the current version, it’s set to unify numeric .jpg images. For example, “5466.Jpeg” would become “005466.JPG”.

Requirements:

  • find
  • sed
  • wc
  • whoami

Code:

#!/bin/bash
 
LOG="${HOME}/.FilenameUnifier.log"
TMPLOG="/tmp/FilenameUnifier-`whoami`"
 
##Write Date & Time to Log File
echo "-------------------------------------" > "${LOG}"
echo "`date +%B %d, %Y`" >> "${LOG}"
echo "-------------------------------------" >> "${LOG}"
 
USAGE="Usage: ${0} -s "
 
echo "FilenameUnifier"
echo "Prototype by Kevin Warns"
echo "Modified by Blake Johnson"
echo "http://www.simplescripts.net/"
echo
 
while getopts 's:h' OPTION; do
	case ${OPTION} in
		s) SOURCE="${OPTARG}";;
		h) echo "${USAGE}" >&2
			exit 2;;
		?) echo "Unknown option "-${OPTARG}"." >&2
			echo ${USAGE};;
		:) echo "Option "-${OPTARG}" needs an argument." >&2
  			echo ${USAGE}
  			exit 2;;
  		*) echo ${USAGE}
  			exit 2;;
  	esac
done
 
if [ -z "$SOURCE" ]
then
	echo "One or more parameters are missing."
	echo "${USAGE}"
	exit 2
fi


find "${SOURCE}" -type f -regextype "posix-extended" -iregex ".*[/][0-9]{1,5}.jpe?g$" > "${TMPLOG}" 2>"${LOG}" ##Let's check for .jpg files with only numbers in their names.

UpperBound=$(cat "${TMPLOG}" | wc -l)  ##Count the number of results found.
 
if [ "${UpperBound}" = "0" ]  ##Check to make sure that 'find' found some files that need to be renamed.
then
	echo "There is nothing to rename."
	exit 1
else
	echo "${UpperBound} file(s) found."
	i=0
	e=0
	s=0
	while [ "${i}" -lt "${UpperBound}" ]
	do
		(( i += 1 ))
		TMPLINE=$(sed -n "${i}p" "${TMPLOG}")
		InputLocation="${TMPLINE%/*}"
		InputName="${TMPLINE##*/}"
 
		NewName="${InputName}"
		NewName=$(echo -n "${NewName}" | sed 's/jpe?g/JPG/i')  ##Strip leading spaces and trailing spaces / periods.

		FilenameLength=${#NewName} ##grab the # of characters in the filename

		#number of digits = length - 4 (accounting for .jpg)
		let COUNTER=$FilenameLength-4
		while [ $COUNTER -lt 6 ]; do
	   	 	NewName="0"${NewName}
			(( COUNTER += 1 ))
		done

		OutputPath="${InputLocation}/${NewName}"

		if [ "${OutputPath}" == "${TMPLINE}" ] ##Check to make sure that the name was actually changed.
		then
			echo -e ""${TMPLINE}" [ 33[1;31mNot Renamed33[0m ]"
			echo "Reason: Name Unchanged. This may be an error in the script."
		fi

		if [ -f "${OutputPath}" ] ##Check to make sure that the new name won't overwrite an existing file.
		then
			OutputPath="${OutputPath}.RENAME_${i}"
		fi

		echo -n "Renaming "${TMPLINE}" to "${OutputPath}"... "
		mv "${TMPLINE}" "${OutputPath}" >> "${LOG}" 2>&1
		echo "mv "${TMPLINE}" "${OutputPath}"" >> "${LOG}" 2>&1

		if [ "$?" == 0 ] ##Check to see if the 'mv' command failed or not.
		then
			echo -e "[ 33[1;32mRenamed33[0m ]"
			(( s += 1 ))
		else
			echo -e "[ 33[1;31mNot Renamed33[0m ]"
			(( e += 1 ))
		fi
		echo
		unset NewName OutputPath TMPLINE
	done

	echo "${s} / ${i} file(s) renamed successfully."
	echo "${e} file(s) could not be renamed."
fi
 
rm "${TMPLOG}" >> "${LOG}"
exit 0

Changes:
v0.2: Initial Release
v0.1: Prototype

Credits: Special thanks to Kevin Warns for creating a prototype for me to start off with.

Filename Sanitizer (v0.6)

Summary: This script was designed to help ease the migration of data from a Mac or Linux PC to a FAT32 flash drive, which in turn would be compatible with Windows. It does this by attempting to find any questionable characters in any of the file names, and replacing them with hyphens ‘-‘. It also removes leading and trailing spaces, along with trailing periods.

Requirements:

  • find
  • sed
  • tac (coreutils)

Code:

#!/bin/bash

LOG="${HOME}/.FilenameSanitizer.log"
TMPLOG="/tmp/FilenameSanitizer-`whoami`"

##Write Date & Time to Log File
echo "-------------------------------------" > "${LOG}"
echo "`date +%B %d, %Y`" >> "${LOG}"
echo "-------------------------------------" >> "${LOG}"

USAGE="Usage: ${0} -s "

echo "FilenameSanitizer"
echo "Scripted by Blake Johnson"
echo "http://www.simplescripts.net/"
echo

while getopts 's:h' OPTION; do
	case ${OPTION} in
		s) SOURCE="${OPTARG}";;
		h) echo "${USAGE}" >&2
			exit 2;;
		?) echo "Unknown option "-${OPTARG}"." >&2
			echo ${USAGE};;
		:) echo "Option "-${OPTARG}" needs an argument." >&2
  			echo ${USAGE}
  			exit 2;;
  		*) echo ${USAGE}
  			exit 2;;
  	esac
done

if [ -z "$SOURCE" ]
then
	echo "One or more parameters are missing."
	echo "${USAGE}"
	exit 2
fi



##This is what the script is looking for...
##1. Illegal Characters
##2. Leading Spaces
##3. Trailing Spaces and periods.
find "${SOURCE}" 
-regex ".*[][%+\"*;:?|,=]+[^/]*$" 
-o -regex ".*/[ ]+[^/]*$" 
-o -regex ".*[ .]+$" 
| tac > "${TMPLOG}" 2>"${LOG}" ##In most cases, reversing the results requires only one run of this script.

UpperBound=$(cat "${TMPLOG}" | wc -l)  ##Count the number of results found.

if [ "${UpperBound}" = "0" ]  ##Check to make sure that 'find' found some files that need to be renamed.
then
	echo "There is nothing to rename."
	exit 1
else
	echo "${UpperBound} file(s) found."
	i=0
	e=0
	s=0
	while [ "${i}" -lt "${UpperBound}" ]
	do
		(( i += 1 ))
		TMPLINE=$(sed -n "${i}p" "${TMPLOG}")
		InputLocation="${TMPLINE%/*}"
		InputName="${TMPLINE##*/}"
	
		NewName="${InputName}"
		NewName=$(echo -n "${NewName}" | sed 's/^ *//' | sed 's/[ .]*$//')  ##Strip leading spaces and trailing spaces / periods.
		NewName=$(echo -n "${NewName}" | sed "s/[][%+\"*;:?|,=]/-/g") ##Replace illegal characters.
		
		if [ "${NewName}" == "" ]  ##Check to make sure the new file name is not blank.
		then
			NewName="Untitled - ${i}"
		fi
		
		OutputPath="${InputLocation}/${NewName}"
		
		if [ "${OutputPath}" == "${TMPLINE}" ] ##Check to make sure that the name was actually changed.
		then
			echo -e ""${TMPLINE}" [ 33[1;31mNot Renamed33[0m ]"
			exit
		fi
		
		if [ -f "${OutputPath}" ] ##Check to make sure that the new name won't overwrite an existing file.
		then
			OutputPath="${OutputPath}.RENAME_${i}"
		fi
		
		echo -n "Renaming "${TMPLINE}" to "${OutputPath}"... "
		mv "${TMPLINE}" "${OutputPath}" >> "${LOG}" 2>&1
		
		if [ "$?" == 0 ] ##Check to see if the 'mv' command failed or not.
		then
			echo -e "[ 33[1;32mRenamed33[0m ]"
			(( s += 1 ))
		else
			echo -e "[ 33[1;31mNot Renamed33[0m ]"
			(( e += 1 ))
		fi
		echo
		unset NewName OutputPath TMPLINE
	done
	
	echo "${s} / ${i} file(s) renamed successfully."
	echo "${e} file(s) could not be renamed."
fi

rm "${TMPLOG}" >> "${LOG}"
exit 0

Changes:
v0.6: Simplified the search command. Added some more questionable characters. Added ability to set parameters at the command line. Displays usage line upon error.
v0.5: Name changed to “Filename Sanitizer”. Simplified the replacement of illegal characters. Parses the results in reverse order. Added check for duplicate names. Commented code a bit.
v0.4: Search results are now written to a file instead of variable, fixes bug with trailing spaces, removes trailing periods, removes leading and trailing spaces, counts and shows success rate.
v0.3: Name changed to Filename Cleanser. Added more questionable characters to search for.
v0.2: Errors are logged, exit status of each rename command, and some other revisions.
v0.1: Initial release.

Bugs / Unimplemented Features:

  • File names with repeating periods _may_ end up disappearing off the face of the planet. (I don’t know why, or how.)

OneStep DVD-Video (v0.3)

Summary: A shell script to convert, and make an DVD-Video image of a specified video file.

Requirements:

  • ffmpeg
  • dvdauthor
  • mkisofs

Code:

#!/bin/bash
TMP="${TMPDIR}/"
LOG="${HOME}/.OneStepDVDVideo.log"

##Write Date & Time to Log File
echo "-------------------------------------" > "${LOG}"
echo "`date +%B %d, %Y`" >> "${LOG}"
echo "-------------------------------------" >> "${LOG}"
 
echo "OneStep DVD-Video"
echo "Scripted by Blake Johnson"
echo "http://www.simplescripts.net/"
echo


if [ "$1" ]
then
	if [ -r "$1" ]
	then
		InputFileLocation="${1%/*}/"
		InputFileName="${1##*/}"
		OutputPath="${InputFileLocation}${InputFileName}.iso"
	else
		echo "Source file either does not exist, or it is not readable."
		exit 2
	fi
else
	echo "Source not specified."
	exit 1
fi

echo



FFmpegCommand="ffmpeg -y -i ${InputFileLocation}${InputFileName} -aspect 3:4 -target ntsc-dvd ${TMP}${InputFileName}.m2v"
DVDAuthorStep1Command="dvdauthor -o ${TMP}${InputFileName}_temp/ -t ${TMP}${InputFileName}.m2v"
DVDAuthorStep2Command="dvdauthor -o ${TMP}${InputFileName}_temp/ -T"
MKISOFSCommand="mkisofs -dvd-video -o ${OutputPath} ${TMP}${InputFileName}_temp/"

##Let's run FFmpeg
echo -n "Step 1 of 4: Converting video to a MPEG2 file..."
FFmpegOutput="`${FFmpegCommand} > /dev/null 2>&1`"

if [ $? == 0 ]
then
	echo -n -e "33[1;32mOK!"
	echo -e "33[0m"

	##Let's run DVDAuthor, Step1
	echo -n "Step 2 of 4: Building initial DVD-Video structure..."
	DVDAuthorStep1Output="`${DVDAuthorStep1Command} > /dev/null 2>&1`"
	
	if [ $? == 0 ]
	then
		echo -n -e "33[1;32mOK!"
		echo -e "33[0m"

		##Let's run DVDAuthor, Step 2
		echo -n "Step 3 of 4: Finalizing DVD-Video structure..."
		DVDAuthorStep2Output="`${DVDAuthorStep2Command} > /dev/null 2>&1`"
		
		if [ $? == 0 ]
		then
			echo -n -e "33[1;32mOK!"
			echo -e "33[0m"

			##Let's run MKISOFS.
			echo -n "Step 4 of 4: Creating an ISO image of the DVD..."
			MKISOFSOutput="`${MKISOFSCommand} > /dev/null 2>&1`"
			
			if [ $? == 0 ]
			then
				echo -n -e "33[1;32mOK!"
				echo -e "33[0m"

				##Everything worked.
				echo "DVD-Video ISO complete."
			else
				echo -n -e "33[1;31mFailed!"
				echo -e "33[0m"

				##MKISO failed to build ISO.
				echo "Failed to build ISO image."
				exit 6
			fi
		else
			echo -n -e "33[1;31mFailed!"
			echo -e "33[0m"

			##DVDAuthor, Step 2 failed.
			echo "Failed to finalize the DVD structure."
			exit 5
		fi
	else
		echo -n -e "33[1;31mFailed!"
		echo -e "33[0m"

		echo "Failed to build the initial DVD directory structure."
		exit 4
	fi
else
	echo -n -e "33[1;31mFailed!"
	echo -e "33[0m"

	##Conversion to MPEG2 failed.
	echo "Conversion of source video to an MPEG2 file failed."
	exit 3
fi

Changes:
v0.3: Bug fixes and revisions.
v0.2: Bug fixes and revisions.
v0.1: Initial release.

ServerCheck (v0.6)

Summary: This script will check to see if a web server is functioning properly by checking the output of a specific location. If this output is wrong, or unavailable, a message will be emailed. Additionally, if the server returns output which the script was not expecting, it has the ability to run a custom restore command and hopefully get the server functioning again.

Requirements:

  • mail
  • curl

Code:

#!/bin/bash
##Set Default Options
CHECKFOR="" ##This is the what the script expects to find in the result.
TIMEOUT="10" ##Max amount of time to wait for a connection.
MAXTIME="30" ##Max time to spend trying to load page.

##Do not edit anything below this comment!

function Restore {
	echo
	echo -n "Attempting Recovery..."
	${RESTORECMD} > /dev/null 2>&1
	
	if [ $? == 0 ]
	then
		echo -n -e "33[1;32mOK!"
		echo -e "33[0m"
		echo -e "Recovery successful.nnNothing is needed for ${CHECKURL}nn" | mail -s "ServerCheck" "${EMAIL}"
	else
		echo -n -e "33[1;31mFailed!"
		echo -e "33[0m"
		echo -e "Recovery failed.nnManual fix may be needed for ${CHECKURL}.nn" | mail -s "ServerCheck" "${EMAIL}"
	fi
}

USAGE="Usage: ${0} -s  -e  -f [CHECKFOR] -d [POST_DATA] -r [RESTORECMD]"

echo "ServerCheck"
echo "Scripted by Blake Johnson"
echo "http://www.blakeanthonyjohnson.com/"
echo

while getopts ':s:f:r:e:d:h' OPTION; do
	case ${OPTION} in
		s) CHECKURL="${OPTARG}";;
		f) CHECKFOR="${OPTARG}";;
		r) RESTORECMD="${OPTARG}";;
		e) EMAIL="${OPTARG}";;
		d) POSTDATA="${OPTARG}";;
		h) echo ${USAGE};;
		?) echo "Unknown option "-${OPTARG}"." >&2
			echo ${USAGE};;
		:) echo "Option "-${OPTARG}" needs an argument." >&2
  			echo ${USAGE}
  			exit 1;;
  		*) echo ${USAGE}
  			exit 1;;
  	esac
done

if [ -z "$CHECKURL" ]
then
	echo "One or more parameters are missing."
	echo "${USAGE}"
	exit 1
fi

if [ -z "$EMAIL" ]
then
	echo "One or more parameters are missing."
	echo "${USAGE}"
	exit 1
fi

echo "Checking URL:  "${CHECKURL}""
echo "Email: "${EMAIL}""
echo "Checking for: "${CHECKFOR}""
echo

echo -n "Checking if server is working properly... "

CURLCOMMAND="curl -s ${CHECKURL} --connect-timeout ${TIMEOUT} --max-time ${MAXTIME}"

if [ $POSTDATA ]
then
	CURLCOMMAND="${CURLCOMMAND} -d ${POSTDATA}"
fi

CURLOUTPUT=`${CURLCOMMAND}`

if [ $? == 0 ]
then
	if [[ "$CURLOUTPUT" =~ "$CHECKFOR" ]]
	then
		echo -n -e "33[1;32mOK!"
		echo -e "33[0m"
	else
		echo -n -e "33[1;31mFailed!"
		echo -e "33[0m"
		echo "String not found."
		
		if [ "$RESTORECMD" ]
		then
			Restore	
		else
			echo -e "Wrong output recieved.nnPlease check ${CHECKURL}.nn" | mail -s "ServerCheck" "${EMAIL}"
		fi
	fi
else
	echo -n -e "33[1;31mFailed!"
	echo -e "33[0m"
	echo "Some other error occurred."
	
	if [ "$RESTORECMD" ]
	then
		Restore
	else
		echo -e "Server may be down.nnPlease check ${CHECKURL}.nn" | mail -s "ServerCheck" "${EMAIL}"
	fi
fi

echo
echo "This script will self-destruct in 6 seconds."
sleep 6
exit 0

Note: Mac OS X users may have to change the line endings to the Unix equivalent.

Changes:
v0.6: Adds the ability to run a custom restore command.
v0.5: Adds the ability to add post data to a page request.
v0.3: Restructured how the parameters are read in.
v0.2: Allowed parameters to be set at the command line.
v0.1: Initial release.

Gnome Background Rotator

Version: v0.5

Summary: This is an easy way to make your desktop rotate images. All you need to do is specify a background location, and it will find all the *.jpg, *.png, and *.svg files in that folder and display them in a random order.

Requirements:

  • Gnome
  • find
  • sed
  • wc
  • whoami

Code:

#!/bin/bash
 
#User Settable Variables (Defaults)
BACKGROUND_PATH="/usr/share/.backgrounds/"
BACKGROUND_STYLE="zoom" ## 'zoom', 'tiled', 'scaled', 'stretched', 'centered'
CYCLE_TIME="7"
TEMP_LOG="/tmp/rotate${RANDOM}.log"
LOG="/tmp/.`whoami`-gnome-background-rotator"

##Write Date & Time to Log File
echo "-------------------------------------" > "${LOG}"
echo "`date +%B %d, %Y`" >> "${LOG}"
echo "-------------------------------------" >> "${LOG}"
 
USAGE="Usage: ${0} -p  -t  -k "
 
echo "Gnome Background Rotator"
echo "Scripted by Blake Johnson"
echo "http://www.simplescripts.net/"
echo
 
while getopts ':p:k:t:h' OPTION; do
	case ${OPTION} in
		p) BGPATH="${OPTARG}";;
		k) KEYWORD="${OPTARG}";;
		t) CTIME="${OPTARG}";;
		h) echo "${USAGE}" >&2
			exit 2;;
		?) echo "Unknown option "-${OPTARG}"." >&2
			echo ${USAGE};;
		:) echo "Option "-${OPTARG}" needs an argument." >&2
  			echo ${USAGE}
  			exit 2;;
  		*) echo ${USAGE}
  			exit 2;;
  	esac
done

if [ "$BGPATH" ] #Check to see if another background source was given.
then
	if [ -d "$BGPATH" ]
	then
		BACKGROUND_PATH="${BGPATH}"
	else
		echo "Unable to continue.  Source specified is not a (readable) directory."
		exit
	fi
fi

if [ "$CTIME" ] #Check to see if another cycle time was given.
then
	if [ "$CTIME" -gt 0 ]
	then
		CYCLE_TIME="${CTIME}"
	else
		echo "Unable to continue.  Time given is not a valid number."
		exit
	fi
fi

gconftool-2 -s --type=string /desktop/gnome/background/picture_options ${BACKGROUND_STYLE}
 
#Search for images and create a temporary logfile of all matches
if [ "$KEYWORD" ]
then
	find ${BACKGROUND_PATH} -iname "*${KEYWORD}*.jpg" -or -iname "*${KEYWORD}*.png" -or -iname "*${KEYWORD}*.svg" > ${TEMP_LOG}
else
	find ${BACKGROUND_PATH} -iname "*.jpg" -or -iname "*.png" -or -iname "*.svg" > ${TEMP_LOG}
fi

LowerBound=1
RandomMax=32767
UpperBound=$(cat ${TEMP_LOG} | wc -l)

if [ $UpperBound -gt 0 ] #Check to make sure 1 or more results have been returned.
then
	echo "Starting to rotate through ${UpperBound} images(s)."
else
	echo "No images found.  Please change directories, or try another keyword."
	exit
fi

while [ "true" ]
	do
		# Choose a random line number (any number from 1 to the length of the file)
		RandomLine=$(( ${LowerBound} + (${UpperBound} * ${RANDOM}) / (${RandomMax} + 1) ))
 
		# Use sed to grab the random line
		IMAGE=$(sed -n "$RandomLine{p;q;}" "${TEMP_LOG}")
 
		if [ -r $IMAGE ]
		then	
        		echo "Changing background to: ${IMAGE}"
        		gconftool-2 -s --type=string /desktop/gnome/background/picture_filename "${IMAGE}"
        		sleep ${CYCLE_TIME}
        	else
        		echo "Unable to change the background to: ${IMAGE}"
        		echo "The background either does not exist anymore, or the permissions to it are denied."
        	fi
	done
done

Changes:
v0.5: Ability to adjust cycle-time and background directory at command line, and also specify a background keyword. More checks added to make sure everything works as expected.
v0.4: Minor fixes.
v0.3: Backgrounds are now randomized.
v0.2: Minor fixes.
v0.1: Initial release.

Credits: Special thanks to Kevin Warns for implementing the randomization feature.

FirefoxUpdater (v0.2)

Summary: Want an easy way to update Firefox to the latest (nightly) build? Want it to automatically update itself? Set this script as a cron job to run nightly, and all that will be taken care of. This can also be used as a way of pushing out Firefox to other computers.

Requirements:

  • Firefox
  • wget

Code:

#!/bin/bash
MARDIRURL="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk"
MARFILENAME="firefox-3.0b3pre.en-US.linux-i686.complete.mar"

cd /tmp
wget "${MARDIRURL}/${MARFILENAME}"
mv "${MARFILENAME}" "/usr/lib/firefox-updater/update.mar"
cd "/usr/lib/firefox/"
../firefox-updater/updater ../firefox-updater 0
rm "/usr/lib/firefox-updater/update.mar"

Rockbox Updater (v0.2)

Summary: Use this simple shell script to update the build of Rockbox on your DAP. Just change the variables at the top, and you should be good to go.

Requirements:

  • Linux
  • wget
  • unzip

Code:

#!/bin/bash
RBMOUNTPOINT="/media/IHP-100"
RBZIPURL="http://build.rockbox.org/dist/build-h300/rockbox.zip"  ##Filename must be rockbox.zip.
cd "${TMPDIR}"
wget "${RBZIPURL}"
cd "${RBMOUNTPOINT}/"
unzip -o "${TMPDIR}/rockbox.zip"
rm "${TMPDIR}/rockbox.zip"

Backup2Novell (v2.0)

Summary: Backup2Novell automates the process of archiving a folder or file, and then adding it to a specific folder on a Novell server. It uses 7zip for Unix for it’s archives.

Requirements:

  • ncpfs
  • p7zip

Code:

#!/bin/bash

##By Blake Johnson

USERNAME="USERNAME" ##Novell Username (this is case sensative to whatever the mounted directory will use.)
CONTEXT="something.something" ##Novell Context w/ out beginning dot.
PASSWORD="PASSWORD" ##Novell Password

BACKUPNAME="public_html" ##This must not contain any special characters.
BACKUPSOURCE="${HOME}/public_html/" ##What file or folder would you like to back up?

SERVERNAME="SERVERNAME" ##The name of the remote Novell server.
SERVERADDRESS="SERVERIP" ##The address of the remote Novell server.

MOUNTDIRECTORY="${HOME}/mnt/MOUNTPOINT" ##The directory where you want to mount the Novell share.

BACKUPHOME="${MOUNTDIRECTORY}/STAFF/USERS/Folders/${USERNAME}" ##Directory where you are first able to write.
BACKUPFILENAME="${BACKUPNAME}.`date +%Y%m%d`.7z" ##This must not contain any special characters.
BACKUPDESTINATION="${MOUNTDIRECTORY}/Folders/${USERNAME}/.backup/${BACKUPNAME}" ##Where should the backup file be placed?

##Write Date & Time to Log File
echo "-------------------------------------" > ~/.Backup2Novell.log
echo "`date +%B %d, %Y`" >> ~/.Backup2Novell.log
echo "-------------------------------------" >> ~/.Backup2Novell.log

echo -n "Checking if the ncpfs package is installed... "
if [ -x /usr/bin/ncpmount ] ; then
	echo -e "33[1;32mOK!"
	echo -e "33[0m"

	##Log in to Novell Share and mount it.
	echo -n "Mounting Novell Share... "
	echo "ncpmount -S ${SERVERNAME} -A ${SERVERADDRESS} -U ${USERNAME}.${CONTEXT} -P ${PASSWORD} ${MOUNTDIRECTORY}" >> ${HOME}/.Backup2Novell.log
	ncpmount -S ${SERVERNAME} -A ${SERVERADDRESS} -U ${USERNAME}.${CONTEXT} -P ${PASSWORD} ${MOUNTDIRECTORY} >> ${HOME}/.Backup2Novell.log

	##Check to see if userfolder exists.
	if [ -d ${BACKUPHOME} ] ; then

		echo -e "33[1;32mOK!"
		echo -e "33[0m"
		echo "Backing up ${BACKUPSOURCE}"
		echo "Please Wait..."

		##Compress and archive backup source and send it to the Novell Folder.
		echo "7z a "${BACKUPDESTINATION}/${BACKUPFILENAME}" "${BACKUPSOURCE}" >> ${HOME}/.Backup2Novell.log" >>  ${HOME}/.Backup2Novell.log
		7z a "${BACKUPDESTINATION}/${BACKUPFILENAME}" "${BACKUPSOURCE}" >> ${HOME}/.Backup2Novell.log

		##Check to see if the file was written.
		if [ -e "${BACKUPDESTINATION}/${BACKUPFILENAME}" ] ; then
			echo -e "~/public_html Backup 33[1;32mSuccessful"
			echo -e "33[0m"
		else
			echo -e "~/public_html Backup 33[1;31mFailed"
			echo -e "33[0mUnable to write to destination"
		fi

		##Unmount and log out of the Novell share.
		echo -n "Unmounting Novell Share... "
		echo "ncpumount ${MOUNTDIRECTORY}" >> ${HOME}/.Backup2Novell.log
		ncpumount ${MOUNTDIRECTORY} >> ${HOME}/.Backup2Novell.log

		if [ -d ${BACKUPHOME} ] ; then
			echo -e "33[1;31mFailed!"
			echo -e "33[0m"
		else
			echo -e "33[1;32mOK!"
			echo -e "33[0m"
		fi

	else
		echo -e "33[1;31mFailed!"
		echo -e "33[0m"
	fi

else
	echo -e "33[1;31mFailed."
	echo -e "33[0mYou must install the ncpfs package in order for this script to work."
	echo
fi

echo "This script will self-destruct in 5 seconds."
sleep 5s

DVDBackupExpress (v0.7)

DVDBackupExpress is a script to automate the process of backing up an entire DVD-Video disc (minus the data content that may be on there). The script will convert the DVD into a *.iso file.

Requirements:

  • dvdbackup
  • Linux
  • libdvdcss
  • mkisofs

Code:

#!/bin/bash
DEVICEPATH="/dev/sr0"
BACKUPPATH="${HOME}/Desktop"
TMP="${TMPDIR}"
LOG="${HOME}/.DVDBackupExpress.log"

##Write Date & Time to Log File
echo "-------------------------------------" > "${LOG}"
echo "`date +%B %d, %Y`" >> "${LOG}"
echo "-------------------------------------" >> "${LOG}"

echo "DVDBackupExpress"
echo "Scripted by Blake Johnson"
echo "http://www.blakeanthonyjohnson.com/"
echo



echo -n "Getting DVD Information... "

label=`dvdbackup -I -i "${DEVICEPATH}" | grep DVD-Video` >> "${LOG}" 2>&1
if [ $? == 0 ]
then
	echo -n -e "33[1;32mOK!"
	echo -e "33[0m"
	label=${label:43}
else
	echo -n -e "33[1;31mFailed!"
	echo -e "33[0m"
	##echo "Unable to get DVD information."
	echo "Press any key to exit."
	read
	exit
fi

echo "The title detected was: "${label}""
echo
echo "If you would like to change the title of your DVD image, please do so now.  Otherwise, leave it blank."
echo -n "New Title: "
read title

if [ -z $title  ]
then
	title=${label}
fi

echo
echo "The DVD image will be labeled "${title}.iso" and will be placed in "${BACKUPPATH}/"."
echo
echo "Press any key to continue, or get out and try again."
echo "If you continue, the next two steps may take a while to complete, which is normal."
read
echo
echo -n "Decrypting DVD-Video to "${TMP}/${label}/"... "

dvdbackup -M -v 9 -i "${DEVICEPATH}" -o "${TMP}" >> "${LOG}" 2>&1
if [ $? == 0 ]
then
	echo -e -n "33[1;32mOK!"
	echo -e "33[0m"
else
	echo -e -n "33[1;31mFailed!"
	echo -e "33[0m"
	##echo "An error occured while decrypting."
	echo "Press any key to exit."
	read
	exit
fi

echo -n "Creating DVD image from "${TMP}/${label}/"... "
mkisofs -dvd-video -V "${label}" -o "${BACKUPPATH}/${title}.iso" "${TMP}/${label}/" >> "${LOG}" 2>&1
if [ $? == 0 ]
then
	echo -n -e "33[1;32mOK!"
	echo -e "33[0m"
else
	echo -n -e "33[1;31mFailed!"
	echo -e "33[0m"
	##echo "An error occured while creating a DVD image."
	echo "Press any key to exit."
	read
	exit
fi

echo -n "Removing temporary files from "${TMP}/${label}/"... "
rm -R "${TMP}/${label}/" >> "${LOG}" 2>&1
if [ $? == 0 ]
then
	echo -n -e "33[1;32mOK!"
	echo -e "33[0m"
else
	echo -n -e "33[1;31mFailed!"
	echo -e "33[0m"
	##echo "An error occured while removing temporary files."
	echo "Press any key to exit."
	read
	exit
fi
echo
echo "All Finished."
read
rm "${LOG}"
exit 0