#!/bin/bash # ------------------------------------------------------------------------- # Jehsom's mp3 linker script, v1.1.1 - Indexes mp3 releases. # Copyright (C) 2000 jehsom@jehsom.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ------------------------------------------------------------------------- # You must have mp3info 0.8.2 or greater, by Cedrec Tefft to link genres. # If you don't have it, get it from my zipscript package, or from: # http://www.ibiblio.org/mp3info # CHANGES: # 1.1 - Script would make links in /glftpd/bin if any of the *_DIR settings # were commented out. This means /glftpd/bin would be deleted. So if # you're running a pre-1.1 version and you don't want one type of the # links, please upgrade asap! # 1.1.1 Fixed a couple misc quoting bugs # Put the full path to mp3info here if it's not in your $PATH. mp3info=`which mp3info 2>/dev/null` # wildcard expressions that match the names of all your release dirs. RLS_DIRS=" /glftpd/site/Archive/*/* /glftpd/site/Incoming/????????/* /glftpd/site/Requests_Filled/* /glftpd/site/Old_Archive/*/* " # Where do you want the link trees to go? Set to "" or comment out to disable. ALPHA_DIR="/glftpd/site/Index/Albums_By_Artist" GENRE_DIR="/glftpd/site/Index/Albums_By_Genre" GROUP_DIR="/glftpd/site/Index/Albums_By_Rls_Grp" ##################################################### ############## You can ignore the rest ############## ##################################################### function link_alpha () { cd "$1" || return 1 rlsdir="$PWD" base="$(basename "$PWD")" sortable="${base#(}" case $sortable in *NUKED*) return 0 ;; [vV][aA][-_.]*|[vV]arious[-_.]*|[vV][_.][aA][.-_]*) letter="Various" ;; *) letter=$(echo ${base%${base#?}} | tr '[:lower:]' '[:upper:]') ;; esac [ -d "$ALPHA_DIR/$letter" ] || mkdir "$ALPHA_DIR/$letter" oIFS="$IFS" IFS="/" relpath= set -- $rlsdir for seg in $ALPHA_DIR; do case $relpath$seg in "$1") shift ;; *) relpath=../$relpath ;; esac done relpath="../$relpath$*" IFS="$oIFS" IFS="$oIFS" ln -s "$relpath/" "$ALPHA_DIR/$letter/$base" cd - } function link_genre () { cd "$1" || return 1 rlsdir="$PWD" base="$(basename "$PWD")" case $base in *NUKED*) return 0 ;; esac mp3="$(echo *.[mM][pP]3 */*.[mM][pP]3 | cut -f1 -d ' ')" [ -f "$mp3" ] || return 1 genre=$($mp3info -p "%g" $mp3 | tr -d '[:punct:]' | tr ' ' '_') [ -z "$genre" ] && genre="Unknown" [ -d "$GENRE_DIR/$genre" ] || mkdir "$GENRE_DIR/$genre" oIFS="$IFS" IFS="/" relpath= set -- $rlsdir for seg in $GENRE_DIR; do case $relpath$seg in "$1") shift ;; *) relpath=../$relpath ;; esac done relpath="../$relpath$*" IFS="$oIFS" IFS="$oIFS" ln -s "$relpath/" "$GENRE_DIR/$genre/$base" cd - } function link_group () { cd "$1" || return 1 rlsdir="$PWD" base="$(basename "$PWD")" case $base in *NUKED*) return 0 ;; *) group=$(echo "${base##*-}" | tr '[:lower:]' '[:upper:]') ;; esac # In case the foler name was formatted improperly [ ${#group} -gt 15 ] && return 0 group=${group#_} [ -d "$GROUP_DIR/$group" ] || mkdir "$GROUP_DIR/$group" oIFS="$IFS" IFS="/" relpath= set -- $rlsdir for seg in $GROUP_DIR; do case $relpath$seg in "$1") shift ;; *) relpath=../$relpath ;; esac done relpath="../$relpath$*" IFS="$oIFS" IFS="$oIFS" ln -s "$relpath/" "$GROUP_DIR/$group/$base" cd - } #### Main program body **** allow_null_glob_expansion=1 shopt -s nullglob 2>/dev/null { [ -n "$mp3info" ] && $mp3info 2>/dev/null | grep "Cedric Tefft" > /dev/null; } || { echo "Your mp3info binary is missing or incorrect. Exiting." 1>&2 exit 0 } for i in ALPHA GENRE GROUP; do if eval [ -d "\"\$${i}_DIR\"" -a -x "\"\$${i}_DIR\"" ]; then eval cd \"\$${i}_DIR\" eval ${i}_DIR="$PWD" else eval [ -n \"\$${i}_DIR\" ] && echo "Your ${i}_DIR is invalid. Skipping $i links." 1>&2 eval ${i}_DIR="" fi done { [ -z "$ALPHA_DIR" ] && [ -z "$GENRE_DIR" ] && [ -z "$GROUP_DIR" ]; } && exit 1 [ -n "$ALPHA_DIR" ] && rm -rf "$ALPHA_DIR"/* [ -n "$GENRE_DIR" ] && rm -rf "$GENRE_DIR"/* [ -n "$GROUP_DIR" ] && rm -rf "$GROUP_DIR"/* for i in $RLS_DIRS; do [ -d "$i" -a -x "$i" ] || continue [ -n "$ALPHA_DIR" ] && link_alpha "$i" [ -n "$GENRE_DIR" ] && link_genre "$i" [ -n "$GROUP_DIR" ] && link_group "$i" done exit 0