#!/bin/bash # # Name: e10update Version="0.2.20070514" # Calls: pmplib & pmplib-tools (pmplib.sourceforge.net, tested with version 0.14), zenity # What does it do?: Updates the iRiver E10 by: entering its directory, running easypmp in # it, with your chosen option, then unmounting the directory as we finish. # Maintained by: ketil.w.aanensen@gmail.com # # Thanks to people at ubuntuforums.org and developers of pmplib # Disclaimer: All the usual stuff. I take no responsibility for loss of # data, heartache, headache, etc, ad nauseum, as a result of using this # script. Having said that, it's so simple, I can't imagine it breaking # anything. # Note for Ubuntu Feisty Fawn users: Eject is broken in current Ubuntu. # That means the script does not handle that command. Eject works as sudo, # but I'm very reluctant to incorporate sudo in a script like # this. Just remember to manually eject/unmount your player before you # unplug, or change the unmount command. Package "pmount" works, and you could use that. { # On Ubuntu (Edgy and Feisty, at least) the E10 mounts on /media/E10. This # might be different with your setup. Find out where your player is mounted # and change the following line to reflect your setup. The variable # "playerdir" is then used throughout this script. playerdir="/media/E10" # As noted before, package eject is broken on current Ubuntu. Pmount can be used, but is not installed by default. # Set your preferred unmount/eject command between the quotes in the following line: unmount_player="eject" # Start with an introductory message, in case user started by mistake. if $(zenity --question --text="You've started an EasyPMP-script ($Version)\n\nWould you like to update your iRiver E10?" --title="Confirm") then # Enter the player directory cd $playerdir EASY_EXIT=$? if [ $EASY_EXIT != 0 ]; then echo $(zenity --error --text="$playerdir does not exist!\n\nEnsure that your player is connected and mounted" --title="Error") exit 1 fi # What does the user want to do? output_list=`zenity --height=200 --text="* 'Create database' sets up your database without sorting 'the'. That means\n 'The Who' will be listed on 'W'\n* 'Create database, sorted after 'the'' puts 'The Who' in 'T'\n* 'Create database, specify prefix' lets you decide which words you wish to ignore.\n\n* Playlist conversion converts playlists that are on your device, but you need\n to put them in the right directory before running this\n\nChoose action from list" --title="Choose from list" --list --radiolist --height=250 --width=500 --column "Choose" --column "Command" TRUE "Create database" FALSE "Create database, sorted after 'the'" FALSE "Create database, specify prefix" FALSE "Convert new playlists" FALSE "Force conversion of playlists" ` # Declare what the output of the former command should translate to # # Like this: # IF former user input option returns exactly "blablabla", # THEN # define variable $HANDLE like "blablabla-response", and # define variable $ERRORMESSAGE like "blablabla-error-response" # 1st possibility: # From man easypmp: # -c, --create: # Create a new music database from scratch. The music files in # the directory on the device used for storing music files is # scanned recursively for music files. For each file found, the # meta-data stored in that file - including the genre, artist, # album and track name - is read, and used to add a record for # that file in the music database stored on the device. # # easypmp -ct the will strip the word ’The’ from the # start of artist names. Hence, ’The Proclaimers’ and # ’The Cat Empire’ will appear in the music database as ’Pro‐ # claimers’ and ’Cat Empire’ respectively. if [ "$output_list" = "Create database" ]; then HANDLE="-ct the" ERRORMESSAGE="create a new database, ignoring 'the'" # Next option, if above fails: # # 2nd possibility: # Same as above, only without the "t" option. That means, no prefixes are stripped. elif [ "$output_list" = "Create database, sorted after 'the'" ]; then HANDLE="-c" ERRORMESSAGE="create database sorting 'the'" # Next option, if above fails: # # 3rd possibility: # From man easypmp: # -t csv-word-list, --strip-words=csv-word-list # Specify a list of words to remove from the start of artist names # when adding new tracks to the database. The list of words # should be comma-separated: that is, a comma (,) should be used # to between each word. # The list is not limited to individual words. Phrases that # include spaces may also be specified from the command line, by # including the whole list in quotes, separating each word or # phrase by a comma. For example: easypmp -ct ’the,pipes and # drums of’. # When used with the -u/--update option, only new tracks that are # not already in the database are affected by this option. To use # this option with all tracks, including those that already exist # in the database, it is necessary to re-build the database with # -c/--create. This option does not modify music files, it only # has an effect on the music database. elif [ "$output_list" = "Create database, specify prefix" ]; then strip_list=`zenity --title "Enter words" --entry --text "Enter words that should be excluded from sorting. Use comma as a separator" ` HANDLE="-ct $strip_list" ERRORMESSAGE="create a database with specified prefixes excluded from sorting" # Next option, if above fails: # # 4th possibility: # From man easypmp: # -p, --playlist # programs for playing music allow playlists to be created # and saved on disk, ready to be played later. Such playlists # frequently have a .m3u or .pls extension. However, the # playlists saved by most programs cannot be used directly on # portable media players. Instead, it is necessary to convert (or # ‘compile’) each playlist into a format that the media player can # read. When the -p/--playlist option is specified, easypmp will # search the playlist directory on the device or the directory # specified by -P/--playlist-source option for playlists that can # be converted into a form that the media player can read (see the # DESCRIPTION section above for information on how to determine # the playlist directory for a particular media player). elif [ "$output_list" = "Convert new playlists" ]; then HANDLE=-p ERRORMESSAGE="convert new playlists" # Next option, if above fails: # # 5th possibility: # From man easypmp: # -r, --reconvert # Overwrite the existing playlists to force conversion. elif [ "$output_list" = "Force conversion of playlists" ]; then HANDLE=-r ERRORMESSAGE="force conversion of all playlists" # Last option, if "Cancel" is clicked: # # 6th possibility: # Just exit the script elif [ "$output_list" = "" ]; then exit 1 fi # Update player using pmplib and the selected option. # While easypmp runs, show simple progress dialog, to make the user understand that # something's running. # PIPESTATUS is used to make the script realize that what matter is the first command from the # preceding line. 0 = the first command, 1 = the second... easypmp $HANDLE | zenity --progress --pulsate --auto-close --title="Updating" --text="Updating iRiver E10...\n\nPlease wait for the operation to finish" if [ "${PIPESTATUS[0]}" != "0" ]; then echo $(zenity --error --text="You tried running the command 'easypmp $HANDLE'\n\nYour attempt to $ERRORMESSAGE failed\n\n Bye!" --title="Error!") exit 1 fi # Exit to home-folder. (The player will not unmount if you stay in its dir.) # The error message is just to show where the script died if t did. The likelihood of bash # not being able to cd into /home/whoever-called-the-script is about 0 cd ~ EASY_EXIT=$? if [ $EASY_EXIT != 0 ]; then echo $(zenity --error --text="Can't navigate to home directory\n\nThis can't be right..." --title="Unlikely error") exit 1 fi # Unmount the player, making it ready to unplug $unmount_player $playerdir EASY_EXIT=$? if [ $EASY_EXIT != 0 ]; then echo $(zenity --error --text="Could not unmount your player\n\nYou have to either\na) find a way to manually eject your player, \nb)change the 'unmount_player' variable to something that works or \nc) turn of the computer before you unplug your player\n\nIf you're using Ubuntu Feisty Fawn, this is probably due to a bug in package 'eject'\n\n(If the script brought you to this point, your player is still updated)" --title="Error") exit 1 fi # Bye-bye! zenity --info --title "Update finished" --text "Your player is updated and ready to disconnect. Enjoy!" fi }