+++ /dev/null
-#!/usr/bin/env bash
-
-#-------------------------------------------------------------------------------
-## Script to convert the database of paraslash 0.2.x to version 0.3.x.
-##
-## Assumptions:
-## - para_server 0.2.x is running and the mysql selector is active
-## - para_server 0.3.x is running on another port
-## - The database of paraslash 0.3.x has been initialized (i.e.
-## para_client init has successfully been executed)
-## - All audio files in the mysql database of paraslash 0.2.x. have
-## already been added to the 0.3.x database (execute para_client add
-## /my/audio/file/dir to do that)
-##
-## The script converts the attribute table, the set attributes for each audio
-## file, the image table and all image ids, and finally the lastplayed and the
-## numplayed data.
-##
-## However, it does not convert the paraslash stream definitions from 0.2.x to
-## the moods of 0.3.x. You'll have to do this by hand.
-#-------------------------------------------------------------------------------
-
-# Call this script without arguments to see usage info
-
-# How to connect to para_server 0.2.x.
-client02=/usr/local/bin/para_client
-port02=2991
-host02=localhost
-
-# How to connect to para_server 0.3.x.
-client03=./para_client
-port03=2990
-host03=localhost
-
-# Unset this to deactivate messages
-debug=1
-
-
-client02_cmd="$client02 -p $port02 -i $host02"
-client03_cmd="$client03 -p $port03 -i $host03"
-
-info_log()
-{
- if test $debug -eq 1; then
- echo "$@"
- fi
-}
-
-exec_client02_cmd()
-{
- info_log "$client02_cmd -- $@"
- result="$($client02_cmd -- "$@")"
-}
-
-exec_client03_cmd()
-{
- info_log "$client03_cmd -- $@"
- result="$($client03_cmd -- "$@")"
-}
-
-convert_attribute_table()
-{
- local atts
- exec_client02_cmd laa
- atts="$result"
- info_log "creating attributes: $atts"
- exec_client03_cmd addatt $atts
-}
-
-convert_attributes()
-{
- local att atts current_atts cmd query="select dir.dir, dir.name"
- exec_client02_cmd laa
- atts="$result"
- for att in $atts; do
- query="$query, data.$att"
- done
- query="$query from dir,data where dir.name=data.name"
- exec_client02_cmd verb "$query"
- echo "$result" | while read dir name current_atts; do
- cmd="setatt "
- for att in $atts; do
- if test "${current_atts#0}" = "$current_atts"; then
- cmd="$cmd $att+"
- current_atts=${current_atts#1 }
- else
- current_atts=${current_atts#0 }
- fi
- done
- if test "$cmd" = "setatt "; then
- continue
- fi
- exec_client03_cmd $cmd "$dir/$name"
- done
-}
-
-convert_lastplayed_numplayed()
-{
- local query="select dir.dir, dir.name, unix_timestamp(data.lastplayed), data.numplayed from dir,data where data.name=dir.name"
- local lp np data dir name
- exec_client02_cmd verb "$query"
- data="$result"
- echo "$result" | while read dir name lp np; do
- cmd="touch -n$np -l$lp $dir/$name"
- exec_client03_cmd $cmd
- done
-}
-
-convert_image_table()
-{
- local num size name
- exec_client02_cmd piclist;
- echo "$result" | while read num size name; do
- info_log "converting $name"
- $client02_cmd -- pic "#$num" | $client03_cmd -- addimg "$name"
- done
-}
-
-convert_image_ids()
-{
- local query="select dir.dir, dir.name, pics.name from dir,data,pics where data.name=dir.name and pics.id=data.pic_id"
- local img_ids_03 dir name img id
- exec_client03_cmd lsimg -l
- img_ids_03="$result"
- exec_client02_cmd verb "$query"
- echo "$result" | while read dir name img; do
- id="$(echo "$img_ids_03" | grep " $img\$" | cut -f 1)"
- exec_client03_cmd touch "-i$id" "$dir/$name"
- done
-}
-
-
-usage()
-{
- grep '^##' $0 | sed -e 's/^## *//'
- echo '
-Usage: $0 command
-
-command is one of the following:
-
- attribute_table: create attributes
- attributes: convert attributes for each audio file
- lastplayed_numplayed: convert numplayed and lastplayed
- data of each audio file
- image_table: retrieve images from mysql and add them to the database
- of paraslash-0.3.x
- image_ids: convert image id of each audio file.
- all: Do all of the above.
-
-Edit the top of the script to customize some options.
-'
-}
-
-if test $# -ne 1; then
- usage
- exit 1
-fi
-
-case "$1" in
-attribute_table)
- convert_attribute_table
- ;;
-attributes)
- convert_attributes
- ;;
-lastplayed_numplayed)
- convert_lastplayed_numplayed
- ;;
-image_table)
- convert_image_table
- ;;
-image_ids)
- convert_image_ids
- ;;
-all)
- convert_attribute_table
- convert_attributes
- convert_lastplayed_numplayed
- convert_image_table
- convert_image_ids
- ;;
-*)
- usage
- exit 1
- ;;
-esac